blib/lib/Getopt/Config/FromPod.pm

filter: Statementstmt 95.2% 80 / 84 Branchbran 75.0% 21 / 28 Conditioncond 60.0% 15 / 25 MC/DCmcdc 21.4% 3 / 14 Subroutinesub 100% 18 / 18 Podpod 100% 6 / 6 totaltotal 81.7% 143 / 175 SCAR 33.1
CC
25
Cov
85%
_extract
14.0
_handle_element_start
5.1
_handle_element_end
4.1
CRAP 27.3
↑ Summary
1 package Getopt::Config::FromPod;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Extract getopt configuration from POD
7 7 our $VERSION = 'v0.0.3'; # VERSION
8  
9 package Getopt::Config::FromPod::Extractor;
10  
11 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 7 ▶use parent qw(Pod::Simple);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub new
17 {
18 16 ▶ my ($ref, %args) = @_;
Subroutine new: called CC=3 SCAR=11.1
19 16 ▶ my $class = ref $ref || $ref;
Condition33%1/3
ref $ref || $ref
l!l&&r!l&&!r
0160
MC/DC0%0/2
ref $ref || $ref
ref $ref $ref
Truth table33%1/3
A || B
A= ref $refB= $ref
ABresult
1X1
011
000
20 16 my $self = bless Pod::Simple::new($class, %args), $class;
21 16 ▶ my $tag = $args{-tag} || 'getopt';
Condition100%2/2
$args{'-tag'} || 'getopt'
l!l
412
MC/DC100%1/1
$args{'-tag'} || 'getopt'
$args{'-tag'}
Truth table100%2/2
A
A= $args{'-tag'}
Aresult
11
00
22 16 $self->{_TAG} = $tag;
23 16 $self->accept_targets($tag);
24 16 return $self;
25 }
26  
27 sub _handle_element_start
28 {
29 292 ▶ my ($parser, $element_name, $attr) = @_;
Subroutine _handle_element_start: called CC=5 SCAR=16.2
30 292 ▶ if($element_name eq 'Document') {
Branch: 1 branch
BranchTrueFalseTotal
if ($element_name eq "Document") 16 276 292
31 16 $parser->{_RESULT} = [];
32 }
33 292 ▶ if(($element_name eq 'for' || $element_name eq 'begin') && $attr->{target} eq $parser->{_TAG}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element_name eq "for" || $element_name eq "begin" and $attr->{"target"} eq $parser->{"_TAG"}) 49 243 292
Condition66%4/6
$element_name eq "for" || $element_name eq "begin" and $attr->{"target"} eq $parser->{"_TAG"}
!ll&&!rl&&r
243049
$element_name eq "for" or $element_name eq "begin"
l!l&&r!l&&!r
490243
MC/DC33%1/3
$element_name eq "for" || $element_name eq "begin" and $attr->{"target"} eq $parser->{"_TAG"}
$element_name eq "for" $element_name eq "begin" $attr->{"target"} eq $parser->{"_TAG"}
Truth table40%2/5
A or B and C
A= $element_name eq "for"B= $element_name eq "begin"C= $attr->{"target"} eq $parser->{"_TAG"}
ABCresult
00X0
1X00
0100
1X11
0111
34 49 $parser->{_IN_TARGET} = 1;
35 }
36 }
37  
38 sub _handle_element_end
39 {
40 292 ▶ my ($parser, $element_name, $attr) = @_;
Subroutine _handle_element_end: called CC=4 SCAR=14.1
41 292 ▶ if($element_name eq 'for' || ($element_name eq 'end' && $attr->{target} eq $parser->{_TAG})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element_name eq "for" or $element_name eq "end" and $attr->{"target"} eq $parser->{"_TAG"}) 49 243 292
Condition66%4/6
$element_name eq "for" or $element_name eq "end" and $attr->{"target"} eq $parser->{"_TAG"}
l!l&&r!l&&!r
4923112
$element_name eq "end" and $attr->{"target"} eq $parser->{"_TAG"}
!ll&&!rl&&r
24300
MC/DC33%1/3
$element_name eq "for" or $element_name eq "end" and $attr->{"target"} eq $parser->{"_TAG"}
$element_name eq "for" $element_name eq "end" $attr->{"target"} eq $parser->{"_TAG"}
Truth table50%2/4
A or B and C
A= $element_name eq "for"B= $element_name eq "end"C= $attr->{"target"} eq $parser->{"_TAG"}
ABCresult
1XX1
0111
00X0
0100
42 49 $parser->{_IN_TARGET} = 0;
43 }
44 }
45  
46 sub _handle_text
47 {
48 182 ▶ my ($parser, $text) = @_;
Subroutine _handle_text: called CC=2 SCAR=6.9
49 182 ▶ push @{$parser->{_RESULT}}, eval $text if $parser->{_IN_TARGET}; ## no critic (ProhibitStringyEval)
Branch: 1 branch
BranchTrueFalseTotal
if $parser->{"_IN_TARGET"} 49 133 182
50 }
51  
52 package Getopt::Config::FromPod;
53  
54 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 sub new
57 {
58 15 ▶ my $self = shift;
Subroutine new: called CC=2 SCAR=7.6
Pod documented
59 15 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
0150
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
60 15 return bless { _ARG => \@_ }, $class;
61 }
62  
63 sub _extract
64 {
65 16 ▶ my ($self, %args) = @_;
Subroutine _extract: called CC=11 SCAR=26.4
66 16 %args = (@{$self->{_ARG}}, %args);
67 16 my $parser = Getopt::Config::FromPod::Extractor->new(%args);
68 16 my $file = $args{-file};
69 16 ▶ $args{-package} ||= 'main';
Condition50%1/2
$args{"-package"} ||= "main"
l!l
016
MC/DC0%0/1
$args{"-package"} ||= "main"
$args{"-package"}
Truth table50%1/2
A
A= $args{"-package"}
Aresult
11
00
70 16 ▶ if(! defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 8 8 16
71 8 my $idx = 0;
72 8 my @caller;
73 8 ▶ while(@caller = caller($idx++)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@caller = caller $idx++) 22 0 22
74 22 ▶ if($caller[0] eq $args{-package}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller[0] eq $args{"-package"}) 8 14 22
75 8 $file = $caller[1];
76 8 last;
77 }
78 }
79 8 ▶ confess "Target module not found" if ! defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 8 8
80 # At least, in PAR environment, this adjustment is necessary.
81 8 ▶ if(! -f $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $file) 0 8 8
82 0 for my $inc (@INC) {
83 0 ▶ if(-f "$inc/$file") {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "$inc/$file") 0 0 0
84 0 $file = "$inc/$file";
85 0 last;
86 }
87 }
88 }
89 }
90 16 ▶ croak "Target file not found: $file" if ref $file eq '' && ! -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if ref $file eq "" and not -f $file 0 16 16
Condition66%2/3
ref $file eq "" and not -f $file
!ll&&!rl&&r
4120
MC/DC0%0/2
ref $file eq "" and not -f $file
ref $file eq "" not -f $file
Truth table66%2/3
A and not(B)
A= ref $file eq ""B= not -f $file
ABresult
0X0
100
111
91 16 $parser->parse_file($file);
92 16 return $parser->{_RESULT};
93 }
94  
95 7 my $SELF = __PACKAGE__->new;
96  
97 sub __ref
98 {
99 30 ▶ my $ref = shift;
Subroutine __ref: called CC=3 SCAR=11.0
100 30 ▶ return if ref $ref->[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref->[0] 24 6 30
101 6 ▶ croak 'Calling as neither instance method nor class method' unless eval { $ref->[0]->isa(__PACKAGE__) };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $ref->[0]->isa(__PACKAGE__) } } 0 6 6
102 6 splice @$ref, 0, 1, $SELF;
103 }
104  
105 sub string
106 {
107 6 ▶ __ref(\@_);
Subroutine string: called CC=2 SCAR=6.9
Pod documented
108 6 my ($self, %args) = @_;
109 6 ▶ return join(exists $args{-separator} ? $args{-separator} : '', $self->array(%args));
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'-separator'} ? : 1 5 6
110 }
111  
112 sub array
113 {
114 16 ▶ __ref(\@_);
Subroutine array: called CC=1 SCAR=0.0
Pod documented
115 16 my ($self, %args) = @_;
116 16 return @{$self->_extract(%args)};
117 }
118  
119 sub arrayref
120 {
121 4 ▶ __ref(\@_);
Subroutine arrayref: called CC=1 SCAR=0.0
Pod documented
122 4 my ($self, %args) = @_;
123 4 return [$self->array(%args)];
124 }
125  
126 sub hashref
127 {
128 4 ▶ __ref(\@_);
Subroutine hashref: called CC=1 SCAR=0.0
Pod documented
129 4 my ($self, %args) = @_;
130 4 return {$self->array(%args)};
131 }
132  
133 sub set_class_default
134 {
135 2 ▶ my ($self, %args) = @_;
Subroutine set_class_default: called CC=1 SCAR=0.0
Pod documented
136 2 $SELF = __PACKAGE__->new(%args);
137 }
138  
139 7 1;
140  
141 __END__
↑ Summary