File Coverage

blib/lib/Monitor/MetricsAPI/Metric/Boolean.pm
Criterion Covered Total %
statement 18 20 90.0
branch n/a
condition n/a
subroutine 7 8 87.5
pod 4 4 100.0
total 29 32 90.6


line stmt bran cond sub pod time code
1 13     13   88 use strict;
  13         24  
  13         628  
2 13     13   82 use warnings;
  13         31  
  13         947  
3              
4             package Monitor::MetricsAPI::Metric::Boolean;
5             $Monitor::MetricsAPI::Metric::Boolean::VERSION = '0.900';
6 13     13   72 use namespace::autoclean;
  13         16  
  13         124  
7 13     13   1082 use Moose;
  13         18  
  13         109  
8              
9             extends 'Monitor::MetricsAPI::Metric';
10              
11             =head1 NAME
12              
13             Monitor::MetricsAPI::Metric::Boolean - Boolean metric class for Monitor::MetricsAPI
14              
15             =head1 SYNOPSIS
16              
17             use Monitor::MetricsAPI;
18              
19             my $collector = Monitor::MetricsAPI->new(
20             metrics => { protocols => { ssl { enabled => 'boolean' } } }
21             );
22              
23             # Later on, when your app validates its config and turns on SSL:
24             $collector->metric('protocols/ssl/enabled')->true;
25              
26             =head1 DESCRIPTION
27              
28             Boolean metrics allow you to track the true/false/unknown state of something
29             in your application. All boolean metrics are initialized as unknown and must
30             be explicitly set to either true or false.
31              
32             =cut
33              
34             =head1 METHODS
35              
36             Boolean metrics disable the set() method from L<Monitor::MetricsAPI::Metric>
37             (a warn() is emitted and no action is taken), and provide only the following
38             methods for manipulating their values.
39              
40             =head2 true
41              
42             Sets the metric to true.
43              
44             =cut
45              
46             sub true {
47 2     2 1 3 my ($self) = @_;
48              
49 2         74 return $self->_set_value(1);
50             }
51              
52             =head2 false
53              
54             Sets the metric to false.
55              
56             =cut
57              
58             sub false {
59 1     1 1 3 my ($self) = @_;
60              
61 1         41 return $self->_set_value(0);
62             }
63              
64             =head2 unknown
65              
66             Sets the metric to unknown (will emit a blank value in reporting output).
67              
68             =cut
69              
70             sub unknown {
71 1     1 1 2 my ($self) = @_;
72              
73 1         40 return $self->_clear_value;
74             }
75              
76             =head2 set
77              
78             Overrides the set() method provided by the base Metric class. Emits a warning
79             whenever called, and performs no other actions.
80              
81             =cut
82              
83             sub set {
84 0     0 1   my ($self) = @_;
85              
86 0           warn "set method incorrectly called on boolean metric " . $self->name;
87             }
88              
89             =head1 AUTHORS
90              
91             Jon Sime <jonsime@gmail.com>
92              
93             =head1 LICENSE AND COPYRIGHT
94              
95             This software is copyright (c) 2015 by OmniTI Computer Consulting, Inc.
96              
97             This module is free software; you can redistribute it and/or
98             modify it under the same terms as Perl itself. See L<perlartistic>.
99              
100             This program is distributed in the hope that it will be useful,
101             but WITHOUT ANY WARRANTY; without even the implied warranty of
102             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
103              
104             =cut
105              
106             __PACKAGE__->meta->make_immutable;
107             1;