From 22a5502e1c9f6e160b0f85656de4fe2ea21a6dee Mon Sep 17 00:00:00 2001 From: Gavin Carr Date: Mon, 11 Sep 2006 01:59:42 +0000 Subject: Add missing Nagios::Plugin::ExitResult class. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1478 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/lib/Nagios/Plugin/ExitResult.pm b/lib/Nagios/Plugin/ExitResult.pm new file mode 100644 index 0000000..f059424 --- /dev/null +++ b/lib/Nagios/Plugin/ExitResult.pm @@ -0,0 +1,67 @@ +# 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__ + +=head1 NAME + +Nagios::Plugin::ExitResult - Helper class for returning both output and +return codes when testing. + +=head1 SYNOPSIS + + use Test::More; + use Nagios::Plugin::Base; + + # In a test file somewhere + Nagios::Plugin::Base::_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!'); + + + +=head1 DESCRIPTION + +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::Base::_fake_exit has been set, instead of doing a +conventional print + exit. + +=head1 AUTHOR + +Gavin Carr , Egavin@openfusion.com.auE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006 by Nagios Plugin Development Team + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut -- cgit v0.10-9-g596f