blib/lib/Devel/Cover/Report/Compilation.pm untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 135 CC 17 SCAR 32.6
CC
17
Cov
0%
print_branches
42.0
report
42.0
print_conditions
20.0
CRAP 26.0
1 # Copyright 2001-2026, Paul Johnson (paul@pjcj.net)
2  
3 # This software is free. It is licensed under the same terms as Perl itself.
4  
5 # ############################################################################ #
6 # 2006-09-14 Denis Howe
7 # Cloned from 0.59 Text.pm and hacked to give a minimal output in a
8 # format similar to that output by Perl itself so that it's easier to
9 # step through the untested locations with Emacs compilation mode
10 # Copyright assigned to Paul Johnson
11 # ############################################################################ #
12  
13 # The latest version of this software should be available from my homepage:
14 # https://pjcj.net
15  
16 package Devel::Cover::Report::Compilation;
17  
18 use strict;
19 use warnings;
20  
21 our $VERSION = '1.52'; # VERSION
22  
23 # TODO - uncoverable code?
24  
25 sub print_statement {
26 my ($db, $file, $options) = @_;
27  
28 my $statements = $db->cover->file($file)->statement or return;
29  
30 for my $location ($statements->items) {
31 my $l = $statements->location($location);
32 for my $statement (@$l) {
33 next if $statement->covered;
34 print "Uncovered statement at $file line $location:\n";
35 }
36 }
37 }
38  
39 sub print_branches {
40 my ($db, $file, $options) = @_;
41  
42 my $branches = $db->cover->file($file)->branch or return;
43  
44 for my $location (sort { $a <=> $b } $branches->items) {
45 for my $b (@{ $branches->location($location) }) {
46 next unless $b->error;
47  
48 # One or both paths from this branch weren't reached.
49 # $b->covered(0) and (1) say whether the first and second
50 # paths were reached. If the branch condition text begins
51 # with "unless" then the meanings of 0 and 1 are swapped.
52 # The output is easier to understand if we strip off
53 # "unless" and say whether the remaining condition was
54 # true or false.
55  
56 my $text = $b->text;
57 my ($t, $f) = map $b->covered($_),
58 $text =~ s/^(if|unless) // && $1 eq "unless" ? (1, 0) : (0, 1);
59 # TODO - uncoverable code?
60 print "Branch never ",
61 $t ? ($f ? "???" : "false") : ($f ? "true" : "reached"),
62 " at $file line $location: $text\n";
63 }
64 }
65 }
66  
67 sub print_conditions {
68 my ($db, $file, $options) = @_;
69  
70 my $conditions = $db->cover->file($file)->condition or return;
71  
72 my $template = sub { "%-5s %3s %6s " . ("%6s " x shift) . " %s\n" };
73  
74 my %r;
75 for my $location (sort { $a <=> $b } $conditions->items) {
76 my %seen;
77 for my $c (@{ $conditions->location($location) }) {
78 push @{ $r{ $c->type } }, [ $c, $seen{ $c->type }++ ? "" : $location ];
79 }
80 }
81  
82 my %seen;
83 for my $type (sort keys %r) {
84 for (@{ $r{$type} }) {
85 my ($c, $location) = @$_;
86 next unless $c->error;
87 my @headers = @{ $c->headers };
88 print "Uncovered condition (",
89 join(", ", map !$c->covered($_) ? $headers[$_] : (),
90 0 .. $c->total - 1), ") at $file line $location: ", $c->text, "\n";
91 }
92 }
93 }
94  
95 sub print_subroutines {
96 my ($db, $file, $options) = @_;
97  
98 my $subroutines = $db->cover->file($file)->subroutine or return;
99  
100 for my $location ($subroutines->items) {
101 my $l = $subroutines->location($location);
102 for my $sub (@$l) {
103 next if $sub->covered;
104 print "Uncovered subroutine ", $sub->name, " at $file line $location\n";
105 }
106 }
107 }
108  
109 sub print_pod {
110 my ($db, $file, $options) = @_;
111  
112 my $pod = $db->cover->file($file)->pod or return;
113  
114 for my $location ($pod->items) {
115 my $l = $pod->location($location);
116 for my $p (@$l) {
117 next if $p->covered;
118 print "Uncovered pod at $file line $location\n";
119 }
120 }
121 }
122  
123 sub report {
124 my ($pkg, $db, $options) = @_;
125  
126 for my $file (@{ $options->{file} }) {
127 print_statement($db, $file, $options) if $options->{show}{statement};
128 print_branches($db, $file, $options) if $options->{show}{branch};
129 print_conditions($db, $file, $options) if $options->{show}{condition};
130 print_subroutines($db, $file, $options) if $options->{show}{subroutine};
131 print_pod($db, $file, $options) if $options->{show}{pod};
132 }
133 }
134  
135 1
136  
137 __END__