Expand/Permutation.pm

filter: Statementstmt 91.4% 32 / 35 Branchbran 64.2% 9 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 80.6% 50 / 62 CC 9 SCAR 15.6
CC
9
Cov
81%
_percent_expand
7.5
expand
3.3
BEGIN
1.0
CRAP 4.8
↑ Summary Expand.pm »
1 package Text::Glob::Expand::Permutation;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '1.1.1'; # VERSION
7  
8 ######################################################################
9 # Private methods
10  
11 90 ▶sub _percent_expand {
Subroutine _percent_expand: called CC=7 SCAR=20.2
12 90 my $self = shift;
13 90 my $match = shift;
14  
15 90 ▶ if ($match eq "%") {
Branch: 1 branch
BranchTrueFalseTotal
if ($match eq "%") 0 90 90
16 0 return "%";
17 }
18  
19 90 ▶ if ($match eq "0") {
Branch: 1 branch
BranchTrueFalseTotal
if ($match eq 0) 34 56 90
20 34 return $self->[0];
21 }
22  
23 56 my $curr = $self;
24 56 my @digits = split /[.]/, $1;
25  
26 56 ▶ while(@digits) {
Branch: 1 branch
BranchTrueFalseTotal
if (@digits) 70 56 126
27 70 my $digit = shift @digits;
28  
29 70 ▶ die "invalid capture name %$1 (contains zero)"
Branch: 1 branch
BranchTrueFalseTotal
unless $digit > 0 0 70 70
30 unless $digit > 0;
31 70 $curr = $curr->[$digit];
32 70 ▶ die "invalid capture name %$1 (reference to non-existent brace)\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $curr and ref $curr 0 70 70
Condition33%1/3
$curr and ref $curr
!ll&&!rl&&r
0070
MC/DC0%0/2
$curr and ref $curr
$curr ref $curr
Truth table33%1/3
A and B
A= $currB= ref $curr
ABresult
0X0
100
111
33 unless $curr && ref $curr;
34 }
35 56 return $curr->[0]
36 }
37  
38  
39 ######################################################################
40 # Public methods - see POD for documentation
41  
42 34 ▶sub text { shift->[0] }
Subroutine text: called CC=1 SCAR=0.0
Pod documented
43  
44 34 ▶sub expand {
Subroutine expand: called CC=3 SCAR=11.8
Pod documented
45 34 my ($self, $format) = @_;
46 34 ▶ croak "you must supply a format string to expand"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $format 0 34 34
47 unless defined $format;
48  
49 eval {
50 # This regex-matches each capture name and replace with the
51 # appropriate string.
52 34 $format =~
53 s{
54 %
55 (
56 % # An an escaped % character
57 |
58 (?: \d+ [.] )* # any number of decimals followed by a period
59 \d+ # a final decimal
60 )
61 }
62 {
63 90 $self->_percent_expand($1)
64 }gex;
65 34 1;
66 }
67 34 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $format =~ s/ % ( % # An an escaped % character | (?: \d+ [.] )* # any number of decimals followed by a period \d+ # a final decimal ) /$self->_percent_expand($1);/egx; 1 } } or do { chomp(my $error = $@); croak("$error when expanding '${format}' with '$self->[0]'") } 34 0 34
68 # Something went wrong, report the error
69 0 chomp(my $error = $@);
70 0 croak "$error when expanding '$format' with '$self->[0]'";
71 };
72  
73 34 return $format;
74 }
75  
76 2 1; # Magic true value required at end of module
77 __END__
↑ Summary Expand.pm »