FindDev/Object.pm

filter: Statementstmt 63.1% 53 / 84 Branchbran 46.4% 13 / 28 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 12 / 14 Podpod 100% 4 / 4 totaltotal 61.4% 83 / 135 CC 15 SCAR 16.8
CC
15
Cov
58%
BUILD
12.2
_step
9.2
_instance_id
6.0
CRAP 5.4
↑ Summary FindDev.pm »
1 2 ▶use 5.006; # our
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Path::FindDev::Object;
6  
7 2 our $VERSION = 'v0.5.3';
8  
9 # ABSTRACT: Object oriented guts to FindDev
10  
11 2 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 2 our $ENV_KEY_DEBUG = 'PATH_FINDDEV_DEBUG';
14 2 ▶our $DEBUG = ( exists $ENV{$ENV_KEY_DEBUG} ? $ENV{$ENV_KEY_DEBUG} : undef );
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{$Path::FindDev::Object::ENV_KEY_DEBUG} ? : 0 2 2
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28 2 ▶use Class::Tiny 0.010 'set', 'uplevel_max', {
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶ nest_retry => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
30 1 return 0;
31 },
32 1 ▶ isdev => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
33 1 require Path::IsDev::Object;
34 1 ▶ return Path::IsDev::Object->new( ( $_[0]->has_set ? ( set => $_[0]->set ) : () ) );
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->has_set ? : 0 1 1
35 },
36 2 };
37  
38  
39  
40  
41  
42  
43  
44  
45  
46 ## no critic (RequireArgUnpacking)
47  
48  
49  
50  
51  
52  
53  
54 1 ▶sub has_set { return exists $_[0]->{set} }
Subroutine has_set: called CC=1 SCAR=0.0
Pod documented
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70 1 ▶sub has_uplevel_max { return exists $_[0]->{uplevel_max} }
Subroutine has_uplevel_max: called CC=1 SCAR=0.0
Pod documented
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89 2 my $instances = {};
90 2 my $instance_id = 0;
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105 0 ▶sub _instance_id {
Subroutine _instance_id: not called CC=2 SCAR=17.9
106 0 my ($self) = @_;
107 0 require Scalar::Util;
108 0 my $addr = Scalar::Util::refaddr($self);
109 0 ▶ return $instances->{$addr} if exists $instances->{$addr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $instances->{$addr} 0 0 0
110 0 $instances->{$addr} = sprintf '%x', $instance_id++;
111 0 return $instances->{$addr};
112 }
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123 1 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=25.0
Pod documented
124 1 my ($self) = @_;
125 1 ▶ return $self unless $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless $Path::FindDev::Object::DEBUG 1 0 1
126 0 $self->_debug('{');
127 0 ▶ $self->_debug( ' set => ' . $self->set ) if $self->has_set;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_set 0 0 0
128 0 ▶ $self->_debug( ' uplevel_max => ' . $self->uplevel_max ) if $self->uplevel_max;
Branch: 1 branch
BranchTrueFalseTotal
if $self->uplevel_max 0 0 0
129 0 $self->_debug( ' nest_retry => ' . $self->nest_retry );
130 0 $self->_debug( ' isdev => ' . $self->isdev );
131 0 $self->_debug('}');
132 0 return $self;
133 }
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147 3 ▶sub _debug {
Subroutine _debug: called CC=2 SCAR=9.2
148 3 my ( $self, $message ) = @_;
149 3 ▶ return unless $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless $Path::FindDev::Object::DEBUG 3 0 3
150 0 my $id = $self->_instance_id;
151 0 return *STDERR->printf( qq{[Path::FindDev=%s] %s\n}, $id, $message );
152 }
153  
154  
155  
156  
157  
158  
159  
160  
161  
162 0 ▶sub _error {
Subroutine _error: not called CC=1 SCAR=6.9
163 0 my ( $self, $message ) = @_;
164 0 my $id = $self->_instance_id;
165 0 my $f_message = sprintf qq{[Path::FindDev=%s] %s\n}, $id, $message;
166 0 require Carp;
167 0 Carp::croak($f_message);
168 }
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185 2 ▶sub _step {
Subroutine _step: called CC=6 SCAR=22.2
186 2 my ( $self, $search_root, $dev_levels, $uplevels ) = @_;
187  
188 2 ▶ if ( $self->isdev->matches($search_root) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isdev->matches($search_root)) 1 1 2
189 1 $self->_debug( 'Found dev dir' . $search_root );
190 1 ${$dev_levels}++;
191 1 ▶ return { type => 'found', path => $search_root } if ${$dev_levels} >= $self->nest_retry;
Branch: 1 branch
BranchTrueFalseTotal
if ${$dev_levels;} >= $self->nest_retry 1 0 1
192 0 $self->_debug( sprintf 'Ignoring found dev dir due to dev_levels(%s) < nest_retry(%s)', ${$dev_levels}, $self->nest_retry );
193 }
194 1 ▶ if ( $search_root->is_rootdir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($search_root->is_rootdir) 0 1 1
195 0 $self->_debug('OS Root hit ( ->is_rootdir )');
196 0 return { type => 'stop' };
197 }
198 0 ▶ if ( $self->has_uplevel_max and ${$uplevels} > $self->uplevel_max ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_uplevel_max and ${$uplevels;} > $self->uplevel_max) 0 1 1
Condition33%1/3
$self->has_uplevel_max and ${$uplevels;} > $self->uplevel_max
!ll&&!rl&&r
100
MC/DC0%0/2
$self->has_uplevel_max and ${$uplevels;} > $self->uplevel_max
$self->has_uplevel_max ${$uplevels;} > $self->uplevel_max
Truth table33%1/3
A and B
A= $self->has_uplevel_maxB= ${$uplevels;} > $self->uplevel_max
ABresult
0X0
100
111
199 0 $self->_debug( 'Stopping search due to uplevels(%s) >= uplevel_max(%s)', ${$uplevels}, $self->uplevel_max );
200 0 return { type => 'stop' };
201 }
202  
203 1 return { type => 'next' };
204 }
205  
206  
207  
208  
209  
210  
211  
212  
213  
214 1 ▶sub find_dev {
Subroutine find_dev: called CC=4 SCAR=14.2
Pod documented
215 1 my ( $self, $path ) = @_;
216 1 require Path::Tiny;
217 1 my $search_root = Path::Tiny::path($path)->absolute->realpath;
218 1 $self->_debug( 'Finding dev for ' . $path );
219 1 my $dev_levels = 0;
220 1 my $uplevels = 0 - 1;
221 FLOW: {
222 1 $uplevels++;
223 2 my $result = $self->_step( $search_root, \$dev_levels, \$uplevels );
224 2 ▶ if ( 'next' eq $result->{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("next" eq $result->{"type"}) 1 1 2
225 1 $self->_debug( 'Trying ../ : ' . $search_root->parent );
226 1 $search_root = $search_root->parent;
227 1 redo FLOW;
228 }
229 1 ▶ if ( 'stop' eq $result->{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("stop" eq $result->{"type"}) 0 1 1
230 0 return;
231 }
232 1 ▶ if ( 'found' eq $result->{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("found" eq $result->{"type"}) 1 0 1
233 1 return $result->{path};
234 }
235 0 $self->_error( 'Unexpected end of flow control with _step response type' . $result->{type} );
236 }
237 0 return;
238 }
239 2 1;
240  
241 __END__
↑ Summary FindDev.pm »