XAS::Lib::App - The base class to write procedures within the XAS environment
use XAS::Lib::App; my $app = XAS::Lib::App->new(); $app->run();
This module defines a base class for writing procedures. It provides signal handling, options processing, along with a exit handler.
This method initializes the module. It inherits from XAS::Base and takes these additional parameters:
This changes the default error message from "changeme" to something useful.
This will change the facility of the alert. The default is 'systems'.
This will change the priority of the alert. The default is 'low'.
This method sets up a global exception handler and calls main(). The main() method will be passed one parameter: an initialized handle to this class.
Example
sub main { my $self = shift; $self->log->debug('in main'); }
If an exception is caught, the global exception handler will send an alert, write the exception to the log and returns an exit code of 1.
When the procedure completes successfully, it will return an exit code of 0.
To change this behavior you would need to override the exit_handler() method.
This is where your main line logic starts.
This method sets up additional cli options. Option handling is provided by Getopt::Long. To access these options you need to define accessors for them.
Example use XAS::Class version => '0.01', base => 'XAS::Lib::App', accessors => 'widget' ; sub main { my $self = shift; $self->log->info('starting up'); sleep(60); $self->log->info('shutting down'); } sub options { my $self = shift; return { 'widget=s' => sub { $self->{widget} = uc($_[1]); } }; }
This method sets up basic signal handling. By default this is only for the INT and QUIT signals.
sub define_signals { my $self = shift; $SIG{INT} = \&signal_handler; $SIG{QUIT} = \&singal_handler; }
This is an entry point to define a pid file.
This is an entry point so the procedure can daemonize.
This method is a default signal handler. By default it throws an exception. It takes one parameter.
The signal that was captured.
This module handles the following command line options.
Defines the facility to use. Defaults to 'systems'. This will override the class parameter.
Defines the priority to use. Defaults to 'low'. This will override the class parameter.
This toggles debugging output.
This toggles sending alerts. They are on by default.
This prints out a short help message based on the procedures pod.
This displaces the procedures manual in the defined pager.
This prints out the version of the module.
What type of log to use. By default the log is displayed on the console. Log types can be one of the following "console", "file", "json" or "syslog".
What log facility class to use. This follows syslog convention. By default the facility is "local6".
The name of the log file. When --logfile is specified, it implies a log type of "file".
Kevin L. Esteb, <kevin@kesteb.us>
Copyright (c) 2012-2015 Kevin L. Esteb
This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://www.perlfoundation.org/artistic_license_2_0.
To install XAS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XAS
CPAN shell
perl -MCPAN -e shell install XAS
For more information on module installation, please visit the detailed CPAN module installation guide.