Agent/Tag/Priority.pm

filter: Statementstmt 100% 29 / 29 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 97.3% 37 / 38 CC 3 SCAR 6.9
CC
3
Cov
100%
make
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« Agent/Tag/String.pm ↑ Summary Agent/Channel.pm »
1 ###########################################################################
2 #
3 # Priority.pm
4 #
5 # Copyright (C) 1999 Raphael Manfredi.
6 # Copyright (C) 2002-2017 Mark Rogaski, mrogaski@cpan.org;
7 # all rights reserved.
8 #
9 # See the README file included with the
10 # distribution for license information.
11 #
12 ##########################################################################
13  
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 ########################################################################
17 package Log::Agent::Tag::Priority;
18  
19 1 require Log::Agent::Tag::String;
20 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 @ISA = qw(Log::Agent::Tag::String);
22  
23 1 ▶use Log::Agent::Priorities qw(level_from_prio prio_from_level);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 #
26 # ->make
27 #
28 # Creation routine.
29 #
30 # Calling arguments: a hash table list.
31 #
32 # The keyed argument list may contain:
33 # -POSTFIX whether to postfix log message or prefix it.
34 # -SEPARATOR separator string to use between tag and message
35 # -DISPLAY a string like '[$priority:$level])'
36 # -PRIORITY the log priority string, e.g. "warning".
37 # -LEVEL the log level value, e.g. 4.
38 #
39 # Attributes:
40 # none, besides the inherited ones
41 #
42 5 ▶sub make {
Subroutine make: called CC=3 SCAR=11.0
Pod undocumented
43 5 my $type = shift;
44 5 my (%args) = @_;
45 5 my $separator = " ";
46 5 my $postfix = 0;
47 5 my ($display, $priority, $level);
48  
49 5 my %set = (
50 -display => \$display,
51 -postfix => \$postfix,
52 -separator => \$separator,
53 -priority => \$priority,
54 -level => \$level,
55 );
56  
57 5 ▶ while (my ($arg, $val) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 20 5 25
58 20 my $vset = $set{lc($arg)};
59 20 ▶ next unless ref $vset;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $vset 5 15 20
60 15 $$vset = $val;
61 }
62  
63 #
64 # Normalize $priority to the full name (e.g. "err" -> "error")
65 #
66  
67 5 $priority = prio_from_level level_from_prio $priority;
68  
69 #
70 # Format according to -display specs.
71 #
72 # Since priority and level are fixed for this object, the resulting
73 # string need only be computed once, i.e. now.
74 #
75 # The following variables are recognized:
76 #
77 # $priority priority name (e.g. "warning")
78 # $level logging level
79 #
80 # We recognize both $level and ${level}.
81 #
82  
83 5 $display =~ s/\$priority\b/$priority/g;
84 5 $display =~ s/\$\{priority}/$priority/g;
85 5 $display =~ s/\$level\b/$level/g;
86 5 $display =~ s/\$\{level}/$level/g;
87  
88 #
89 # Now create the constant tag string.
90 #
91  
92 5 my $self = Log::Agent::Tag::String->make(
93 -name => "priority",
94 -value => $display,
95 -postfix => $postfix,
96 -separator => $separator,
97 );
98  
99 5 return bless $self, $type; # re-blessed in our package
100 }
101  
102 1 1; # for "require"
103 __END__
« Agent/Tag/String.pm ↑ Summary Agent/Channel.pm »