| 1 | package Config::Maker::Path; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 9 | require Config::Maker::Path::Root; | |||||||||||||||||||||||||||||||||
| 10 | 9 | require Config::Maker::Path::AnyPath; | |||||||||||||||||||||||||||||||||
| 11 | 9 | require Config::Maker::Path::This; | |||||||||||||||||||||||||||||||||
| 12 | 9 | require Config::Maker::Path::Parent; | |||||||||||||||||||||||||||||||||
| 13 | 9 | require Config::Maker::Path::Meta; | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | use overload | ||||||||||||||||||||||||||||||||||
| 16 | 9 | ▶ | 'cmp' => \&Config::Maker::truecmp, | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | '<=>' => \&Config::Maker::truecmp, | ||||||||||||||||||||||||||||||||||
| 18 | '""' => 'str', | ||||||||||||||||||||||||||||||||||
| 19 | 9 | fallback => 1; | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 9 | our $parser = $Config::Maker::parser; | |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 9 | our %paths; # Cache for paths... | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 9 | our %checks; # For [$if$] directive... | |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | # Coversion of expressions to regexes and coderefs: | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 1976 | ▶ | sub _glob_to_re { | ||||||||||||||||||||||||||||||||
|
Subroutine
_glob_to_re: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 30 | 1976 | local $_ = $_[0]; | |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | 1976 | ▶ | /[.+^\-\$]/ ? "\\$_" : | ||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||
| 33 | /\{/ ? "(?:" : | ||||||||||||||||||||||||||||||||||
| 34 | /\}/ ? ")" : | ||||||||||||||||||||||||||||||||||
| 35 | /\*/ ? ".*" : | ||||||||||||||||||||||||||||||||||
| 36 | /\?/ ? "." : | ||||||||||||||||||||||||||||||||||
| 37 | $_; | ||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | 596 | ▶ | sub glob_to_re { | ||||||||||||||||||||||||||||||||
|
Subroutine
glob_to_re: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 41 | 596 | my ($self, $patt) = @_; | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 596 | ▶ | return qr/.*/ if (!defined $patt); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 44 | 300 | ▶ | return qr/$patt/ if ($patt =~ s/^RE://); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | 300 | ▶ | $patt =~ s/([^\\])|(\\.)/defined $1 ? _glob_to_re($1) : $2/eg; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 47 | 300 | qr/^$patt$/; | |||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 298 | ▶ | sub code_to_sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
code_to_sub: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 51 | 298 | my ($self, $code) = @_; | |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | 298 | ▶ | return sub { 1; } unless $code; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 54 | 6 | Config::Maker::DBG("Code-to-sub: qq{$code}"); | |||||||||||||||||||||||||||||||||
| 55 | 6 | $code =~ s/\A\(//; | |||||||||||||||||||||||||||||||||
| 56 | 6 | $code =~ s/\)\Z//; | |||||||||||||||||||||||||||||||||
| 57 | 6 | my $sub = Config::Maker::exe("sub { $code; };"); | |||||||||||||||||||||||||||||||||
| 58 | 6 | return $sub; | |||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | # Common argument parsing: | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 361 | ▶ | sub bhash { | ||||||||||||||||||||||||||||||||
|
Subroutine
bhash: called CC=5 SCAR=17.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 64 | 361 | my ($class, $keys) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||||
| 65 | 361 | ▶ | $keys = +{ map { $_ => 1; } @$keys } if(ref($keys) eq 'ARRAY'); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | my %hash = (ref($_[0]) eq 'HASH' ? %{$_[0]} : @_); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | 361 | for(keys %hash) { | |||||||||||||||||||||||||||||||||
| 69 | croak "Unknown argument $_" | ||||||||||||||||||||||||||||||||||
| 70 | 336 | ▶ | unless $keys->{$_}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||
| 72 | 361 | bless \%hash, $class; | |||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | # Public interface: | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 298 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 78 | 298 | my $self = shift->bhash([qw/-type -value -code -tail/], @_); | |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | 298 | $self->{-text} = ''; | |||||||||||||||||||||||||||||||||
| 81 | 298 | ▶ | $self->{-text} .= $self->{-type} if $self->{-type}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 82 | 298 | ▶ | $self->{-text} .= ':' . $self->{-value} if $self->{-value}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 83 | 298 | ▶ | $self->{-text} .= $self->{-code} if $self->{-code}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 298 | $self->{-type} = $self->glob_to_re($self->{-type}); | |||||||||||||||||||||||||||||||||
| 86 | 298 | $self->{-value} = $self->glob_to_re($self->{-value}); | |||||||||||||||||||||||||||||||||
| 87 | 298 | $self->{-code} = $self->code_to_sub($self->{-code}); | |||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | 298 | return $self; | |||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 1303 | ▶ | sub make { | ||||||||||||||||||||||||||||||||
|
Subroutine
make: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 93 | 1303 | my ($class, $text) = @_; | |||||||||||||||||||||||||||||||||
| 94 | #D# DBG "Making path from `$text'"; | ||||||||||||||||||||||||||||||||||
| 95 | 1303 | ▶ | return $text if UNIVERSAL::isa($text, __PACKAGE__); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 96 | 1183 | ▶ | return $paths{$text} if($paths{$text}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 97 | 269 | ▶ | $paths{$text} = $parser->path_whole($text) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 98 | or croak "Invalid path: $text"; | ||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 2054 | ▶ | sub match { | ||||||||||||||||||||||||||||||||
|
Subroutine
match: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 102 | 2054 | my ($self, $from) = @_; | |||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | grep { | ||||||||||||||||||||||||||||||||||
| 105 | # no warnings 'uninitialized'; # NOTEME | ||||||||||||||||||||||||||||||||||
| 106 | ($_->{-type} =~ /$self->{-type}/) | ||||||||||||||||||||||||||||||||||
| 107 | && ($_->{-value} =~ /$self->{-value}/) | ||||||||||||||||||||||||||||||||||
| 108 | 3990 | ▶ | && ($self->{-code}->()) | ||||||||||||||||||||||||||||||||
|
Condition100%6/6
$_->{'-type'} =~ /$self->{'-type'}/ && $_->{'-value'} =~ /$self->{'-value'}/ && $self->{'-code'}->()
$_->{"-type"} =~ /$self->{"-type"}/ and $_->{"-value"} =~ /$self->{"-value"}/
MC/DC100%3/3
$_->{'-type'} =~ /$self->{'-type'}/ && $_->{'-value'} =~ /$self->{'-value'}/ && $self->{'-code'}->()
$_->{"-type"} =~ /$self->{"-type"}/
$_->{"-value"} =~ /$self->{"-value"}/
$self->{'-code'}->()
Truth table100%4/4
A and B && C
A= $_->{"-type"} =~ /$self->{"-type"}/B= $_->{"-value"} =~ /$self->{"-value"}/C= $self->{'-code'}->()
| |||||||||||||||||||||||||||||||||||
| 109 | 2054 | } @{$from->{-children}} | |||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | 2197 | ▶ | sub find { | ||||||||||||||||||||||||||||||||
|
Subroutine
find: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 113 | 2197 | my ($self, $from, $gather) = @_; | |||||||||||||||||||||||||||||||||
| 114 | 2197 | ▶ | $gather ||= []; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$gather ||= []
MC/DC100%1/1
$gather ||= []
$gather
Truth table100%2/2
A
A= $gather
| |||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||
| 116 | #D# DBG "Pattern $self find in ".$from->id; | ||||||||||||||||||||||||||||||||||
| 117 | 2197 | ▶ | if($self->{-tail}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 118 | 75 | $self->{-tail}->find($_, $gather) for $self->match($from); | |||||||||||||||||||||||||||||||||
| 119 | } else { | ||||||||||||||||||||||||||||||||||
| 120 | 2122 | push @$gather, ($self->match($from)); | |||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||
| 122 | #D# DBG "Returning: `" . join("', `", map $_->id, @$gather) . "'"; | ||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||
| 124 | 2197 | return $gather; | |||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||
| 127 | 1359 | ▶ | sub text { | ||||||||||||||||||||||||||||||||
|
Subroutine
text: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 128 | 1359 | $_[0]->{-text}; | |||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | 1376 | ▶ | sub str { | ||||||||||||||||||||||||||||||||
|
Subroutine
str: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 132 | 1376 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 133 | 1376 | ▶ | $self->text . ($self->{-tail} ? '/' . $self->{-tail}->str : ''); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | 26 | ▶ | sub _findtimes { | ||||||||||||||||||||||||||||||||
|
Subroutine
_findtimes: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||
| 137 | 26 | ▶ | confess "$_[1] can't ->find" unless UNIVERSAL::can($_[1], 'find'); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 138 | 26 | my $r = $_[1]->find($_[0]); | |||||||||||||||||||||||||||||||||
| 139 | 26 | ▶ | return 0 if @$r < $_[2]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 140 | 13 | ▶ | return 1 if @_ == 3; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 141 | 9 | ▶ | return 0 if @$r > $_[3]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 142 | 4 | return 1; | |||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | 9 | ▶ | BEGIN { # Constants must be done early enough... | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||||||||
| 146 | %checks = ( | ||||||||||||||||||||||||||||||||||
| 147 | 7 | ▶ | none => sub { _findtimes($_, @_, 0,0); }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | unique => sub { _findtimes($_, @_,0,1); }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 149 | 7 | ▶ | one => sub { _findtimes($_, @_,1,1); }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 150 | 12 | ▶ | exists => sub { _findtimes($_, @_,1); }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | any => sub { 1; }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 152 | 9 | ); | |||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||
| 155 | 9 | 1; | |||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||||||||