Nagios::Plugin::ExitResult - Helper class for returning both output and


Nagios-Plugin documentation Contained in the Nagios-Plugin distribution.

Index


Code Index:

NAME

Top

Nagios::Plugin::ExitResult - Helper class for returning both output and return codes when testing.

SYNOPSIS

Top

    use Test::More;
    use Nagios::Plugin::Functions;

    # In a test file somewhere
    Nagios::Plugin::Functions::_fake_exit(1);

    # Later ...
    $e = nagios_exit( CRITICAL, 'aiiii ...' );
    print $e->message;
    print $e->return_code;

    # NP::ExitResult also stringifies to the message output
    like(nagios_exit( WARNING, 'foobar'), qr/^foo/, 'matches!');







DESCRIPTION

Top

Nagios::Plugin::ExitResult is a tiny helper class intended for use when testing other Nagios::Plugin modules. A Nagios::Plugin::ExitResult object is returned by nagios_exit() and friends when Nagios::Plugin::Functions::_fake_exit has been set, instead of doing a conventional print + exit.

AUTHOR

Top

Gavin Carr , <gavin@openfusion.com.au>

COPYRIGHT AND LICENSE

Top


Nagios-Plugin documentation Contained in the Nagios-Plugin distribution.

# Tiny helper class to return both output and return_code when testing

package Nagios::Plugin::ExitResult;

use strict;

# Stringify to message
use overload '""' => sub { shift->{message} };

# Constructor
sub new { 
    my $class = shift;
    return bless { return_code => $_[0], message => $_[1] }, $class;
}

# Accessors
sub message { shift->{message} }
sub return_code { shift->{return_code} }
sub code { shift->{return_code} }

1;

__END__