App::Framework::Feature::Data - Handle application setup data
# Data feature is loaded by default as if the script contained: use App::Framework '+Data' ;
System feature that provides the application core with access to the setup information stored in the __DATA__ section.
The __DATA__ section at the end of the script is used by the application framework to allow the script developer to define various settings for his/her script. This setup is split into "headed" sections of the form:
[ <section name> ] <settings>
In general, the <section name> is the name of a field value in the application, and <settings> is some text that the field will be set to. Sections of this type are:
A single line summary of the application. Used for man pages and usage summary.
(Stored in the application's summary field).
Multiple line description of the application. Used for man pages.
(Stored in the application's description field).
Multiple line synopsis of the application usage. By default the application framework creates this if it is not specified.
(Stored in the application's synopsis field).
Name of the application usage. By default the application framework creates this if it is not specified.
(Stored in the application's name field).
__DATA__ sections that have special meaning are:
These are fully described in App::Framework::Features::Options.
If no options are specified, then only those created by the application framework will be defined.
These are fully described in App::Framework::Features::Args.
After the settings (described above), one or more extra data areas can be created by starting that area with a new __DATA__ line.
Each defined data area is named 'data1', 'data2' and so on. These data areas are user-defined multi line text that can be accessed by the object's accessor method "data", for example:
my $data = $app->data('data1') ;
Alternatively, the user-defined data section can be arbitrarily named by appending a text name after __DATA__. For example, the definition:
__DATA__ [DESCRIPTION] An example __DATA__ test.txt some text __DATA__ a_bit_of_sql.sql DROP TABLE IF EXISTS `listings2`;
leads to the use of the defined data areas as:
my $file = $app->data('text.txt') ; # or $file = $app->data('data1') ; my $sql = $app->data('a_bit_of_sql.sql') ; # or $file = $app->Data('data2') ;
The data text can contain variables, defined using the standard Perl format:
$<name> ${<name>}
When the data is used, the variable is expanded and replaced with a suitable value. The value will be looked up from a variety of possible sources: object fields (where the variable name matches the field name) or environment variables.
The variable name is looked up in the following order, the first value found with a matching name is used:
Option names - the values of any command line options may be used as variables
Arguments names - the values of any command line arguments may be used as variables
Application fields - any fields of the $app object may be used as variables
Environment variables - if no application fields match the variable name, then the environment variables are used
Any lines starting with:
__#
are treated as comment lines and not included in the data.
No public fields
This feature adds the following additional command line options to any application:
Display the __DATA__ definition text then exit
Show all of the processed __DATA__ items then exit
Create a new Data.
The %args are specified as they would be in the set method (see "Fields").
Initialises the Data object class variables.
Called at the end of app_start. Used to expand the variables in the data
Called at start of application
Returns the lines for the named __DATA__ section. If no name is specified returns the first section. If an ARRAY is required, returns the array; otherwise concatenates the lines with "\n".
Returns undef if no data found, or no section with specified name
Alias to "data"
If caller package namespace has __DATA__ defined then use that information to set up object parameters.
Adds any user-defined options to the end of the options list
Setting the debug flag to level 1 prints out (to STDOUT) some debug messages, setting it to level 2 prints out more verbose messages.
Steve Price <sdprice at cpan.org>
<sdprice at cpan.org>
None that I know of!
To install App::Framework, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::Framework
CPAN shell
perl -MCPAN -e shell install App::Framework
For more information on module installation, please visit the detailed CPAN module installation guide.