| 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
| |||||||||||||||||||||||||||||
| 16 | 0 | return "%"; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 90 | ▶ | if ($match eq "0") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 27 | 70 | my $digit = shift @digits; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 70 | ▶ | die "invalid capture name %$1 (contains zero)" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$curr and ref $curr
MC/DC0%0/2
$curr and ref $curr
$curr
ref $curr
Truth table33%1/3
A and B
A= $currB= ref $curr
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||