| 1 | package File::GlobMapper; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 130 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 130 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 130 | ▶ | use Carp; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 130 | ▶ | use File::Glob ':glob'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | 130 | our ($Error); | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 130 | our ($VERSION, @EXPORT_OK); | |||||||||||||||||||||||||||||
| 11 | 130 | $VERSION = '1.002'; | |||||||||||||||||||||||||||||
| 12 | 130 | @EXPORT_OK = qw( globmap ); | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | 130 | our $BEGIN_DELIM = "\xFF"; | |||||||||||||||||||||||||||||
| 15 | 130 | our $END_DELIM = "\xFE"; | |||||||||||||||||||||||||||||
| 16 | 130 | our $BACKSLASH_ESC = "\xFD"; | |||||||||||||||||||||||||||||
| 17 | 130 | our $HASH_ESC = "\xFC"; | |||||||||||||||||||||||||||||
| 18 | 130 | our $STAR_ESC = "\xFB"; | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | 130 | our ($noPreBS, $metachars, $matchMetaRE, %mapping, %wildCount); | |||||||||||||||||||||||||||||
| 21 | 130 | $noPreBS = '(?<!\\\)' ; # no preceding backslash | |||||||||||||||||||||||||||||
| 22 | 130 | $metachars = '.*?[](){}'; | |||||||||||||||||||||||||||||
| 23 | 130 | $matchMetaRE = '[' . quotemeta($metachars) . ']'; | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | 130 | %mapping = ( | |||||||||||||||||||||||||||||
| 26 | '*' => '([^/]*)', | ||||||||||||||||||||||||||||||
| 27 | '?' => '([^/])', | ||||||||||||||||||||||||||||||
| 28 | '.' => '\.', | ||||||||||||||||||||||||||||||
| 29 | '[' => '([', | ||||||||||||||||||||||||||||||
| 30 | '(' => '(', | ||||||||||||||||||||||||||||||
| 31 | ')' => ')', | ||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||
| 34 | 130 | %wildCount = map { $_ => 1 } qw/ * ? . { ( [ /; | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | sub globmap ($$;) | ||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
globmap: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 38 | 4 | my $inputGlob = shift ; | |||||||||||||||||||||||||||||
| 39 | 4 | my $outputGlob = shift ; | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | my $obj = File::GlobMapper->new($inputGlob, $outputGlob, @_) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 42 | or croak "globmap: $Error" ; | ||||||||||||||||||||||||||||||
| 43 | 4 | return $obj->getFileMap(); | |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||
| 46 | sub new | ||||||||||||||||||||||||||||||
| 47 | 59 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 48 | 59 | my $class = shift ; | |||||||||||||||||||||||||||||
| 49 | 59 | my $inputGlob = shift ; | |||||||||||||||||||||||||||||
| 50 | 59 | my $outputGlob = shift ; | |||||||||||||||||||||||||||||
| 51 | # TODO -- flags needs to default to whatever File::Glob does | ||||||||||||||||||||||||||||||
| 52 | 59 | ▶ | my $flags = shift || GLOB_CSH; | ||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 11904
MC/DC0%0/1
shift() || 11904
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||
| 53 | #my $flags = shift ; | ||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||
| 55 | 59 | $inputGlob =~ s/^\s*\<\s*//; | |||||||||||||||||||||||||||||
| 56 | 59 | $inputGlob =~ s/\s*\>\s*$//; | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | 59 | $outputGlob =~ s/^\s*\<\s*//; | |||||||||||||||||||||||||||||
| 59 | 59 | $outputGlob =~ s/\s*\>\s*$//; | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||
| 61 | 59 | my %object = | |||||||||||||||||||||||||||||
| 62 | ( InputGlob => $inputGlob, | ||||||||||||||||||||||||||||||
| 63 | OutputGlob => $outputGlob, | ||||||||||||||||||||||||||||||
| 64 | GlobFlags => $flags, | ||||||||||||||||||||||||||||||
| 65 | Braces => 0, | ||||||||||||||||||||||||||||||
| 66 | WildCount => 0, | ||||||||||||||||||||||||||||||
| 67 | Pairs => [], | ||||||||||||||||||||||||||||||
| 68 | Sigil => '#', | ||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||
| 71 | 59 | ▶ | my $self = bless \%object, ref($class) || $class ; | ||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | 59 | ▶ | $self->_parseInputGlob() | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 74 | or return undef ; | ||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | 34 | ▶ | $self->_parseOutputGlob() | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 77 | or return undef ; | ||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||
| 79 | 34 | my @inputFiles = File::Glob::csh_glob($self->{InputGlob}, $flags) ; | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||
| 81 | 34 | ▶ | if (GLOB_ERROR) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||||
| 83 | 0 | $Error = $!; | |||||||||||||||||||||||||||||
| 84 | 0 | return undef ; | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | #if (whatever) | ||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||
| 89 | 34 | my $missing = grep { ! -e $_ } @inputFiles ; | |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | 34 | ▶ | if ($missing) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||||
| 93 | 0 | $Error = "$missing input files do not exist"; | |||||||||||||||||||||||||||||
| 94 | 0 | return undef ; | |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | 34 | $self->{InputFiles} = \@inputFiles ; | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | 34 | ▶ | $self->_getFiles() | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 101 | or return undef ; | ||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||
| 103 | 33 | return $self; | |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||
| 106 | sub _retError | ||||||||||||||||||||||||||||||
| 107 | 25 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
_retError: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 108 | 25 | my $string = shift ; | |||||||||||||||||||||||||||||
| 109 | 25 | $Error = "$string in input fileglob" ; | |||||||||||||||||||||||||||||
| 110 | 25 | return undef ; | |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||
| 113 | sub _unmatched | ||||||||||||||||||||||||||||||
| 114 | 25 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
_unmatched: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 115 | 25 | my $delimeter = shift ; | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||
| 117 | 25 | _retError("Unmatched $delimeter"); | |||||||||||||||||||||||||||||
| 118 | 25 | return undef ; | |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||
| 121 | sub _parseBit | ||||||||||||||||||||||||||||||
| 122 | 7 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
_parseBit: called CC=15 SCAR=27.9
| |||||||||||||||||||||||||||||||
| 123 | 7 | my $self = shift ; | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||
| 125 | 7 | my $string = shift ; | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||
| 127 | 7 | my $out = ''; | |||||||||||||||||||||||||||||
| 128 | 7 | my $depth = 0 ; | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | 7 | ▶ | while ($string =~ s/(.*?)$noPreBS(,|$matchMetaRE)//) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 131 | { | ||||||||||||||||||||||||||||||
| 132 | 9 | $out .= quotemeta($1) ; | |||||||||||||||||||||||||||||
| 133 | 9 | ▶ | $out .= $mapping{$2} if defined $mapping{$2}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||
| 135 | 9 | ▶ | ++ $self->{WildCount} if $wildCount{$2} ; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||
| 137 | 9 | ▶ | if ($2 eq ',') | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||||
| 139 | 3 | ▶ | return _unmatched("(") | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 140 | if $depth ; | ||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||
| 142 | 3 | $out .= '|'; | |||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||
| 144 | elsif ($2 eq '(') | ||||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||||
| 146 | 1 | ++ $depth ; | |||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||
| 148 | elsif ($2 eq ')') | ||||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | return _unmatched(")") | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 151 | if ! $depth ; | ||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||
| 153 | 0 | -- $depth ; | |||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||
| 155 | elsif ($2 eq '[') | ||||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||||
| 157 | # TODO -- quotemeta & check no '/' | ||||||||||||||||||||||||||||||
| 158 | # TODO -- check for \] & other \ within the [] | ||||||||||||||||||||||||||||||
| 159 | 1 | ▶ | $string =~ s#(.*?\])## | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 160 | or return _unmatched("["); | ||||||||||||||||||||||||||||||
| 161 | 0 | $out .= "$1)" ; | |||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||
| 163 | elsif ($2 eq ']') | ||||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||||
| 165 | 1 | return _unmatched("]"); | |||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||
| 167 | ▶ | elsif ($2 eq '{' || $2 eq '}') | |||||||||||||||||||||||||||||
|
Condition33%1/3
$2 eq "{" or $2 eq "}"
MC/DC0%0/2
$2 eq "{" or $2 eq "}"
$2 eq "{"
$2 eq "}"
Truth table33%1/3
A or B
A= $2 eq "{"B= $2 eq "}"
| |||||||||||||||||||||||||||||||
| 168 | { | ||||||||||||||||||||||||||||||
| 169 | 0 | return _retError("Nested {} not allowed"); | |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||
| 173 | 4 | $out .= quotemeta $string; | |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||
| 175 | 4 | ▶ | return _unmatched("(") | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 176 | if $depth ; | ||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||
| 178 | 3 | return $out ; | |||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | sub _parseInputGlob | ||||||||||||||||||||||||||||||
| 182 | 59 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
_parseInputGlob: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||
| 183 | 59 | my $self = shift ; | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||
| 185 | 59 | my $string = $self->{InputGlob} ; | |||||||||||||||||||||||||||||
| 186 | 59 | my $inGlob = ''; | |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||
| 188 | # Multiple concatenated *'s don't make sense | ||||||||||||||||||||||||||||||
| 189 | #$string =~ s#\*\*+#*# ; | ||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||
| 191 | # TODO -- Allow space to delimit patterns? | ||||||||||||||||||||||||||||||
| 192 | #my @strings = split /\s+/, $string ; | ||||||||||||||||||||||||||||||
| 193 | #for my $str (@strings) | ||||||||||||||||||||||||||||||
| 194 | 59 | my $out = ''; | |||||||||||||||||||||||||||||
| 195 | 59 | my $depth = 0 ; | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||
| 197 | 59 | ▶ | while ($string =~ s/(.*?)$noPreBS($matchMetaRE)//) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 198 | { | ||||||||||||||||||||||||||||||
| 199 | 135 | $out .= quotemeta($1) ; | |||||||||||||||||||||||||||||
| 200 | 135 | ▶ | $out .= $mapping{$2} if defined $mapping{$2}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 201 | 135 | ▶ | ++ $self->{WildCount} if $wildCount{$2} ; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||
| 203 | 135 | ▶ | if ($2 eq '(') | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 204 | { | ||||||||||||||||||||||||||||||
| 205 | 3 | ++ $depth ; | |||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||
| 207 | elsif ($2 eq ')') | ||||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||||
| 209 | 18 | ▶ | return _unmatched(")") | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 210 | if ! $depth ; | ||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||
| 212 | 2 | -- $depth ; | |||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||
| 214 | elsif ($2 eq '[') | ||||||||||||||||||||||||||||||
| 215 | { | ||||||||||||||||||||||||||||||
| 216 | # TODO -- quotemeta & check no '/' or '(' or ')' | ||||||||||||||||||||||||||||||
| 217 | # TODO -- check for \] & other \ within the [] | ||||||||||||||||||||||||||||||
| 218 | 2 | ▶ | $string =~ s#(.*?\])## | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 219 | or return _unmatched("["); | ||||||||||||||||||||||||||||||
| 220 | 1 | $out .= "$1)" ; | |||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||
| 222 | elsif ($2 eq ']') | ||||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||||
| 224 | 1 | return _unmatched("]"); | |||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||
| 226 | elsif ($2 eq '}') | ||||||||||||||||||||||||||||||
| 227 | { | ||||||||||||||||||||||||||||||
| 228 | 1 | return _unmatched("}"); | |||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||
| 230 | elsif ($2 eq '{') | ||||||||||||||||||||||||||||||
| 231 | { | ||||||||||||||||||||||||||||||
| 232 | # TODO -- check no '/' within the {} | ||||||||||||||||||||||||||||||
| 233 | # TODO -- check for \} & other \ within the {} | ||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||
| 235 | 8 | my $tmp ; | |||||||||||||||||||||||||||||
| 236 | 8 | ▶ | unless ( $string =~ s/(.*?)$noPreBS\}//) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 237 | { | ||||||||||||||||||||||||||||||
| 238 | 1 | return _unmatched("{"); | |||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||
| 240 | #$string =~ s#(.*?)\}##; | ||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||
| 242 | #my $alt = join '|', | ||||||||||||||||||||||||||||||
| 243 | # map { quotemeta $_ } | ||||||||||||||||||||||||||||||
| 244 | # split "$noPreBS,", $1 ; | ||||||||||||||||||||||||||||||
| 245 | 7 | my $alt = $self->_parseBit($1); | |||||||||||||||||||||||||||||
| 246 | 7 | ▶ | defined $alt or return 0 ; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 247 | 3 | $out .= "($alt)" ; | |||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||
| 249 | 3 | ++ $self->{Braces} ; | |||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||
| 253 | 35 | ▶ | return _unmatched("(") | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 254 | if $depth ; | ||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||
| 256 | 34 | $out .= quotemeta $string ; | |||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||
| 259 | 34 | $self->{InputGlob} =~ s/$noPreBS[\(\)]//g; | |||||||||||||||||||||||||||||
| 260 | 34 | $self->{InputPattern} = $out ; | |||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||
| 262 | #print "# INPUT '$self->{InputGlob}' => '$out'\n"; | ||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||
| 264 | 34 | return 1 ; | |||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||
| 268 | sub _parseOutputGlob | ||||||||||||||||||||||||||||||
| 269 | 34 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
_parseOutputGlob: called CC=6 SCAR=19.5
| |||||||||||||||||||||||||||||||
| 270 | 34 | my $self = shift ; | |||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||
| 272 | 34 | my $string = $self->{OutputGlob} ; | |||||||||||||||||||||||||||||
| 273 | 34 | my $maxwild = $self->{WildCount}; | |||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||
| 275 | 34 | ▶ | if ($self->{GlobFlags} & GLOB_TILDE) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 276 | #if (1) | ||||||||||||||||||||||||||||||
| 277 | { | ||||||||||||||||||||||||||||||
| 278 | 34 | $string =~ s{ | |||||||||||||||||||||||||||||
| 279 | ^ ~ # find a leading tilde | ||||||||||||||||||||||||||||||
| 280 | ( # save this in $1 | ||||||||||||||||||||||||||||||
| 281 | [^/] # a non-slash character | ||||||||||||||||||||||||||||||
| 282 | * # repeated 0 or more times (0 means me) | ||||||||||||||||||||||||||||||
| 283 | ) | ||||||||||||||||||||||||||||||
| 284 | }{ | ||||||||||||||||||||||||||||||
| 285 | $1 | ||||||||||||||||||||||||||||||
| 286 | ? (getpwnam($1))[7] | ||||||||||||||||||||||||||||||
| 287 | : ( $ENV{HOME} || $ENV{LOGDIR} ) | ||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | }ex; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ENV{"HOME"} or $ENV{"LOGDIR"}
MC/DC0%0/2
$ENV{"HOME"} or $ENV{"LOGDIR"}
$ENV{"HOME"}
$ENV{"LOGDIR"}
Truth table0%0/3
A or B
A= $ENV{"HOME"}B= $ENV{"LOGDIR"}
| |||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||
| 292 | # max #1 must be == to max no of '*' in input | ||||||||||||||||||||||||||||||
| 293 | 34 | ▶ | while ( $string =~ m/#(\d)/g ) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 294 | { | ||||||||||||||||||||||||||||||
| 295 | 35 | ▶ | croak "Max wild is #$maxwild, you tried #$1" | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 296 | if $1 > $maxwild ; | ||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||
| 299 | 34 | my $noPreBS = '(?<!\\\)' ; # no preceding backslash | |||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||
| 301 | # escape any use of the delimiter symbols | ||||||||||||||||||||||||||||||
| 302 | # $string =~ s/(${BEGIN_DELIM}|${END_DELIM}|${BACKSLASH_ESC})/$1$1/g; | ||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||
| 304 | # escape \# and \* | ||||||||||||||||||||||||||||||
| 305 | 34 | $string =~ s/\\#/${HASH_ESC}/g; | |||||||||||||||||||||||||||||
| 306 | 34 | $string =~ s/\\\*/${STAR_ESC}/g; | |||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||
| 308 | # Transform "#3" to BEGIN_DELIM 3 END_DELIM | ||||||||||||||||||||||||||||||
| 309 | 34 | $string =~ s/#(\d)/${BEGIN_DELIM}${1}${END_DELIM}/g; | |||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||
| 311 | 34 | $string =~ s#\*#${BEGIN_DELIM}${END_DELIM}#g; | |||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||
| 313 | # print "INPUT '$self->{InputPattern}'\n"; | ||||||||||||||||||||||||||||||
| 314 | # print "OUTPUT '$self->{OutputGlob}' => '$string'\n"; | ||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||
| 316 | 34 | $self->{OutputPattern} = $string ; | |||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||
| 318 | 34 | return 1 ; | |||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||
| 321 | sub _getFiles | ||||||||||||||||||||||||||||||
| 322 | 34 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
_getFiles: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 323 | 34 | my $self = shift ; | |||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||
| 325 | 34 | my %outInMapping = (); | |||||||||||||||||||||||||||||
| 326 | 34 | my %inFiles = () ; | |||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||
| 328 | 34 | foreach my $inFile (@{ $self->{InputFiles} }) | |||||||||||||||||||||||||||||
| 329 | { | ||||||||||||||||||||||||||||||
| 330 | 81 | ▶ | next if $inFiles{$inFile} ++ ; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||
| 332 | 80 | my $outFile = $inFile ; | |||||||||||||||||||||||||||||
| 333 | 80 | my @matches ; | |||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||
| 335 | 80 | ▶ | if (@matches = ($inFile =~ m/$self->{InputPattern}/ )) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||||
| 337 | 80 | $outFile = $self->{OutputPattern}; | |||||||||||||||||||||||||||||
| 338 | 80 | my $ix = 1; | |||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||
| 340 | # get the filename glob | ||||||||||||||||||||||||||||||
| 341 | 80 | $outFile =~ s/${BEGIN_DELIM}${END_DELIM}/$inFile/g; | |||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||
| 343 | # now each of the #1, #2,... | ||||||||||||||||||||||||||||||
| 344 | 80 | for my $pattern (@matches) | |||||||||||||||||||||||||||||
| 345 | { | ||||||||||||||||||||||||||||||
| 346 | 109 | $outFile =~ s/${BEGIN_DELIM}${ix}${END_DELIM}/$pattern/g; | |||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||
| 348 | 109 | ++ $ix; | |||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||
| 351 | # unescape | ||||||||||||||||||||||||||||||
| 352 | 80 | $outFile =~ s/${BEGIN_DELIM}${BEGIN_DELIM}/${BEGIN_DELIM}/g; | |||||||||||||||||||||||||||||
| 353 | 80 | $outFile =~ s/${END_DELIM}${END_DELIM}/${END_DELIM}/g; | |||||||||||||||||||||||||||||
| 354 | 80 | $outFile =~ s/${HASH_ESC}/#/g; | |||||||||||||||||||||||||||||
| 355 | 80 | $outFile =~ s/${STAR_ESC}/*/g; | |||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||
| 357 | 80 | ▶ | if (defined $outInMapping{$outFile}) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 358 | { | ||||||||||||||||||||||||||||||
| 359 | 1 | $Error = "multiple input files map to one output file"; | |||||||||||||||||||||||||||||
| 360 | 1 | return undef ; | |||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||
| 362 | 79 | $outInMapping{$outFile} = $inFile; | |||||||||||||||||||||||||||||
| 363 | 79 | push @{ $self->{Pairs} }, [$inFile, $outFile]; | |||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||
| 367 | 33 | return 1 ; | |||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||
| 370 | sub getFileMap | ||||||||||||||||||||||||||||||
| 371 | 33 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
getFileMap: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 372 | 33 | my $self = shift ; | |||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||
| 374 | 33 | return $self->{Pairs} ; | |||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||
| 377 | sub getHash | ||||||||||||||||||||||||||||||
| 378 | 4 | ▶ | { | ||||||||||||||||||||||||||||
|
Subroutine
getHash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 379 | 4 | my $self = shift ; | |||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||
| 381 | 4 | return { map { $_->[0] => $_->[1] } @{ $self->{Pairs} } } ; | |||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||
| 384 | 130 | 1; | |||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||
| 386 | __END__ | ||||||||||||||||||||||||||||||