From b418181dfe80dd75169b6e8a619ac1932155dea2 Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Mon, 20 Jan 2014 00:54:34 +0100 Subject: renamed module into Monitoring::Plugin since the complete monitoring team has been renamed, we also rename this module. Signed-off-by: Sven Nierlein --- lib/Monitoring/Plugin/ExitResult.pm | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 lib/Monitoring/Plugin/ExitResult.pm (limited to 'lib/Monitoring/Plugin/ExitResult.pm') diff --git a/lib/Monitoring/Plugin/ExitResult.pm b/lib/Monitoring/Plugin/ExitResult.pm new file mode 100644 index 0000000..aa9f5da --- /dev/null +++ b/lib/Monitoring/Plugin/ExitResult.pm @@ -0,0 +1,71 @@ +# Tiny helper class to return both output and return_code when testing + +package Monitoring::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 + +Monitoring::Plugin::ExitResult - Helper class for returning both output and +return codes when testing. + +=head1 SYNOPSIS + + use Test::More; + use Monitoring::Plugin::Functions; + + # In a test file somewhere + Monitoring::Plugin::Functions::_fake_exit(1); + + # Later ... + $e = plugin_exit( CRITICAL, 'aiiii ...' ); + print $e->message; + print $e->return_code; + + # MP::ExitResult also stringifies to the message output + like(plugin_exit( WARNING, 'foobar'), qr/^foo/, 'matches!'); + + + +=head1 DESCRIPTION + +Monitoring::Plugin::ExitResult is a tiny helper class intended for use +when testing other Monitoring::Plugin modules. A Monitoring::Plugin::ExitResult +object is returned by plugin_exit() and friends when +Monitoring::Plugin::Functions::_fake_exit has been set, instead of doing a +conventional print + exit. + +=head1 AUTHOR + +This code is maintained by the Monitoring Plugin Development Team: see +https://monitoring-plugins.org + +Originally: + Gavin Carr , Egavin@openfusion.com.auE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2006-2014 Monitoring 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 v1.2.3-74-g34f1