| 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
MC/DC0%0/2
ref $ref || $ref
ref $ref
$ref
Truth table33%1/3
A || B
A= ref $refB= $ref
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 16 | my $self = bless Pod::Simple::new($class, %args), $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 16 | ▶ | my $tag = $args{-tag} || 'getopt'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'-tag'} || 'getopt'
MC/DC100%1/1
$args{'-tag'} || 'getopt'
$args{'-tag'}
Truth table100%2/2
A
A= $args{'-tag'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 16 | $parser->{_RESULT} = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 292 | ▶ | if(($element_name eq 'for' || $element_name eq 'begin') && $attr->{target} eq $parser->{_TAG}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$element_name eq "for" || $element_name eq "begin" and $attr->{"target"} eq $parser->{"_TAG"}
$element_name eq "for" or $element_name eq "begin"
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
$element_name eq "for" or $element_name eq "end" and $attr->{"target"} eq $parser->{"_TAG"}
$element_name eq "end" and $attr->{"target"} eq $parser->{"_TAG"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$args{"-package"} ||= "main"
$args{"-package"}
Truth table50%1/2
A
A= $args{"-package"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 16 | ▶ | if(! defined $file) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 8 | my $idx = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 8 | my @caller; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 8 | ▶ | while(@caller = caller($idx++)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 22 | ▶ | if($caller[0] eq $args{-package}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 8 | $file = $caller[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 8 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 8 | ▶ | confess "Target module not found" if ! defined $file; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # At least, in PAR environment, this adjustment is necessary. | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 8 | ▶ | if(! -f $file) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | for my $inc (@INC) { | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if(-f "$inc/$file") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
ref $file eq "" and not -f $file
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | ▶ | croak 'Calling as neither instance method nor class method' unless eval { $ref->[0]->isa(__PACKAGE__) }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||