IsDev/Object.pm

filter: Statementstmt 83.7% 62 / 74 Branchbran 57.1% 8 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.7% 18 / 19 Podpod 100% 2 / 2 totaltotal 82.5% 90 / 109 CC 6 SCAR 4.9
CC
6
Cov
80%
BUILD
3.5
_debug
2.5
_matches
2.0
CRAP 1.6
« IsDev/Role/HeuristicSet/Simple.pm ↑ Summary IsDev/NegativeHeuristic/PerlINC.pm »
1 12 ▶use 5.008; # utf8
Subroutine BEGIN: called CC=1 SCAR=0.0
2 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Path::IsDev::Object;
7  
8 12 our $VERSION = '1.001003';
9  
10 # ABSTRACT: Object Oriented guts for IsDev export
11  
12 12 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26 12 our $ENV_KEY_DEBUG = 'PATH_ISDEV_DEBUG';
27 12 ▶our $DEBUG = ( exists $ENV{$ENV_KEY_DEBUG} ? $ENV{$ENV_KEY_DEBUG} : undef );
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{$Path::IsDev::Object::ENV_KEY_DEBUG} ? : 0 12 12
28  
29 12 our $ENV_KEY_DEFAULT = 'PATH_ISDEV_DEFAULT_SET';
30 our $DEFAULT =
31 12 ▶ ( exists $ENV{$ENV_KEY_DEFAULT} ? $ENV{$ENV_KEY_DEFAULT} : 'Basic' );
Branch: 1 branch
BranchTrueFalseTotal
exists $ENV{$Path::IsDev::Object::ENV_KEY_DEFAULT} ? : 0 12 12
32  
33  
34  
35  
36  
37  
38  
39  
40  
41 12 ▶use Class::Tiny 0.010 {
Subroutine BEGIN: called CC=1 SCAR=0.0
42 10 ▶ set => sub { $DEFAULT },
Subroutine __ANON__: called CC=1 SCAR=0.0
43 11 ▶ set_prefix => sub { 'Path::IsDev::HeuristicSet' },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 11 ▶ set_module => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
45 11 require Module::Runtime;
46 11 return Module::Runtime::compose_module_name( $_[0]->set_prefix => $_[0]->set );
47 },
48 11 ▶ loaded_set_module => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
49 11 require Module::Runtime;
50 11 return Module::Runtime::use_module( $_[0]->set_module );
51 },
52 12 };
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72 12 my $instances = {};
73 12 my $instance_id = 0;
74  
75 0 ▶sub _carp { require Carp; goto &Carp::carp; }
Subroutine _carp: not called CC=1 SCAR=6.9
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88 2 ▶sub _instance_id {
Subroutine _instance_id: called CC=2 SCAR=7.0
89 2 my ($self) = @_;
90 2 require Scalar::Util;
91 2 my $addr = Scalar::Util::refaddr($self);
92 2 ▶ return $instances->{$addr} if exists $instances->{$addr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $instances->{$addr} 0 2 2
93 2 $instances->{$addr} = sprintf '%x', $instance_id++;
94 2 return $instances->{$addr};
95 }
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107 250 ▶sub _debug {
Subroutine _debug: called CC=2 SCAR=9.2
108 250 my ( $self, $message ) = @_;
109  
110 250 ▶ return unless $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless $Path::IsDev::Object::DEBUG 250 0 250
111 0 my $id = $self->_instance_id;
112 0 return *STDERR->printf( qq{[Path::IsDev=%s] %s\n}, $id, $message );
113 }
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126 16 ▶sub _with_debug {
Subroutine _with_debug: called CC=1 SCAR=0.0
127 16 my ( $self, $code ) = @_;
128 16 require Path::IsDev;
129 ## no critic (ProhibitNoWarnings)
130 12 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
131 229 ▶ local *Path::IsDev::debug = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
132 229 $self->_debug(@_);
133 16 };
134 16 return $code->();
135 }
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146 11 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=12.6
Pod documented
147 11 my ($self) = @_;
148 11 ▶ return $self unless $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless $Path::IsDev::Object::DEBUG 11 0 11
149 0 $self->_debug('{');
150 0 $self->_debug( ' set => ' . $self->set );
151 0 $self->_debug( ' set_prefix => ' . $self->set_prefix );
152 0 $self->_debug( ' set_module => ' . $self->set_module );
153 0 $self->_debug( ' loaded_set_module => ' . $self->loaded_set_module );
154 0 $self->_debug('}');
155 0 return $self;
156 }
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168 16 ▶sub _matches {
Subroutine _matches: called CC=2 SCAR=7.0
169 16 my ( $self, $path ) = @_;
170 16 require Path::IsDev::Result;
171 16 my $result_object = Path::IsDev::Result->new( path => $path );
172 16 my $result;
173 $self->_with_debug(
174 16 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
175  
176 16 $self->_debug( 'Matching ' . $result_object->path );
177 16 $result = $self->loaded_set_module->matches($result_object);
178 },
179 16 );
180 16 ▶ if ( !!$result != !!$result_object->result ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!!$result != !!$result_object->result) 0 16 16
181 0 _carp(q[Result and Result Object missmatch]);
182 }
183 16 return $result_object;
184 }
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196 15 ▶sub matches {
Subroutine matches: called CC=2 SCAR=6.9
Pod documented
197 15 my ( $self, $path ) = @_;
198  
199 15 my $result_object = $self->_matches($path);
200  
201 15 ▶ if ( not $result_object->result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result_object->result) 3 12 15
202 3 $self->_debug('no match found');
203 3 return;
204 }
205  
206 12 return $result_object->result;
207 }
208  
209 12 1;
210  
211 __END__
« IsDev/Role/HeuristicSet/Simple.pm ↑ Summary IsDev/NegativeHeuristic/PerlINC.pm »