Maker/Path.pm

filter: Statementstmt 96.5% 83 / 86 Branchbran 85.4% 41 / 48 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 4 / 4 Subroutinesub 91.3% 21 / 23 Podpod 0.0% 0 / 9 totaltotal 88.2% 157 / 178 CC 30 SCAR 12.7
CC
30
Cov
93%
_glob_to_re
6.0
bhash
5.6
_findtimes
5.0
CRAP 3.6
« Maker/Tee.pm ↑ Summary Maker/Eval.pm »
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
BranchTrueFalseTotal
/[.+^\-\$]/ ? : 27 1949 1976
/\{/ ? : 1 1948 1949
/\}/ ? : 1 1947 1948
/\*/ ? : 18 1929 1947
/\?/ ? : 1 1928 1929
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
BranchTrueFalseTotal
unless defined $patt 296 300 596
44 300 ▶ return qr/$patt/ if ($patt =~ s/^RE://);
Branch: 1 branch
BranchTrueFalseTotal
if $patt =~ s/^RE:// 0 300 300
45  
46 300 ▶ $patt =~ s/([^\\])|(\\.)/defined $1 ? _glob_to_re($1) : $2/eg;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 1976 0 1976
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
BranchTrueFalseTotal
unless $code 292 6 298
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
BranchTrueFalseTotal
if ref $keys eq "ARRAY" 361 0 361
66 0 ▶ my %hash = (ref($_[0]) eq 'HASH' ? %{$_[0]} : @_);
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 361 361
67  
68 361 for(keys %hash) {
69 croak "Unknown argument $_"
70 336 ▶ unless $keys->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $keys->{$_} 0 336 336
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
BranchTrueFalseTotal
if $self->{"-type"} 294 4 298
82 298 ▶ $self->{-text} .= ':' . $self->{-value} if $self->{-value};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"-value"} 6 292 298
83 298 ▶ $self->{-text} .= $self->{-code} if $self->{-code};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"-code"} 6 292 298
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
BranchTrueFalseTotal
if UNIVERSAL::isa($text, __PACKAGE__) 120 1183 1303
96 1183 ▶ return $paths{$text} if($paths{$text});
Branch: 1 branch
BranchTrueFalseTotal
if $Config::Maker::Path::paths{$text} 914 269 1183
97 269 ▶ $paths{$text} = $parser->path_whole($text)
Branch: 1 branch
BranchTrueFalseTotal
$Config::Maker::Path::paths{$text} = $Config::Maker::Path::parser->path_whole($text) or croak("Invalid path: $text") 269 0 269
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'}->()
!ll&&!rl&&r
29847999
$_->{"-type"} =~ /$self->{"-type"}/ and $_->{"-value"} =~ /$self->{"-value"}/
!ll&&!rl&&r
2964201006
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'}->()
ABCresult
0XX0
10X0
1100
1111
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 ||= []
l!l
2021995
MC/DC100%1/1
$gather ||= []
$gather
Truth table100%2/2
A
A= $gather
Aresult
11
00
115  
116 #D# DBG "Pattern $self find in ".$from->id;
117 2197 ▶ if($self->{-tail}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'-tail'}) { } 75 2122 2197
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
BranchTrueFalseTotal
$self->{'-tail'} ? : 60 1316 1376
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
BranchTrueFalseTotal
unless UNIVERSAL::can($_[1], "find") 0 26 26
138 26 my $r = $_[1]->find($_[0]);
139 26 ▶ return 0 if @$r < $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if @$r < $_[2] 13 13 26
140 13 ▶ return 1 if @_ == 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 3 4 9 13
141 9 ▶ return 0 if @$r > $_[3];
Branch: 1 branch
BranchTrueFalseTotal
if @$r > $_[3] 5 4 9
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__
« Maker/Tee.pm ↑ Summary Maker/Eval.pm »