blib/lib/Dancer2/Plugin/RoutePodCoverage.pm

filter: Statementstmt 94.8% 74 / 78 Branchbran 80.7% 21 / 26 Conditioncond 41.6% 5 / 12 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 84.0% 111 / 132 CC 22 SCAR 26.1
CC
22
Cov
86%
_get_routes
19.9
__ANON__
5.5
BEGIN
1.0
CRAP 13.6
↑ Summary
1 package Dancer2::Plugin::RoutePodCoverage;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Dancer2::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Pod::Simple::Search;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Pod::Simple::SimpleTree;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 our $VERSION = '0.071';
12  
13 3 my $PACKAGES_TO_COVER = [];
14  
15 2 ▶register 'packages_to_cover' => sub {
Subroutine __ANON__: called CC=4 SCAR=17.1
16 2 my ( $dsl, $packages_to_cover ) = @_;
17 2 ▶ croak "no package(s) provided for 'packages_to_cover' "
Branch: 1 branch
BranchTrueFalseTotal
if not $packages_to_cover or ref $packages_to_cover ne "ARRAY" or not @$packages_to_cover 0 2 2
Condition33%2/6
not $packages_to_cover or ref $packages_to_cover ne "ARRAY" or not @$packages_to_cover
l!l&&r!l&&!r
002
not $packages_to_cover or ref $packages_to_cover ne "ARRAY"
l!l&&r!l&&!r
002
MC/DC0%0/3
not $packages_to_cover or ref $packages_to_cover ne "ARRAY" or not @$packages_to_cover
not $packages_to_cover ref $packages_to_cover ne "ARRAY" not @$packages_to_cover
Truth table25%1/4
not(A) or B or not(C)
A= not $packages_to_coverB= ref $packages_to_cover ne "ARRAY"C= not @$packages_to_cover
ABCresult
1XX1
01X1
0011
0000
18 if ( !$packages_to_cover
19 || ref $packages_to_cover ne 'ARRAY'
20 || !@$packages_to_cover );
21 2 $PACKAGES_TO_COVER = $packages_to_cover;
22 3 };
23  
24 3 ▶register 'routes_pod_coverage' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
25 3 return _get_routes(@_);
26 3 };
27  
28 3 ▶sub _get_routes {
Subroutine _get_routes: called CC=19 SCAR=29.9
29 3 my ($dsl) = @_;
30 3 my @apps = @{ $dsl->runner->apps };
31 3 my $all_routes = {};
32  
33 3 for my $app (@apps) {
34 next
35 9 ▶ if ( @$PACKAGES_TO_COVER && !grep { $app->name eq $_ }
Branch: 1 branch
BranchTrueFalseTotal
if @$PACKAGES_TO_COVER and not grep({$app->name eq $_;} @$PACKAGES_TO_COVER) 4 5 9
Condition100%3/3
@$PACKAGES_TO_COVER and not grep({$app->name eq $_;} @$PACKAGES_TO_COVER)
!ll&&!rl&&r
324
MC/DC100%2/2
@$PACKAGES_TO_COVER and not grep({$app->name eq $_;} @$PACKAGES_TO_COVER)
@$PACKAGES_TO_COVER not grep({$app->name eq $_;} @$PACKAGES_TO_COVER)
Truth table100%3/3
A and not(B)
A= @$PACKAGES_TO_COVERB= not grep({$app->name eq $_;} @$PACKAGES_TO_COVER)
ABresult
0X0
100
111
36 @$PACKAGES_TO_COVER );
37 5 my $routes = $app->routes;
38 5 my $available_routes = [];
39 5 foreach my $method ( sort { $b cmp $a } keys %$routes ) {
40 30 foreach my $r ( @{ $routes->{$method} } ) {
41  
42 # we don't need pod coverage for head
43 10 ▶ next if $method eq 'head';
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "head" 2 8 10
44 8 push @$available_routes, $method . ' ' . $r->spec_route;
45 }
46 }
47 5 ▶ next unless @$available_routes;
Branch: 1 branch
BranchTrueFalseTotal
unless @$available_routes 1 4 5
48  
49 ## copy unreferenced array
50 4 $all_routes->{ $app->name }{routes} = [@$available_routes];
51  
52 4 my $undocumented_routes = [];
53 4 my $file = Pod::Simple::Search->new->find( $app->name );
54 4 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) { } 4 0 4
55 4 $all_routes->{ $app->name }{ has_pod } = 1;
56 4 my $parser = Pod::Simple::SimpleTree->new->parse_file($file);
57 4 my $pod_dataref = $parser->root;
58 4 my $found_routes = {};
59 4 ▶ for ( my $i = 0 ; $i < @$available_routes ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$available_routes) 8 4 12
60  
61 8 my $r = $available_routes->[$i];
62 8 my $app_string = lc $r;
63 8 $app_string =~ s/\*/_REPLACED_STAR_/g;
64  
65 8 ▶ for ( my $idx = 0 ; $idx < @$pod_dataref ; $idx++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < @$pod_dataref) 64 8 72
66 64 my $pod_part = $pod_dataref->[$idx];
67  
68 64 ▶ next if ref $pod_part ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $pod_part ne "ARRAY" 16 48 64
69 48 foreach my $ref_part (@$pod_part) {
70 148 ▶ if (ref($ref_part) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref_part eq "ARRAY") 8 140 148
71 8 push @$pod_dataref, $ref_part;
72 }
73 }
74  
75 48 my $pod_string = lc $pod_part->[2];
76 48 $pod_string =~ s/['|"|\s]+/ /g;
77 48 $pod_string =~ s/\s$//g;
78 48 $pod_string =~ s/\*/_REPLACED_STAR_/g;
79 48 ▶ if ( $pod_string =~ m/^$app_string$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pod_string =~ /^$app_string$/) 4 44 48
80 4 $found_routes->{$app_string} = 1;
81 4 next;
82 }
83 }
84 8 ▶ if ( !$found_routes->{$app_string} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found_routes->{$app_string}) 6 2 8
85 6 push @$undocumented_routes, $r;
86 }
87 }
88 }
89 else { ### no POD found
90 0 $all_routes->{ $app->name }{ has_pod } = 0;
91 }
92 4 ▶ if (@$undocumented_routes) {
Branch: 2 branches
BranchTrueFalseTotal
if (@$undocumented_routes) { } 4 0 4
elsif (not $$all_routes{$app->name}{'has_pod'} and @{$$all_routes{$app->name}{'routes'};}) { } 0 0 0
93 4 $all_routes->{ $app->name }{undocumented_routes} = $undocumented_routes;
94 }
95 ▶ elsif (! $all_routes->{ $app->name }{ has_pod }
Condition0%0/3
not $$all_routes{$app->name}{"has_pod"} and @{$$all_routes{$app->name}{"routes"};}
!ll&&!rl&&r
000
MC/DC0%0/2
not $$all_routes{$app->name}{"has_pod"} and @{$$all_routes{$app->name}{"routes"};}
not $$all_routes{$app->name}{"has_pod"} @{$$all_routes{$app->name}{"routes"};}
Truth table0%0/3
not(A) and B
A= not $$all_routes{$app->name}{"has_pod"}B= @{$$all_routes{$app->name}{"routes"};}
ABresult
0X0
100
111
96 0 && @{$all_routes->{ $app->name }{routes}} ){
97 ## copy dereferenced array
98 0 $all_routes->{ $app->name }{undocumented_routes} = [@{$all_routes->{ $app->name }{routes}}];
99 }
100 }
101 3 return $all_routes;
102 }
103  
104 3 register_plugin;
105  
106 3 1;
107  
108 __END__
↑ Summary