NAME
XAS::Lib::App - The base class to write procedures within the XAS environment
SYNOPSIS
use XAS::Lib::App;
my $app = XAS::Lib::App->new();
$app->run();
DESCRIPTION
This module defines a base class for writing procedures. It provides signal handling, options processing, along with a exit handler.
METHODS
new
This method initilaizes the module. It inherits from XAS::Base and takes these additional parameters:
- -throws
-
This changes the default error message from "changeme" to something useful.
- -facility
-
This will change the facility of the alert. The default is 'systems'.
- -priority
-
This will change the priority of the alert. The default is 'low'.
run
This method sets up a global exception handler and calls main(). The main() method will be passed one parameter: an initialised handle to this class.
Example
sub main {
my $self = shift;
$self->log->debug('in main');
}
- Exception Handling
-
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.
- Normal Completion
-
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.
main
This is where your main line logic starts.
options
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]);
}
};
}
define_signals
This method sets up basic signal handling. By default this is only for the INT and QUIT signals.
Example
sub define_signals {
my $self = shift;
$SIG{INT} = \&signal_handler;
$SIG{QUIT} = \&singal_handler;
}
define_pidfile
This is an entry point to define a pid file.
define_daemon
This is an entry point so the procedure can daemonize.
signal_handler($signal)
This method is a default signal handler. By default it throws an exception. It takes one parameter.
OPTIONS
This module handles the following command line options.
--debug
This toggles debugging output.
--[no]alerts
This toggles sending alerts. They are on by default.
--help
This prints out a short help message based on the procedures pod.
--manual
This displaces the procedures manual in the defined pager.
--version
This prints out the version of the module.
--log-type
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".
--log-facility
What log facility class to use. This follows syslog convention. By default the facility is "local6".
--logfile
The name of the log file. When --logfile is specified, it implies a log type of "file".
SEE ALSO
AUTHOR
Kevin L. Esteb, <kevin@kesteb.us>
COPYRIGHT AND LICENSE
Copyright (c) 2014 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.