blib/lib/Acme/Beamerang/Logger.pm

filter: Statementstmt 100% 30 / 30 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 90.3% 47 / 52 CC 6 SCAR 10.4
CC
6
Cov
95%
_get_prefixes
5.0
arg_default_logger
2.0
BEGIN
1.0
CRAP 2.8
↑ Summary
1 4 ▶use 5.006; # our
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Acme::Beamerang::Logger;
6  
7 4 our $VERSION = '0.001000';
8  
9 4 ▶use parent 'Log::Contextual';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶sub default_import { qw(:dlog :log ) }
Subroutine default_import: called CC=1 SCAR=0.0
Pod undocumented
12  
13 # This ideally would be regulated by the importing class
14 # but I got tired of trying to guess what horrible magic
15 # was necessary to make Exporter::Declare and whatever
16 # the hell Log::Contextual's import logic does work.
17 4 ▶sub _get_prefixes {
Subroutine _get_prefixes: called CC=5 SCAR=16.1
18 4 my $class = $_[0];
19 4 my (@parts) = split /::/sx, $class;
20  
21 # Always assume there is no Acme
22 # Acme::X is X in the future.
23 4 ▶ shift @parts if $parts[0] eq 'Acme';
Branch: 1 branch
BranchTrueFalseTotal
if $parts[0] eq "Acme" 1 3 4
24  
25 4 my (@prefixes);
26  
27 # Always include FQ name, sans Acme
28 4 push @prefixes, uc( join q/_/, @parts );
29 4 pop @parts;
30  
31 # If its a Beamerang subclass, split the namespace
32 # and create env vars for each level.
33 4 ▶ if ( 2 <= @parts and ( 'Beamerang' eq shift @parts ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (2 <= @parts and "Beamerang" eq shift @parts) 2 2 4
Condition66%2/3
2 <= @parts and "Beamerang" eq shift @parts
!ll&&!rl&&r
202
MC/DC50%1/2
2 <= @parts and "Beamerang" eq shift @parts
2 <= @parts "Beamerang" eq shift @parts
Truth table66%2/3
A and B
A= 2 <= @partsB= "Beamerang" eq shift @parts
ABresult
0X0
100
111
34 2 ▶ while (@parts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts) 2 2 4
35 2 push @prefixes, uc( join q/_/, 'BEAMERANG', @parts );
36 2 pop @parts;
37 }
38 }
39 4 return @prefixes, 'BEAMERANG';
40 }
41  
42 4 ▶sub arg_default_logger {
Subroutine arg_default_logger: called CC=2 SCAR=7.0
Pod undocumented
43 4 ▶ return $_[1] if $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 0 4 4
44 4 require Log::Contextual::WarnLogger::Fancy;
45 4 my $caller = caller(3);
46  
47 4 my ( $env, @group ) = _get_prefixes($caller);
48 4 return Log::Contextual::WarnLogger::Fancy->new(
49 {
50 env_prefix => $env,
51 group_env_prefix => \@group,
52 label => $caller,
53 label_length => 21,
54 default_upto => 'warn',
55 }
56 );
57 }
58  
59 4 1;
60  
61 =head1 NAME
62  
63 Acme::Beamerang::Logger - A Simple per-class clan warnlogger loader
64  
65 =head1 SYNOPSIS
66  
67 # Interface is basically the same as Log::Contextual::Easy::Default
68 use Acme::Beamerang::Logger; # imports :dlog and :log by default
69 # also assigns a default logger to the package.
70  
71 =head1 DESCRIPTION
72  
73 This class is a convenience layer to tie L<Log::Contextual::WarnLogger::Fancy>
74 into the C<Acme::Beamerang> project space.
75  
76 This is very experiemental and is a research project ( hence C<Acme::> ).
77  
78 This would otherwise be part of the other C<Acme::Beamerang> things that are still yet to
79 materialise, but the inversion control this project entails means directly coupling
80 this component with either of those parts would lead to a dependency graph that would
81 defeat the point of the control inversion.
82  
83 This tool otherwise loads up C<Log::Contextual> with a nice default logger, with all the glue
84 in place to be convenient for this project, while still having an open door to a real logger.
85  
86 =head1 ENVIRONMENT
87  
88 This module utilizes the C<env_prefix> and C<group_env_prefix> of L<Log::Contextual::WarnLogger::Fancy>
89 to generate a collection of C<ENV> vars for narrow or broad incision of logging statements without need
90 to use more complex logging technology.
91  
92 Every package that uses this logger will respond to C<BEAMERANG_$LOG_LEVEL> and C<BEAMERANG_UPTO> values.
93  
94 Every package beginning with either C<Acme::Beamerang::> or C<Beamerang::> will additionally respond to
95 a collection of namespace oriented C<ENV> variables.
96  
97 For instance,
98  
99 Acme::Beamerang::Foo::Bar::Baz
100  
101 Will respond to any of the following C<ENV> vars:
102  
103 BEAMERANG_FOO_BAR_BAZ_$LEVEL
104 BEAMERANG_FOO_BAR_$LEVEL
105 BEAMERANG_FOO_$LEVEL
106 BEAMERANG_$LEVEL
107 BEAMERNAG_FOO_BAR_BAZ_UPTO
108 BEAMERANG_FOO_BAR_UPTO
109 BEAMERANG_FOO_UPTO
110 BEAMERANG_UPTO
111  
112 This means you can turn on debugging for as much, or as little as you like, without
113 having to radically change the code.
114  
115 =head1 NAMING
116  
117 =head2 Acme
118  
119 Firstly, this is named C<Acme::>, because its a bunch of bad ideas glued together, and I
120 don't want people to use this until its "ready", but I'm going to need to use it lots before I get comfortable
121 anything right is done.
122  
123 When its ready (if ever), it will ship as C<Beamerang::> ... maybe.
124  
125 =head2 Beamerang
126  
127 This is my dumb joke based on C<Beam>, which this compontent is going to end up being used in conjunction with.
128  
129 I thought at first C<Beam> -> C<Boom>, but then that was too high level.
130  
131 And then I thought C<Boomerang> .... but eh, I didn't like that either.
132  
133 So C<Beamerang> is a mutant hybrid of the above.
134  
135 Other parts of this system that have yet to manifest will use the same convention.
136  
137 =head1 SEE ALSO
138  
139 =over 4
140  
141 =item * L<< C<Log::Contextual::Easy::Default>|Log::Contextual::Easy::Default >> - Interface is otherwise identical to this
142 module, only the default logger in choice and its configuration differs.
143  
144 =back
145  
146 =head1 AUTHOR
147  
148 Kent Fredric <kentnl@cpan.org>
149  
150 =head1 LICENSE
151  
152 This software is copyright (c) 2016 by Kent Fredric.
153  
154 This is free software; you can redistribute it and/or modify it under the
155 same terms as the Perl 5 programming language system itself.
156  
157 =cut
↑ Summary