App-Framework
view release on metacpan or search on metacpan
lib/App/Framework/Feature/Data.pm view on Meta::CPAN
No public fields
=cut
my %FIELDS = (
'_data' => [],
'_data_hash' => {},
'_user_options' => [],
) ;
=head2 ADDITIONAL COMMAND LINE OPTIONS
This feature adds the following additional command line options to any application:
=over 4
=item B<-dbg-data> - show __DATA__
Display the __DATA__ definition text then exit
=item B<-dbg-data-array> - show all __DATA__ items
Show all of the processed __DATA__ items then exit
=back
=cut
my @OPTIONS = (
['dev:dbg-data', 'Debug option: Show __DATA__', 'Show __DATA__ definition in script then exit' ],
['dev:dbg-data-array', 'Debug option: Show all __DATA__ items', 'Show all processed __DATA__ items then exit' ],
) ;
#============================================================================================
=head2 CONSTRUCTOR
=over 4
=cut
#============================================================================================
=item B< new([%args]) >
Create a new Data.
The %args are specified as they would be in the B<set> method (see L</Fields>).
=cut
sub new
{
my ($obj, %args) = @_ ;
my $class = ref($obj) || $obj ;
# Create object
my $this = $class->SUPER::new(%args,
'priority' => $App::Framework::Base::PRIORITY_SYSTEM + 20, # needs to be after options
'registered' => [qw/app_start_exit application_entry/],
'feature_options' => \@OPTIONS,
) ;
#$this->debug(2);
return($this) ;
}
#============================================================================================
=back
=head2 CLASS METHODS
=over 4
=cut
#============================================================================================
#-----------------------------------------------------------------------------
=item B< init_class([%args]) >
Initialises the Data object class variables.
=cut
sub init_class
{
my $class = shift ;
my (%args) = @_ ;
# Add extra fields
$class->add_fields(\%FIELDS, \%args) ;
# init class
$class->SUPER::init_class(%args) ;
}
#============================================================================================
=back
=head2 OBJECT METHODS
=over 4
=cut
#============================================================================================
#----------------------------------------------------------------------------
=item B<app_start_exit()>
Called at the end of app_start. Used to expand the variables in the data
=cut
sub app_start_exit
{
my $this = shift ;
## Handle special options
my $app = $this->app ;
my %app_vars = $app->vars ;
my %opts = $app->options() ;
my $args_values_href = $app->feature('Args')->args_values_hash() ;
my $data_href = $this->_data_hash() ;
$this->expand_keys($data_href, [\%opts, $args_values_href, \%app_vars, \%ENV]) ;
}
#----------------------------------------------------------------------------
=item B<application_entry()>
Called at start of application
=cut
sub application_entry
{
my $this = shift ;
## Handle special options
my $app = $this->app ;
my %opts = $app->options() ;
## Debug
if ($opts{'dbg-data'})
( run in 1.128 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )