blib/lib/Module/Data.pm

filter: Statementstmt 94.4% 68 / 72 Branchbran 75.0% 12 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.4% 17 / 18 Podpod 100% 3 / 3 totaltotal 91.7% 100 / 109 CC 9 SCAR 6.4
CC
9
Cov
91%
_build_root
4.0
__ANON__
2.0
require
2.0
CRAP 1.9
« /home/cpancover/.cpan/build/Module-Data-0.013-0/t/03_t/lib/site_perl/VERSION/ARCH-linux/Test/A.pm ↑ Summary /home/cpancover/.cpan/build/Module-Data-0.013-0/t/03_t/lib/VERSION/ARCH-linux/Test/C.pm »
1 4 ▶use 5.006; # our
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Module::Data;
6  
7 4 our $VERSION = '0.013';
8  
9 # ABSTRACT: Introspect context information about modules in @INC
10  
11 4 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 4 ▶use Moo qw( around has );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Sub::Quote qw( quote_sub );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 6 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
17 6 my ( $orig, $class, @args ) = @_;
18  
19 6 ▶ unshift @args, 'package' if @args % 2 == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 == 1 6 0 6
20  
21 6 return $class->$orig(@args);
22 4 };
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61 4 has package => (
62 required => 1,
63 is => 'ro',
64 ## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars, ValuesAndExpressions::RestrictLongStrings)
65 isa => quote_sub q{}
66 . q{die "given undef for 'package' , expects a Str/module name" if not defined $_[0];}
67 . q{die " ( 'package' => $_[0] ) is not a Str/module name, got a ref : " . ref $_[0] if ref $_[0];}
68 . q{require Module::Runtime;}
69 . q{Module::Runtime::check_module_name( $_[0] );},
70 );
71  
72 4 has _notional_name => (
73 is => 'ro',
74 lazy => 1,
75 ## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
76 default => quote_sub q{} . q{require Module::Runtime;} . q{return Module::Runtime::module_notional_filename( $_[0]->package );},
77 );
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89 15 ▶sub loaded {
Subroutine loaded: called CC=1 SCAR=0.0
Pod documented
90 15 my ($self) = @_;
91 15 return exists $INC{ $self->_notional_name };
92 }
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108 ## no critic ( ProhibitBuiltinHomonyms )
109 4 ▶sub require {
Subroutine require: called CC=2 SCAR=7.0
Pod documented
110 4 my ($self) = @_;
111 4 ▶ return $self->package if $self->loaded;
Branch: 1 branch
BranchTrueFalseTotal
if $self->loaded 0 4 4
112  
113 4 require Module::Runtime;
114 4 Module::Runtime::require_module( $self->package );
115 3 return $self->package;
116 }
117  
118 0 ▶sub _find_module_perl {
Subroutine _find_module_perl: not called CC=1 SCAR=6.9
119 0 my ($self) = @_;
120 0 $self->require;
121 0 return $INC{ $self->_notional_name };
122 }
123  
124 4 ▶sub _find_module_emulate {
Subroutine _find_module_emulate: called CC=1 SCAR=0.0
125 4 my ($self) = @_;
126 4 require Path::ScanINC;
127 4 Path::ScanINC->VERSION('0.011');
128 4 return Path::ScanINC->new()->first_file( $self->_notional_name );
129 }
130  
131 5 ▶sub _find_module_optimistic {
Subroutine _find_module_optimistic: called CC=2 SCAR=6.9
132 5 my ($self) = @_;
133 5 ▶ return $INC{ $self->_notional_name } if $self->loaded;
Branch: 1 branch
BranchTrueFalseTotal
if $self->loaded 1 4 5
134 4 return $self->_find_module_emulate;
135 }
136  
137 ## use critic
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153 4 has path => (
154 is => 'ro',
155 lazy => 1,
156 init_arg => undef,
157 builder => '_build_path',
158 );
159  
160 5 ▶sub _build_path {
Subroutine _build_path: called CC=2 SCAR=7.0
161 5 my ( $self, ) = @_;
162 5 my $value = $self->_find_module_optimistic;
163 5 ▶ return if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 5 5
164 5 require Path::Tiny;
165 5 return Path::Tiny::path($value)->absolute;
166 }
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184 4 has root => (
185 is => 'ro',
186 lazy => 1,
187 init_arg => undef,
188 builder => '_build_root',
189 );
190  
191 5 ▶sub _build_root {
Subroutine _build_root: called CC=4 SCAR=14.0
192 5 my ($path) = $_[0]->path;
193  
194 # Parent ne Self is the only cross-platform way
195 # I can think of that will stop at the top of a tree
196 # as / is not applicable on windows.
197 5 ▶ while ( $path->parent->absolute ne $path->absolute ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path->parent->absolute ne $path->absolute) 15 0 15
198 15 ▶ if ( not $path->is_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path->is_dir) 5 10 15
199 5 $path = $path->parent;
200 5 next;
201 }
202 10 ▶ if ( $path->child( $_[0]->_notional_name )->absolute eq $_[0]->path->absolute ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path->child($_[0]->_notional_name)->absolute eq $_[0]->path->absolute) 5 5 10
203 5 return $path->absolute;
204 }
205 5 $path = $path->parent;
206 }
207 0 return;
208  
209 }
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231 4 ▶sub _version_perl {
Subroutine _version_perl: called CC=1 SCAR=0.0
232 4 my ($self) = @_;
233 4 $self->require;
234  
235 # has to load the code into memory to work
236 3 return $self->package->VERSION;
237 }
238  
239 4 ▶sub _version_emulate {
Subroutine _version_emulate: called CC=1 SCAR=0.0
240 4 my ($self) = @_;
241 4 my $path = $self->path;
242 4 require Module::Metadata;
243 4 my $i = Module::Metadata->new_from_file( $path, collect_pod => 0 );
244 4 return $i->version( $self->package );
245 }
246  
247 6 ▶sub _version_optimistic {
Subroutine _version_optimistic: called CC=2 SCAR=6.9
248 6 my ($self) = @_;
249 6 ▶ return $self->package->VERSION if $self->loaded;
Branch: 1 branch
BranchTrueFalseTotal
if $self->loaded 2 4 6
250 4 return $self->_version_emulate;
251 }
252  
253 6 ▶sub version {
Subroutine version: called CC=1 SCAR=0.0
Pod documented
254 6 my ( $self, ) = @_;
255 6 return $self->_version_optimistic;
256 }
257  
258  
259  
260  
261  
262  
263  
264  
265  
266 4 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
267  
268 4 1;
269  
270 __END__
« /home/cpancover/.cpan/build/Module-Data-0.013-0/t/03_t/lib/site_perl/VERSION/ARCH-linux/Test/A.pm ↑ Summary /home/cpancover/.cpan/build/Module-Data-0.013-0/t/03_t/lib/VERSION/ARCH-linux/Test/C.pm »