App-Framework
view release on metacpan or search on metacpan
lib/App/Framework/Feature/Pod.pm view on Meta::CPAN
This feature adds the following additional command line options to any application:
=over 4
=item B<-help> - show help
Displays brief help message then exits
=item B<-man> - show full man pages
Displays the application's full man pages then exits
=item B<-man-dev> - show full developer man pages
Displays the application's full developer man pages then exits. Developer man pages contain extra
information and is intended for the application developer (rather than the end user).
=item B<-pod> - show man pages as pod [I<developer use>]
Outputs the full pod text.
=back
=cut
my @OPTIONS = (
['h|"help"', 'Print help', 'Show brief help message then exit'],
['man', 'Full documentation', 'Show full man page then exit' ],
['man-dev', 'Full developer\'s documentation', 'Show full man page for the application developer then exit' ],
['dev:pod', 'Output full pod', 'Show full man page as pod then exit' ],
) ;
#============================================================================================
=head2 CONSTRUCTOR
=over 4
=cut
#============================================================================================
=item B< new([%args]) >
Create a new Pod.
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,
'feature_options' => \@OPTIONS,
'registered' => [qw/application_entry/],
) ;
#$this->debug(2);
return($this) ;
}
#============================================================================================
=back
=head2 CLASS METHODS
=over 4
=cut
#============================================================================================
#-----------------------------------------------------------------------------
=item B< init_class([%args]) >
Initialises the Pod 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<application_entry()>
Called by the application framework at the start of the application.
This method checks for the user specifying any of the options described above (see L</ADDITIONAL COMMAND LINE OPTIONS>) and handles
them if so.
=cut
sub application_entry
{
my $this = shift ;
$this->_dbg_prt(["application_entry()\n"]) ;
## Handle special options
my $app = $this->app ;
my %opts = $app->options() ;
$this->_dbg_prt(["pod options=",\%opts]) ;
if ($opts{'man'} || $opts{'help'})
{
$this->_dbg_prt(["pod man page=$opts{'man'} \n"]) ;
my $type = $opts{'man'} ? 'man' : 'help' ;
$app->usage($type) ;
$app->exit(0) ;
}
if ($opts{'man-dev'})
{
$app->usage('man-dev') ;
$app->exit(0) ;
}
if ($opts{'pod'})
{
print $this->pod() ;
$app->exit(0) ;
}
}
#----------------------------------------------------------------------------
( run in 0.625 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )