File Coverage

blib/lib/Path/IsDev/Object.pm
Criterion Covered Total %
statement 53 65 81.5
branch 6 10 60.0
condition n/a
subroutine 14 15 93.3
pod 2 2 100.0
total 75 92 81.5


line stmt bran cond sub pod time code
1 12     12   2497 use 5.008; # utf8
  12         28  
2 12     12   40 use strict;
  12         19  
  12         212  
3 12     12   39 use warnings;
  12         13  
  12         264  
4 12     12   1510 use utf8;
  12         38  
  12         56  
5              
6             package Path::IsDev::Object;
7              
8             our $VERSION = '1.001003';
9              
10             # ABSTRACT: Object Oriented guts for IsDev export
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14              
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26             our $ENV_KEY_DEBUG = 'PATH_ISDEV_DEBUG';
27             our $DEBUG = ( exists $ENV{$ENV_KEY_DEBUG} ? $ENV{$ENV_KEY_DEBUG} : undef );
28              
29             our $ENV_KEY_DEFAULT = 'PATH_ISDEV_DEFAULT_SET';
30             our $DEFAULT =
31             ( exists $ENV{$ENV_KEY_DEFAULT} ? $ENV{$ENV_KEY_DEFAULT} : 'Basic' );
32              
33              
34              
35              
36              
37              
38              
39              
40              
41             use Class::Tiny 0.010 {
42 10         789 set => sub { $DEFAULT },
43 11         1578 set_prefix => sub { 'Path::IsDev::HeuristicSet' },
44             set_module => sub {
45 11         2435 require Module::Runtime;
46 11         2808 return Module::Runtime::compose_module_name( $_[0]->set_prefix => $_[0]->set );
47             },
48             loaded_set_module => sub {
49 11         3727 require Module::Runtime;
50 11         11182 return Module::Runtime::use_module( $_[0]->set_module );
51             },
52 12     12   7251 };
  12         26261  
  12         110  
53              
54              
55              
56              
57              
58              
59              
60              
61              
62              
63              
64              
65              
66              
67              
68              
69              
70              
71              
72             my $instances = {};
73             my $instance_id = 0;
74              
75 0     0   0 sub _carp { require Carp; goto &Carp::carp; }
  0         0  
76              
77              
78              
79              
80              
81              
82              
83              
84              
85              
86              
87              
88             sub _instance_id {
89 2     2   1823 my ($self) = @_;
90 2         11 require Scalar::Util;
91 2         7 my $addr = Scalar::Util::refaddr($self);
92 2 50       9 return $instances->{$addr} if exists $instances->{$addr};
93 2         14 $instances->{$addr} = sprintf '%x', $instance_id++;
94 2         5 return $instances->{$addr};
95             }
96              
97              
98              
99              
100              
101              
102              
103              
104              
105              
106              
107             sub _debug {
108 250     250   1573 my ( $self, $message ) = @_;
109              
110 250 50       607 return unless $DEBUG;
111 0         0 my $id = $self->_instance_id;
112 0         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             sub _with_debug {
127 16     16   25 my ( $self, $code ) = @_;
128 16         717 require Path::IsDev;
129             ## no critic (ProhibitNoWarnings)
130 12     12   8077 no warnings 'redefine';
  12         16  
  12         3422  
131             local *Path::IsDev::debug = sub {
132 229     229   430 $self->_debug(@_);
133 16         66 };
134 16         32 return $code->();
135             }
136              
137              
138              
139              
140              
141              
142              
143              
144              
145              
146             sub BUILD {
147 11     11 1 1995 my ($self) = @_;
148 11 50       60 return $self unless $DEBUG;
149 0         0 $self->_debug('{');
150 0         0 $self->_debug( ' set => ' . $self->set );
151 0         0 $self->_debug( ' set_prefix => ' . $self->set_prefix );
152 0         0 $self->_debug( ' set_module => ' . $self->set_module );
153 0         0 $self->_debug( ' loaded_set_module => ' . $self->loaded_set_module );
154 0         0 $self->_debug('}');
155 0         0 return $self;
156             }
157              
158              
159              
160              
161              
162              
163              
164              
165              
166              
167              
168             sub _matches {
169 16     16   2008 my ( $self, $path ) = @_;
170 16         3871 require Path::IsDev::Result;
171 16         111 my $result_object = Path::IsDev::Result->new( path => $path );
172 16         64 my $result;
173             $self->_with_debug(
174             sub {
175              
176 16     16   291 $self->_debug( 'Matching ' . $result_object->path );
177 16         229 $result = $self->loaded_set_module->matches($result_object);
178             },
179 16         79 );
180 16 50       306 if ( !!$result != !!$result_object->result ) {
181 0         0 _carp(q[Result and Result Object missmatch]);
182             }
183 16         99 return $result_object;
184             }
185              
186              
187              
188              
189              
190              
191              
192              
193              
194              
195              
196             sub matches {
197 15     15 1 9024 my ( $self, $path ) = @_;
198              
199 15         38 my $result_object = $self->_matches($path);
200              
201 15 100       203 if ( not $result_object->result ) {
202 3         18 $self->_debug('no match found');
203 3         18 return;
204             }
205              
206 12         194 return $result_object->result;
207             }
208              
209             1;
210              
211             __END__