blib/lib/PPIx/DocumentName.pm

filter: Statementstmt 76.3% 42 / 55 Branchbran 66.6% 8 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 68.7% 11 / 16 Podpod 100% 3 / 3 totaltotal 72.5% 66 / 91 SCAR 22.1
CC
8
Cov
74%
extract_via_statement
4.1
__ANON__
3.1
BEGIN
2.4
CRAP 9.1
↑ 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 PPIx::DocumentName;
6  
7 4 our $VERSION = '0.001003';
8  
9 # ABSTRACT: Utility to extract a name from a PPI Document
10  
11 4 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 4 ▶use PPI::Util qw( _Document );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16  
17  
18 sub log_info(&@);
19 sub log_debug(&@);
20 sub log_trace(&@);
21  
22 BEGIN {
23 4 ▶ if ( $INC{'Log/Contextual.pm'} ) {
Subroutine BEGIN: called CC=2 SCAR=8.7
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{'Log/Contextual.pm'}) { } 0 4 4
24 ## Hide from autoprereqs
25 0 require 'Log/Contextual/WarnLogger.pm'; ## no critic (Modules::RequireBarewordIncludes)
26 0 my $deflogger = Log::Contextual::WarnLogger->new( { env_prefix => 'PPIX_DOCUMENTNAME', } );
27 0 Log::Contextual->import( 'log_info', 'log_debug', 'log_trace', '-default_logger' => $deflogger );
28 }
29 else {
30 4 require Carp;
31 4 ▶ *log_info = sub (&@) { Carp::carp( $_[0]->() ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
32 4 ▶ *log_debug = sub (&@) { };
Subroutine __ANON__: called CC=1 SCAR=0.0
33 4 ▶ *log_trace = sub (&@) { };
Subroutine __ANON__: called CC=1 SCAR=0.0
34 }
35 }
36  
37 ## OO
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51 sub extract {
52 3 ▶ my ( $self, $ppi_document ) = @_;
Subroutine extract: called CC=2 SCAR=7.0
Pod documented
53 3 ▶ my $docname = $self->extract_via_comment($ppi_document)
Condition66%2/3
$self->extract_via_comment($ppi_document) || $self->extract_via_statement($ppi_document)
l!l&&r!l&&!r
120
MC/DC0%0/2
$self->extract_via_comment($ppi_document) || $self->extract_via_statement($ppi_document)
$self->extract_via_comment($ppi_document) $self->extract_via_statement($ppi_document)
Truth table66%2/3
A || B
A= $self->extract_via_comment($ppi_document)B= $self->extract_via_statement($ppi_document)
ABresult
1X1
011
000
54 || $self->extract_via_statement($ppi_document);
55  
56 3 return $docname;
57 }
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70 sub extract_via_statement {
71 5 ▶ my ( undef, $ppi_document ) = @_;
Subroutine extract_via_statement: called CC=3 SCAR=14.2
Pod documented
72  
73 # Keep alive until done
74 # https://github.com/adamkennedy/PPI/issues/112
75 5 my $dom = _Document($ppi_document);
76 5 my $pkg_node = $dom->find_first('PPI::Statement::Package');
77 5 ▶ if ( not $pkg_node ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pkg_node) 0 5 5
78 0 ▶ log_debug { "No PPI::Statement::Package found in <<$ppi_document>>" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
79 0 return;
80 }
81 5 ▶ if ( not $pkg_node->namespace ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pkg_node->namespace) 0 5 5
82 0 ▶ log_debug { "PPI::Statement::Package $pkg_node has empty namespace in <<$ppi_document>>" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 0 return;
84 }
85 5 return $pkg_node->namespace;
86 }
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99 sub extract_via_comment {
100 6 ▶ my ( undef, $ppi_document ) = @_;
Subroutine extract_via_comment: called CC=2 SCAR=7.0
Pod documented
101 6 my $regex = qr{ ^ \s* \#+ \s* PODNAME: \s* (.+) $ }x; ## no critic (RegularExpressions)
102 6 my $content;
103 my $finder = sub {
104 82 ▶ my $node = $_[1];
Subroutine __ANON__: called CC=3 SCAR=11.4
105 82 ▶ return 0 unless $node->isa('PPI::Token::Comment');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->isa("PPI::Token::Comment") 80 2 82
106 2 ▶ log_trace { "Found comment node $node" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
107 2 ▶ if ( $node->content =~ $regex ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->content =~ /$regex/) 2 0 2
108 2 $content = $1;
109 2 return 1;
110 }
111 0 return 0;
112 6 };
113  
114 # Keep alive until done
115 # https://github.com/adamkennedy/PPI/issues/112
116 6 my $dom = _Document($ppi_document);
117 6 $dom->find_first($finder);
118  
119 6 ▶ log_debug { "<<$ppi_document>> has no PODNAME comment" } if not $content;
Subroutine __ANON__: not called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless $content 4 2 6
120  
121 6 return $content;
122 }
123  
124 4 1;
125  
126 __END__
↑ Summary