File Coverage

blib/lib/App/PerlWatcher/Levels.pm
Criterion Covered Total %
statement 32 32 100.0
branch 1 2 50.0
condition n/a
subroutine 10 10 100.0
pod 0 1 0.0
total 43 45 95.5


line stmt bran cond sub pod time code
1             package App::PerlWatcher::Levels;
2             {
3             $App::PerlWatcher::Levels::VERSION = '0.20';
4             }
5             # ABSTRACT: Creates constants pool for all available levels for application
6              
7 13     13   874440 use 5.12.0;
  13         50  
  13         581  
8 13     13   67 use strict;
  13         30  
  13         407  
9 13     13   679 use warnings;
  13         39  
  13         371  
10              
11 13     13   80 use Carp;
  13         131  
  13         1050  
12 13     13   69 use Exporter;
  13         22  
  13         582  
13              
14 13     13   9127 use App::PerlWatcher::Level;
  13         39  
  13         451  
15              
16 13     13   110 use parent qw/Exporter/;
  13         25  
  13         117  
17              
18             our %_INSTANCE_FOR;
19              
20              
21             sub _create {
22 78     78   126 my ($level_value, $level_description) = @_;
23 78         6871 my $level = App::PerlWatcher::Level->new(
24             value => $level_value,
25             description => $level_description,
26             );
27 78         23501 $_INSTANCE_FOR{$level_description} = $level;
28 78         3214 return $level;
29             }
30              
31             sub get_by_description {
32 200     200 0 352 my $description = shift;
33 200         320 my $level = $_INSTANCE_FOR{$description};
34 200 50       1264 carp "unknown level '$description'"
35             unless $level;
36 200         1547 return $level;
37             }
38              
39             use constant {
40 13         49 LEVEL_ANY => _create(0, 'unknown'),
41              
42             LEVEL_NOTICE => _create(2, 'notice'),
43             LEVEL_INFO => _create(3, 'info'),
44             LEVEL_WARN => _create(4, 'warn'),
45             LEVEL_ALERT => _create(5, 'alert'),
46             LEVEL_IGNORE => _create(10, 'ignore'),
47 13     13   3661 };
  13         37  
48              
49             our @ALL_LEVELS = (
50             LEVEL_ANY,
51              
52             LEVEL_NOTICE,
53             LEVEL_INFO,
54             LEVEL_WARN,
55             LEVEL_ALERT,
56              
57             LEVEL_IGNORE,
58             );
59              
60             my @all_levels_strings = qw
61             /
62             LEVEL_ANY
63              
64             LEVEL_NOTICE
65             LEVEL_INFO
66             LEVEL_WARN
67             LEVEL_ALERT
68              
69             LEVEL_IGNORE
70             /;
71              
72             our @EXPORT = (qw/get_by_description/, @all_levels_strings);
73              
74             1;
75              
76             __END__