blib/lib/Log/Sigil.pm

filter: Statementstmt 100% 47 / 47 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 98.5% 67 / 68 CC 7 SCAR 14.4
CC
7
Cov
98%
swarn
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.2
↑ Summary
1 package Log::Sigil;
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use Exporter "import";
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use List::Util qw( max );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 our @EXPORT = qw( swarn swarn2 );
10 7 our $VERSION = "1.02";
11  
12 7 our @SIGILS = (
13 qw(
14 =
15 +
16 !
17 @
18 ),
19 q{#},
20 qw(
21 $
22 %
23 ^
24 &
25 *
26 -
27 |
28 \
29 ~
30 ?
31 ),
32 );
33 7 our $TIMES = 3;
34 7 our $SEPARATOR = q{ };
35 7 our $BIAS = 0;
36 7 our %INDEX = ( "main::" => 0 ); # Ensure `values` + 1 is the next.
37 7 my $ANON_REGEX = qr{ (?: .*::__ANON__ | [(]eval[)] ) \z}msx;
38  
39 16 ▶sub swarn {
Subroutine swarn: called CC=7 SCAR=19.5
Pod documented
40 16 my $nth = 0;
41 16 my $bias = 1;
42  
43 16 ▶ $nth++
Branch: 1 branch
BranchTrueFalseTotal
caller $nth and do { ++$nth } 34 16 50
44 while caller $nth;
45  
46 16 my( $package, $filename, $line, $subroutine ) = caller $nth - $bias - $BIAS;
47  
48 16 $bias++;
49  
50 16 ▶ $subroutine = "main::"
Branch: 1 branch
BranchTrueFalseTotal
if $subroutine eq "Log::Sigil::swarn" 2 14 16
51 if $subroutine eq join q{::}, __PACKAGE__, "swarn";
52  
53 16 ▶ $subroutine = "${subroutine}::$line"
Branch: 1 branch
BranchTrueFalseTotal
if $subroutine =~ /$ANON_REGEX/ 9 7 16
54 if $subroutine =~ m{$ANON_REGEX};
55  
56 16 ▶ $bias++
Branch: 1 branch
BranchTrueFalseTotal
if $subroutine =~ /$ANON_REGEX/ 0 16 16
57 if $subroutine =~ m{$ANON_REGEX};
58  
59 16 ▶ if ( my @list = caller $nth - $bias - $BIAS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@list) = ) 14 2 16
60 14 ( undef, undef, $line ) = @list;
61 }
62  
63 16 warn "\$package:\t$package" if DEBUG;
64 16 warn "\$filename:\t$filename" if DEBUG;
65 16 warn "\$line:\t$line" if DEBUG;
66 16 warn "\$subroutine:\t$subroutine" if DEBUG;
67  
68 16 ▶ unless ( exists $INDEX{ $subroutine } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Log::Sigil::INDEX{$subroutine}) 8 8 16
69 8 $INDEX{ $subroutine } = max( values %INDEX ) + 1;
70 }
71  
72 16 my $sigil = $SIGILS[ $INDEX{ $subroutine } % @SIGILS ];
73 16 warn "\$sigil:\t$sigil" if DEBUG;
74 16 unshift @_, $sigil x $TIMES, $SEPARATOR;
75 16 push @_, " by ${filename}[$line]: $subroutine\n"; # Ignore if original has \n at the end.
76  
77 16 warn @_;
78 }
79  
80 2 ▶sub swarn2 {
Subroutine swarn2: called CC=1 SCAR=0.0
Pod documented
81 2 local $BIAS = $BIAS + 1;
82 2 &swarn;
83 }
84  
85 7 1;
86 __END__
↑ Summary