package Test::Smoke::App::Base; use warnings; use strict; use Carp; our $VERSION = '0.002'; use base 'Test::Smoke::ObjectBase'; use Cwd 'abs_path'; use Getopt::Long qw/:config pass_through/; use Test::Smoke::App::AppOption; use Test::Smoke::App::AppOptionCollection; use Test::Smoke::LogMixin; use Test::Smoke::Util::Serialise qw/serialise/; =head1 NAME Test::Smoke::App::Base - Baseclass for Test::Smoke::App::* applications. =head1 SYNOPSIS package Test::Smoke::App::Mailer; use base 'Test::Smoke::App::Base'; sub run {...} =head1 DESCRIPTION use Test::Smoke::App::Mailer; my $mailer = Test::Smoke::App::Mailer->new( main_options => [ Test::Smoke::App::AppOption->new( name => 'mailer', option => '=s', allow => [qw/MIME::lite sendmail/], helptext => "Mailsystem to use for sendig reports.", ), ], genral_options => [ Test::Smoke::AppOption->new( name => 'ddir', option => '=s', helptxt => "Smoke Destination Directory.", ), ], special_options => { 'MIME::Lite' => [ mserver(), msport(), msuser(), mspass(), ], 'sendmail' => [], }, ); $mailer->run(); =head2 Test::Smoke::App->new(%arguments) =head3 Arguments Named: =over =item main_options => $list_of_test_smoke_appoptions =item general_options => $list_of_test_smoke_appoptions These options are always valid. =item special_options => $hashref This is a hashref with the values of the C-array, that hold a list of L. =back =head3 Exceptions None. =cut sub new { my $class = shift; my %args = @_; my $struct = { _main_options => [], _general_options => [], _special_options => {}, _final_options => {}, }; for my $known (keys %$struct) { (my $key = $known) =~ s/^_//; $struct->{$known} = delete $args{$key} if exists $args{$key}; } my $self = bless $struct, $class; $self->process_options(); return $self; } =head2 Test::Smoke::App::Base->configfile_option() Returns a L for 'configfile'. =cut sub configfile_option { my $class = shift; return Test::Smoke::App::AppOption->new( name => 'configfile', option => 'config|c=s', helptext => "Set the name/prefix of the configfile\n", ); } =head2 Test::Smoke::App::Base->verbose_option() Returns a L for 'verbose'. =cut sub verbose_option { my $class = shift; return Test::Smoke::App::AppOption->new( name => 'verbose', option => 'v=i', allow => [0, 1, 2], default => 0, helptext => 'Set verbosity level.', ); } =head2 $app->show_config_option =cut sub show_config_option { return Test::Smoke::App::AppOption->new( name => 'show_config', option => 'show-config', helptext => "Show all about config vars.", ); } =head2 $app->process_options() This process constists of three (3) steps: =over =item 1. pre_process_options This step organizes the options in a AppOptionCollection. =item 2. get_options This step processes the arguments passed on the command line. =item 3. post_process_options This step integrates the arguments, their coded-defaults, config-file values and command-line overrides. =back =head3 Arguments None. =head3 Returns The object-instance. =head3 Exceptions None. =cut sub process_options { my $self = shift; $self->{_opt_collection} = Test::Smoke::App::AppOptionCollection->new(); $self->_pre_process_options(); $self->_get_options(); $self->_post_process_options(); return $self; } =head2 $app->option($option) Return the value of an option. =head3 Arguments Positional. =over =item $option_name =back =head3 Returns The value of that option if applicable. =head3 Exceptions =over =item B $type)> =item B