blib/lib/String/Glob/Permute.pm

filter: Statementstmt 82.9% 39 / 47 Branchbran 80.0% 16 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 3 / 3 Podpod 0.0% 0 / 1 totaltotal 80.2% 61 / 76 CC 14 SCAR 26.5
CC
14
Cov
81%
string_glob_permute
16.1
BEGIN
1.0
BEGIN
1.0
CRAP 14.2
↑ Summary
1 # Copyright (c) 2008 Yahoo! Inc. All rights reserved. The copyrights to
2 # the contents of this file are licensed under the Perl Artistic License
3 # (ver. 15 Aug 1997).
4 ###########################################
5 package String::Glob::Permute;
6 ###########################################
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 require Exporter;
11 1 our @ISA = qw(Exporter);
12 1 our @EXPORT_OK = qw(string_glob_permute);
13 1 our $VERSION = "0.01";
14  
15 ###########################################
16 4 ▶sub string_glob_permute {
Subroutine string_glob_permute: called CC=14 SCAR=27.8
Pod undocumented
17 ###########################################
18 4 my( $string_glob ) = @_;
19  
20 4 my @stringlist;
21 4 my @patterns = ($string_glob);
22  
23 4 ▶ while (@patterns) {
Branch: 1 branch
BranchTrueFalseTotal
if (@patterns) 24 4 28
24  
25 24 my $h = shift(@patterns);
26  
27 24 ▶ if ($h =~ /^(.*?)\[([^\]]+)\]([^,{[]*)(,(.*))?$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($h =~ /^(.*?)\[([^\]]+)\]([^,{[]*)(,(.*))?$/) { } 4 20 24
elsif ($h =~ /^(.*?)\{([^\}]+)\}([^,[{]*)(,(.*))?$/) { } 3 17 20
28 4 my($pre,$post) = ($1,$3);
29  
30 4 my @r = split(/,/,$2);
31  
32 4 for (@r) {
33  
34 8 ▶ if (/^(!?)(\d+)(-(\d+))?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(!?)(\d+)(-(\d+))?$/) { } 8 0 8
35 8 my $lo = $2;
36 8 ▶ my $hi = $3 ? $4 : $lo;
Branch: 1 branch
BranchTrueFalseTotal
$3 ? : 4 4 8
37 8 my $fmt = "%d";
38  
39 # Expand [09-11] to ("09", "10", "11") instead of
40 # ("9", "10", "11").
41 8 ▶ if (length($lo) == length($hi) && length($lo) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $lo == length $hi and length $lo > 1) 4 4 8
Condition66%2/3
length $lo == length $hi and length $lo > 1
!ll&&!rl&&r
044
MC/DC50%1/2
length $lo == length $hi and length $lo > 1
length $lo == length $hi length $lo > 1
Truth table66%2/3
A and B
A= length $lo == length $hiB= length $lo > 1
ABresult
0X0
100
111
42 4 $fmt = "%0" . length($lo) . "d";
43 }
44  
45 8 ▶ for (my $n = $lo; $n <= $hi; $n++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n <= $hi) 14 8 22
46 14 my $hn = $pre . sprintf($fmt, $n) . $post;
47  
48 14 ▶ if ($1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1) { } 0 14 14
49 0 @stringlist = grep { $_ ne $hn } @stringlist;
50 0 @patterns = grep { $_ ne $hn } @patterns;
51 } else {
52 14 push(@patterns,$hn);
53 }
54 }
55 } else {
56 0 warn("Unrecognized host pattern: $h");
57 0 return undef;
58 }
59 }
60  
61 4 ▶ if ($4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($4) 0 4 4
62 0 push(@patterns,$5);
63 }
64  
65 } elsif ($h =~ /^(.*?)\{([^\}]+)\}([^,[{]*)(,(.*))?$/) {
66  
67 3 my($pre,$post) = ($1,$3);
68 3 my @r = split(/,/,$2);
69  
70 3 for (@r) {
71 6 push(@patterns,$pre.$_.$post);
72 }
73  
74 3 ▶ if ($4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($4) 0 3 3
75 0 push(@patterns,$5);
76 }
77 } else {
78 17 my @h = split(/,/,$h);
79 17 push(@stringlist,@h);
80 }
81 }
82 4 return @stringlist;
83 }
84  
85 1 1;
86  
87 __END__
↑ Summary