summaryrefslogtreecommitdiffstats
path: root/lib/Monitoring/Plugin/ExitResult.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Monitoring/Plugin/ExitResult.pm')
-rw-r--r--lib/Monitoring/Plugin/ExitResult.pm71
1 files changed, 71 insertions, 0 deletions
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 @@
1# Tiny helper class to return both output and return_code when testing
2
3package Monitoring::Plugin::ExitResult;
4
5use strict;
6
7# Stringify to message
8use overload '""' => sub { shift->{message} };
9
10# Constructor
11sub new {
12 my $class = shift;
13 return bless { return_code => $_[0], message => $_[1] }, $class;
14}
15
16# Accessors
17sub message { shift->{message} }
18sub return_code { shift->{return_code} }
19sub code { shift->{return_code} }
20
211;
22
23__END__
24
25=head1 NAME
26
27Monitoring::Plugin::ExitResult - Helper class for returning both output and
28return codes when testing.
29
30=head1 SYNOPSIS
31
32 use Test::More;
33 use Monitoring::Plugin::Functions;
34
35 # In a test file somewhere
36 Monitoring::Plugin::Functions::_fake_exit(1);
37
38 # Later ...
39 $e = plugin_exit( CRITICAL, 'aiiii ...' );
40 print $e->message;
41 print $e->return_code;
42
43 # MP::ExitResult also stringifies to the message output
44 like(plugin_exit( WARNING, 'foobar'), qr/^foo/, 'matches!');
45
46
47
48=head1 DESCRIPTION
49
50Monitoring::Plugin::ExitResult is a tiny helper class intended for use
51when testing other Monitoring::Plugin modules. A Monitoring::Plugin::ExitResult
52object is returned by plugin_exit() and friends when
53Monitoring::Plugin::Functions::_fake_exit has been set, instead of doing a
54conventional print + exit.
55
56=head1 AUTHOR
57
58This code is maintained by the Monitoring Plugin Development Team: see
59https://monitoring-plugins.org
60
61Originally:
62 Gavin Carr , E<lt>gavin@openfusion.com.auE<gt>
63
64=head1 COPYRIGHT AND LICENSE
65
66Copyright (C) 2006-2014 Monitoring Plugin Development Team
67
68This library is free software; you can redistribute it and/or modify
69it under the same terms as Perl itself.
70
71=cut