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 a logger, signal handling, options processing along with a exit handler.

METHODS

new

This method initilaizes the module. It takes several parameters:

-throws

This changes the default error message from "changeme" to something useful.

-options

This will parse additional options from the command line. Those options are a list of command line options and defaults.

Example

my $app = XAS::Lib::App->new(
   -options => [
       { 'logfile=s' => 'test.log' }
   ]
);

This will then create an accessor named "logfile" that will return the value, which may be the supplied default or supplied from the command line.

-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 'high'.

-alerts

This will toggle wither to send an alert to the XAS Alert System. The default is to do so. Values of 'true', 'yes' or 1 will evaluate to TRUE.

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 Completiion

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.

define_logging

This method sets up the logger. By default, this logs to stderr.

Example

sub define_logging {
    my $self = shift;

    my $logfile = defined($self->logfile) ? 
                          $self->logfile : 
                          $self->env->logfile;

    $self->{log} = XAS::System->module(
        logger => {
            -filename => $logfile,
            -debug    => $debug,
        }
    );

}

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;

}

signal_handler($signal)

This method is a default signal handler. By default it throws an exception. It takes one parameter.

$signal

The signal that was captured.

ACCESSORS

This module has several accessors that make life easier for you.

log

This is the handle to the XAS logger.

alert

This is the handle to the XAS Alert system.

env

This is the handle to the XAS environment.

MUTATORS

These mutator are provided to help control the process.

facility

The facility to use when sending an alert.

priority

The priority of the alert.

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.

SEE ALSO

XAS

AUTHOR

Kevin L. Esteb, <kevin@kesteb.us>

COPYRIGHT AND LICENSE

Copyright (C) 2012 by Kevin L. Esteb

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.