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