blib/lib/Devel/SummarizedWarnings.pm

filter: Statementstmt 52.2% 23 / 44 Branchbran 15.0% 3 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 3 totaltotal 44.0% 33 / 75 CC 13 SCAR 38.8
CC
13
Cov
41%
dump_warnings
79.8
install_handler
2.2
__ANON__
2.0
CRAP 48.4
↑ Summary
1 package Devel::SummarizedWarnings;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use vars qw(@LOGGED_WARNINGS $INSTALLED_HANDLER $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶sub install_handler {
Subroutine install_handler: called CC=2 SCAR=7.9
Pod undocumented
6 2 my $old_handler = $SIG{'__WARN__'};
7 my $new_handler =
8 ( $old_handler
9 0 ▶ ? sub { &$old_handler; &append_to_warning_log; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
10 2 ▶ : \&append_to_warning_log );
Branch: 1 branch
BranchTrueFalseTotal
$old_handler ? : 0 2 2
11
12 2 $INSTALLED_HANDLER = $SIG{'__WARN__'} = $new_handler;
13
14 2 return;
15 }
16  
17 # Modify this globally
18 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 $VERSION = 0.01;
20 1 install_handler();
21 }
22  
23 1 ▶END {
Subroutine END: called CC=1 SCAR=0.0
24 1 dump_warnings();
25 }
26  
27 1 ▶sub append_to_warning_log {
Subroutine append_to_warning_log: called CC=1 SCAR=0.0
Pod undocumented
28 1 push @LOGGED_WARNINGS, @_;
29 }
30  
31 1 ▶sub dump_warnings {
Subroutine dump_warnings: called CC=12 SCAR=43.8
Pod undocumented
32 1 local $^W;
33 1 ▶ if ( $SIG{'__WARN__'} != $INSTALLED_HANDLER ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SIG{"__WARN__"} != $Devel::SummarizedWarnings::INSTALLED_HANDLER) 0 1 1
34 0 push
35 @LOGGED_WARNINGS,
36 __PACKAGE__ . " was disabled prior to summarization\n";
37 }
38  
39 # Summarize the saved warnings
40 1 my %order;
41 my %sum;
42 1 ▶ while ( my $warning = shift @LOGGED_WARNINGS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $warning = shift @Devel::SummarizedWarnings::LOGGED_WARNINGS) 0 1 1
43 0 my $msg;
44 my $line;
45 0 ▶ if ( not $warning =~ /^(.*) at .+? line (\d+)\.$/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $warning =~ /^(.*) at .+? line (\d+)\.$/s) { } 0 0 0
46 0 $warning =~ s/\n$//;
47 0 $msg = $warning;
48 0 $line = 'NoSuchLine';
49 } else {
50 0 $msg = $1;
51 0 $line = $2;
52 }
53 0 $sum{$msg}{$line}++;
54
55 0 ▶ if ( not exists $order{$msg} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $order{$msg}) 0 0 0
56 0 $order{$msg} = 1 + %order;
57 }
58 }
59  
60 # Reformat the summarization
61 1 my @out;
62 0 for ( sort { $order{$a} <=> $order{$b} }
63 keys %order ) {
64 0 my $wrn = $sum{$_};
65 0 ▶ if ( exists $wrn->{'NoSuchLine'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $wrn->{'NoSuchLine'}) { } 0 0 0
66 push
67 @out,
68 $_
69 0 ▶ . ( $wrn->{'NoSuchLine'} > 1
Branch: 1 branch
BranchTrueFalseTotal
$wrn->{'NoSuchLine'} > 1 ? : 0 0 0
70 ? " (x$wrn->{'NoSuchLine'})"
71 : '' );
72 } else {
73 push
74 @out,
75 0 ▶ "$_ on line@{[1 < keys %$wrn ? 's' : '']} "
Branch: 2 branches
BranchTrueFalseTotal
1 < keys %$wrn ? : 0 0 0
2 == keys %$wrn ? : 0 0 0
76 . join( 2 == keys %$wrn ? ' and ' : ', ',
77 0 ▶ map "$_@{[ $wrn->{$_} == 1
Branch: 1 branch
BranchTrueFalseTotal
$wrn->{$_} == 1 ? : 0 0 0
78 ? ''
79 : qq[ (x$wrn->{$_})]]}",
80 0 sort { $a <=> $b }
81 keys %$wrn );
82 }
83 }
84
85 1 local $\ = "\n";
86 1 print STDERR for @out;
87 }
88  
89 1 1;
90  
91 __END__
↑ Summary