| 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
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 24 | my $h = shift(@patterns); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 24 | ▶ | if ($h =~ /^(.*?)\[([^\]]+)\]([^,{[]*)(,(.*))?$/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 35 | 8 | my $lo = $2; | |||||||||||||||||||||||||||
| 36 | 8 | ▶ | my $hi = $3 ? $4 : $lo; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
length $lo == length $hi and length $lo > 1
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
| |||||||||||||||||||||||||||||
| 42 | 4 | $fmt = "%0" . length($lo) . "d"; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 8 | ▶ | for (my $n = $lo; $n <= $hi; $n++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 14 | my $hn = $pre . sprintf($fmt, $n) . $post; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 14 | ▶ | if ($1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||