Autouse.pm

filter: Statementstmt 96.5% 1989 / 2060 Branchbran 59.4% 126 / 212 Conditioncond 56.3% 31 / 55 MC/DCmcdc 23.5% 8 / 34 Subroutinesub 99.0% 603 / 609 Podpod 88.8% 8 / 9 totaltotal 92.8% 2765 / 2979 CC 138 SCAR 13.9
CC
138
Cov
92%
_depth
42.0
autouse
40.2
sugar
30.0
CRAP 4.0
↑ Summary Autouse/Parent.pm »
1 package Class::Autouse; # git description: c42b80d
2  
3 # See POD at end of file for documentation
4  
5 8 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶no strict 'refs'; # We _really_ abuse refs :)
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use UNIVERSAL ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Load required modules
11 # Luckily, these are so common they are basically free
12 8 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use File::Spec 0.80 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use List::Util 1.18 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # Globals
19 8 ▶use vars qw{ $VERSION @ISA $DB $DEBUG };
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use vars qw{ $DEVEL $SUPERLOAD $NOSTAT $NOPREBLESS $STATICISA }; # Load environment
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 ▶use vars qw{ %SPECIAL %LOADED %BAD %TRIED_CLASS %TRIED_METHOD }; # Special cases
Subroutine BEGIN: called CC=1 SCAR=0.0
22 8 ▶use vars qw{ @LOADERS @SUGAR $HOOKS $ORIGINAL_CAN $ORIGINAL_ISA }; # Working information
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # Handle optimisation switches via constants to allow debugging and
25 # similar functions to be optimised out at compile time if not in use.
26 8 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=12.0
27 8 ▶ $DB = 0 unless defined &DB::DB;
Branch: 1 branch
BranchTrueFalseTotal
unless defined &DB::DB 8 0 8
28 8 ▶ $DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Class::Autouse::DEBUG 8 0 8
29 }
30 8 ▶use constant DB => !! $DB;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 8 ▶use constant DEBUG => !! $DEBUG;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 8 print "Class::Autouse -> Debugging Activated.\n" if DEBUG;
33  
34 8 our $VERSION = '2.02';
35  
36 # Compile-time Initialisation and Optimisation
37 8 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
38 # Become an exporter so we don't get complaints when we act as a pragma.
39 # I don't fully understand the reason for this, but it works and I can't
40 # recall how to replicate the problem, so leaving it in to avoid any
41 # possible reversion. Besides, so many things use Exporter it should
42 # be practically free to do this.
43 8 @ISA = qw{ Exporter };
44  
45 # We always start with the superloader off
46 8 $SUPERLOAD = 0;
47  
48 # When set, disables $obj->isa/can where $obj is blessed before its class is loaded
49 # Things will operate more quickly when set, but this breaks things if you're
50 # unserializing objects from Data::Dumper, etc., and relying on this module to
51 # load the related classes on demand.
52 8 $NOPREBLESS = 0;
53  
54 # Disable stating for situations where modules are on remote disks
55 8 $NOSTAT = 0;
56  
57 # AUTOLOAD hook counter
58 8 $HOOKS = 0;
59  
60 # ERRATA
61 # Special classes are internal and should be left alone.
62 # Loaded modules are those already loaded by us.
63 # Bad classes are those that are incompatible with us.
64 8 %BAD = map { $_ => 1 } qw{
65 IO::File
66 };
67  
68 8 %SPECIAL = map { $_ => 1 } qw{
69 CORE main UNIVERSAL
70 ARRAY HASH SCALAR REF GLOB
71 };
72  
73 8 %LOADED = map { $_ => 1 } qw{
74 UNIVERSAL
75 Carp
76 Exporter
77 File::Spec
78 List::Util
79 Scalar::Util
80 Class::Autouse
81 };
82  
83 # "Have we tried to autoload a class before?"
84 # Per-class loop protection and improved shortcutting.
85 # Defaults to specials+preloaded to prevent attempting them.
86 8 %TRIED_CLASS = ( %SPECIAL, %LOADED );
87  
88 # "Have we tried to autoload a method before?"
89 # Per-method loop protection and improved shortcutting
90 8 %TRIED_METHOD = ();
91  
92 # Storage for dynamic loaders (regular and sugar)
93 8 @LOADERS = ();
94 8 @SUGAR = ();
95  
96 # We play with UNIVERSAL:: functions, so save backup copies
97 8 $ORIGINAL_CAN = \&UNIVERSAL::can;
98 8 $ORIGINAL_ISA = \&UNIVERSAL::isa;
99 }
100  
101  
102  
103  
104  
105 #####################################################################
106 # Configuration and Setting up
107  
108 # Developer mode flag.
109 # Cannot be turned off once turned on.
110 1 ▶sub devel {
Subroutine devel: called CC=3 SCAR=13.3
Pod documented
111 1 _debug(\@_, 1) if DEBUG;
112  
113 # Enable if not already
114 1 ▶ return 1 if $DEVEL++;
Branch: 1 branch
BranchTrueFalseTotal
if $Class::Autouse::DEVEL++ 0 1 1
115  
116 # Load any unloaded modules.
117 # Most of the time there should be nothing here.
118 1 foreach my $class ( grep { $INC{$_} eq 'Class::Autouse' } keys %INC ) {
119 0 $class =~ s/\//::/;
120 0 $class =~ s/\.pm$//i;
121 0 Class::Autouse->load($class);
122 }
123 }
124  
125 # Happy Fun Super Loader!
126 # The process here is to replace the &UNIVERSAL::AUTOLOAD sub
127 # ( which is just a dummy by default ) with a flexible class loader.
128 0 ▶sub superloader {
Subroutine superloader: not called CC=2 SCAR=17.9
Pod documented
129 0 _debug(\@_, 1) if DEBUG;
130  
131 # Shortcut if needed
132 0 ▶ return 1 if $SUPERLOAD++;
Branch: 1 branch
BranchTrueFalseTotal
if $Class::Autouse::SUPERLOAD++ 0 0 0
133  
134 # Enable the global hooks
135 0 _GLOBAL_HOOKS();
136  
137 0 return 1;
138 }
139  
140 0 ▶sub sugar {
Subroutine sugar: not called CC=5 SCAR=34.0
Pod documented
141 # Operate as a function or a method
142 0 ▶ shift if $_[0] eq 'Class::Autouse';
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq "Class::Autouse" 0 0 0
143  
144 # Ignore calls with no arguments
145 0 ▶ return 1 unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
146  
147 0 _debug(\@_) if DEBUG;
148  
149 0 foreach my $callback ( grep { $_ } @_ ) {
150 # Handle a callback or regex
151 0 ▶ unless ( ref $callback eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $callback eq "CODE") 0 0 0
152 0 die(
153 __PACKAGE__
154 . ' takes a code reference for syntactic sugar handlers'
155 . ": unexpected value $callback has type "
156 . ref($callback)
157 );
158 }
159 0 push @SUGAR, $callback;
160  
161 # Enable global hooking
162 0 _GLOBAL_HOOKS();
163 }
164  
165 0 return 1;
166 }
167  
168 # The main autouse sub
169 2118 ▶sub autouse {
Subroutine autouse: called CC=20 SCAR=36.9
Pod documented
170 # Operate as a function or a method
171 2118 ▶ shift if $_[0] eq 'Class::Autouse';
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq "Class::Autouse" 2118 0 2118
172  
173 # Ignore calls with no arguments
174 2118 ▶ return 1 unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 5 2113 2118
175  
176 2113 _debug(\@_) if DEBUG;
177  
178 2113 foreach my $class ( grep { $_ } @_ ) {
179 2117 ▶ if ( ref $class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 1153 964 2117
180 1153 ▶ unless ( ref $class eq 'Regexp' or ref $class eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $class eq "Regexp" or ref $class eq "CODE") 0 1153 1153
Condition66%2/3
ref $class eq "Regexp" or ref $class eq "CODE"
l!l&&r!l&&!r
5765770
MC/DC0%0/2
ref $class eq "Regexp" or ref $class eq "CODE"
ref $class eq "Regexp" ref $class eq "CODE"
Truth table66%2/3
A or B
A= ref $class eq "Regexp"B= ref $class eq "CODE"
ABresult
1X1
011
000
181 0 die( __PACKAGE__
182 . ' can autouse explicit class names, or take a regex or subroutine reference'
183 . ": unexpected value $class has type "
184 . ref($class)
185 );
186 }
187 1153 push @LOADERS, $class;
188  
189 # Enable the global hooks
190 1153 _GLOBAL_HOOKS();
191  
192 # Reset shortcut cache, since we may have previously
193 # tried a class and failed, which could now work
194 1153 %TRIED_CLASS = ( %SPECIAL, %LOADED );
195 1153 next;
196 }
197  
198 # Control flag handling
199 964 ▶ if ( substr($class, 0, 1) eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($class, 0, 1) eq ":") 1 963 964
200 1 ▶ if ( $class eq ':superloader' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($class eq ':superloader') { } 0 1 1
elsif ($class eq ':devel') { } 1 0 1
elsif ($class eq ':nostat') { } 0 0 0
elsif ($class eq ':noprebless') { } 0 0 0
elsif ($class eq ':staticisa') { } 0 0 0
201 # Turn on the superloader
202 0 Class::Autouse->superloader;
203 } elsif ( $class eq ':devel' ) {
204 # Turn on devel mode
205 1 Class::Autouse->devel(1);
206 } elsif ( $class eq ':nostat' ) {
207 # Disable stat checks
208 0 $NOSTAT = 1;
209 } elsif ( $class eq ':noprebless') {
210 # Disable support for objects blessed before their class module is loaded
211 0 $NOPREBLESS = 1;
212 } elsif ( $class eq ':staticisa') {
213 # Expect that @ISA won't change after loading
214 # This allows some performance tweaks
215 0 $STATICISA = 1;
216 }
217 1 next;
218 }
219  
220 # Load now if in devel mode, or if its a bad class
221 963 ▶ if ( $DEVEL || $BAD{$class} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Class::Autouse::DEVEL or $Class::Autouse::BAD{$class}) 0 963 963
Condition33%1/3
$Class::Autouse::DEVEL or $Class::Autouse::BAD{$class}
l!l&&r!l&&!r
00963
MC/DC0%0/2
$Class::Autouse::DEVEL or $Class::Autouse::BAD{$class}
$Class::Autouse::DEVEL $Class::Autouse::BAD{$class}
Truth table33%1/3
A or B
A= $Class::Autouse::DEVELB= $Class::Autouse::BAD{$class}
ABresult
1X1
011
000
222 0 Class::Autouse->load($class);
223 0 next;
224 }
225  
226 # Does the file for the class exist?
227 963 my $file = _class_file($class);
228 963 ▶ next if exists $INC{$file};
Branch: 1 branch
BranchTrueFalseTotal
if exists $INC{$file} 378 585 963
229 585 ▶ unless ( $NOSTAT or _file_exists($file) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Class::Autouse::NOSTAT or &_file_exists($file)) 0 585 585
Condition33%1/3
$Class::Autouse::NOSTAT or &_file_exists($file)
l!l&&r!l&&!r
05850
MC/DC0%0/2
$Class::Autouse::NOSTAT or &_file_exists($file)
$Class::Autouse::NOSTAT &_file_exists($file)
Truth table33%1/3
A or B
A= $Class::Autouse::NOSTATB= &_file_exists($file)
ABresult
1X1
011
000
230 0 my $inc = join ', ', @INC;
231 0 _cry("Can't locate $file in \@INC (\@INC contains: $inc)");
232 }
233  
234 # Don't actually do anything if the superloader is on.
235 # It will catch all AUTOLOAD calls.
236 585 ▶ next if $SUPERLOAD;
Branch: 1 branch
BranchTrueFalseTotal
if $Class::Autouse::SUPERLOAD 0 585 585
237  
238 # Add the AUTOLOAD hook and %INC lock to prevent 'use'ing
239 585 *{"${class}::AUTOLOAD"} = \&_AUTOLOAD;
240 585 $INC{$file} = 'Class::Autouse';
241  
242 # When we add the first hook, hijack UNIVERSAL::can/isa
243 585 ▶ _UPDATE_HOOKS() unless $HOOKS++;
Branch: 1 branch
BranchTrueFalseTotal
unless $Class::Autouse::HOOKS++ 12 573 585
244 }
245  
246 2113 return 1;
247 }
248  
249 # Import behaves the same as autouse
250 386 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
251 386 shift->autouse(@_);
252 }
253  
254  
255  
256  
257  
258 #####################################################################
259 # Explicit Actions
260  
261 # Completely load a class ( The class and all its dependencies ).
262 569 ▶sub load {
Subroutine load: called CC=4 SCAR=14.1
Pod documented
263 569 _debug(\@_, 1) if DEBUG;
264  
265 569 ▶ my $class = $_[1] or _cry('No class name specified to load');
Branch: 1 branch
BranchTrueFalseTotal
my $class = $_[1] or _cry("No class name specified to load") 569 0 569
266 569 ▶ return 1 if $LOADED{$class};
Branch: 1 branch
BranchTrueFalseTotal
if $Class::Autouse::LOADED{$class} 0 569 569
267  
268 569 my @search = _super( $class, \&_load );
269  
270 # If called an an array context, return the ISA tree.
271 # In scalar context, just return true.
272 569 ▶ wantarray ? @search : 1;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 120 449 569
273 }
274  
275 # Is a particular class installed in out @INC somewhere
276 # OR is it loaded in our program already
277 0 ▶sub class_exists {
Subroutine class_exists: not called CC=2 SCAR=17.9
Pod documented
278 0 _debug(\@_, 1) if DEBUG;
279 0 ▶ _namespace_occupied($_[1]) or _file_exists($_[1]);
Branch: 1 branch
BranchTrueFalseTotal
&_namespace_occupied($_[1]) or &_file_exists($_[1]) 0 0 0
280 }
281  
282 # A more general method to answer the question
283 # "Can I call a method on this class and expect it to work"
284 # Returns undef if the class does not exist
285 # Returns 0 if the class is not loaded ( or autouse'd )
286 # Returns 1 if the class can be used.
287 0 ▶sub can_call_methods {
Subroutine can_call_methods: not called CC=2 SCAR=17.9
Pod undocumented
288 0 _debug(\@_, 1) if DEBUG;
289 0 ▶ _namespace_occupied($_[1]) or exists $INC{_class_file($_[1])};
Branch: 1 branch
BranchTrueFalseTotal
&_namespace_occupied($_[1]) or exists $INC{&_class_file($_[1])} 0 0 0
290 }
291  
292 # Recursive methods currently only work withing the scope of the single @INC
293 # entry containing the "top" module, and will probably stay this way
294  
295 # Autouse not only a class, but all others below it.
296 2 ▶sub autouse_recursive {
Subroutine autouse_recursive: called CC=3 SCAR=11.0
Pod documented
297 2 _debug(\@_, 1) if DEBUG;
298  
299 # Just load if in devel mode
300 2 ▶ return Class::Autouse->load_recursive($_[1]) if $DEVEL;
Branch: 1 branch
BranchTrueFalseTotal
if $Class::Autouse::DEVEL 1 1 2
301  
302 # Don't need to do anything if the super loader is on
303 1 ▶ return 1 if $SUPERLOAD;
Branch: 1 branch
BranchTrueFalseTotal
if $Class::Autouse::SUPERLOAD 0 1 1
304  
305 # Find all the child classes, and hand them to the autouse method
306 1 Class::Autouse->autouse( $_[1], _children($_[1]) );
307 }
308  
309 # Load not only a class and all others below it
310 1 ▶sub load_recursive {
Subroutine load_recursive: called CC=2 SCAR=6.9
Pod documented
311 1 _debug(\@_, 1) if DEBUG;
312  
313 # Load the parent class, and its children
314 1 foreach ( $_[1], _children($_[1]) ) {
315 2 Class::Autouse->load($_);
316 }
317  
318 1 return 1;
319 }
320  
321  
322  
323  
324  
325 #####################################################################
326 # Symbol Table Hooks
327  
328 # These get hooked to various places on the symbol table,
329 # to enable the autoload functionality
330  
331 # Linked to each individual class via the symbol table
332 120 ▶sub _AUTOLOAD {
Subroutine _AUTOLOAD: called CC=7 SCAR=19.6
333 120 _debug(\@_, 0, ", AUTOLOAD = '$Class::Autouse::AUTOLOAD'") if DEBUG;
334  
335 # Loop detection (just in case)
336 120 ▶ my $method = $Class::Autouse::AUTOLOAD or _cry('Missing method name');
Branch: 1 branch
BranchTrueFalseTotal
my $method = $Class::Autouse::AUTOLOAD or _cry("Missing method name") 120 0 120
337 120 ▶ _cry("Undefined subroutine &$method called") if ++$TRIED_METHOD{$method} > 10;
Branch: 1 branch
BranchTrueFalseTotal
if ++$Class::Autouse::TRIED_METHOD{$method} > 10 0 120 120
338  
339 # Don't bother with special classes
340 120 my ($class, $function) = $method =~ m/^(.*)::(.*)\z/s;
341 120 ▶ _cry("Undefined subroutine &$method called") if $SPECIAL{$class};
Branch: 1 branch
BranchTrueFalseTotal
if $Class::Autouse::SPECIAL{$class} 0 120 120
342  
343 # Load the class and it's dependancies, and get the search path
344 120 my @search = Class::Autouse->load($class);
345  
346 # Find and go to the named method
347 298 ▶ my $found = List::Util::first {
Subroutine __ANON__: called CC=1 SCAR=0.0
348 298 defined *{"${_}::$function"}{CODE}
349 120 } @search;
350 120 ▶ goto &{"${found}::$function"} if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 63 57 120
351  
352 # Check for package AUTOLOADs
353 57 foreach my $c ( @search ) {
354 119 ▶ if ( defined *{"${c}::AUTOLOAD"}{CODE} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${c}::AUTOLOAD";}{"CODE"}) 57 62 119
355 # Simulate a normal autoload call
356 57 ${"${c}::AUTOLOAD"} = $method;
357 57 goto &{"${c}::AUTOLOAD"};
358 }
359 }
360  
361 # Can't find the method anywhere. Throw the same error Perl does.
362 0 _cry("Can't locate object method \"$function\" via package \"$class\"");
363 }
364  
365 # This is a special version of the above for use in UNIVERSAL
366 # It does the :superloader, and/or also any regex or callback (code ref) loaders
367 228 ▶sub _UNIVERSAL_AUTOLOAD {
Subroutine _UNIVERSAL_AUTOLOAD: called CC=13 SCAR=28.7
368 228 _debug(\@_, 0, ", \$AUTOLOAD = '$Class::Autouse::AUTOLOAD'") if DEBUG;
369  
370 # Loop detection ( Just in case )
371 228 ▶ my $method = $Class::Autouse::AUTOLOAD or _cry('Missing method name');
Branch: 1 branch
BranchTrueFalseTotal
my $method = $Class::Autouse::AUTOLOAD or _cry("Missing method name") 228 0 228
372 228 ▶ _cry("Undefined subroutine &$method called") if ++$TRIED_METHOD{ $method } > 10;
Branch: 1 branch
BranchTrueFalseTotal
if ++$Class::Autouse::TRIED_METHOD{$method} > 10 0 228 228
373  
374 # Don't bother with special classes
375 228 my ($class, $function) = $method =~ m/^(.*)::(.*)\z/s;
376 228 ▶ _cry("Undefined subroutine &$method called") if $SPECIAL{$class};
Branch: 1 branch
BranchTrueFalseTotal
if $Class::Autouse::SPECIAL{$class} 0 228 228
377  
378 228 my @search;
379 228 ▶ if ( $SUPERLOAD ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Class::Autouse::SUPERLOAD) 0 228 228
380 # Only try direct loading of the class if the superloader is active.
381 # This might be installed in universal for either the superloader, special loaders, or both.
382  
383 # Load the class and it's dependancies, and get the search path
384 0 @search = Class::Autouse->load($class);
385 }
386  
387 228 ▶ unless ( @search ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@search) 228 0 228
388 # The special loaders will attempt to dynamically instantiate the class.
389 # They will not fire if the superloader is turned on and has already loaded the class.
390 228 ▶ if ( _try_loaders($class, $function, @_) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_try_loaders($class, $function, @_)) 228 0 228
391 228 my $fref = $ORIGINAL_CAN->($class, $function);
392 228 ▶ if ( $fref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fref) { } 114 114 228
393 114 goto $fref;
394 } else {
395 114 @search = _super($class);
396 }
397 }
398 }
399  
400 # Find and go to the named method
401 114 ▶ my $found = List::Util::first { defined *{"${_}::$function"}{CODE} } @search;
Subroutine __ANON__: called CC=1 SCAR=0.0
402 0 ▶ goto &{"${found}::$function"} if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 114 114
403  
404 # Check for package AUTOLOADs
405 114 foreach my $c ( @search ) {
406 238 ▶ if ( defined *{"${c}::AUTOLOAD"}{CODE} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${c}::AUTOLOAD";}{"CODE"}) 114 124 238
407 # Simulate a normal autoload call
408 114 ${"${c}::AUTOLOAD"} = $method;
409 114 goto &{"${c}::AUTOLOAD"};
410 }
411 }
412  
413 0 for my $callback ( @SUGAR ) {
414 0 my $rv = $callback->( $class, $function, @_ );
415 0 ▶ goto $rv if $rv;
Branch: 1 branch
BranchTrueFalseTotal
if $rv 0 0 0
416 }
417  
418 # Can't find the method anywhere. Throw the same error Perl does.
419 0 _cry("Can't locate object method \"$function\" via package \"$class\"");
420 }
421  
422 # This just handles the call and does nothing.
423 # It prevents destroy calls going through to the AUTOLOAD hooks.
424 665231 ▶sub _UNIVERSAL_DESTROY {
Subroutine _UNIVERSAL_DESTROY: called CC=1 SCAR=0.0
425 665231 _debug(\@_) if DEBUG;
426 }
427  
428 195 ▶sub _isa {
Subroutine _isa: called CC=7 SCAR=21.8
429 # Optional performance hack
430 195 ▶ goto $ORIGINAL_ISA if ref $_[0] and $NOPREBLESS;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] and $Class::Autouse::NOPREBLESS 0 195 195
Condition33%1/3
ref $_[0] and $Class::Autouse::NOPREBLESS
!ll&&!rl&&r
19500
MC/DC0%0/2
ref $_[0] and $Class::Autouse::NOPREBLESS
ref $_[0] $Class::Autouse::NOPREBLESS
Truth table33%1/3
A and B
A= ref $_[0]B= $Class::Autouse::NOPREBLESS
ABresult
0X0
100
111
431  
432 # Load the class, unless we are sure it is already
433 195 ▶ my $class = ref $_[0] || $_[0] || return undef;
Condition40%2/5
ref $_[0] || $_[0] || (return undef)
l!l
1950
ref $_[0] or $_[0]
l!l&&r!l&&!r
01950
MC/DC0%0/2
ref $_[0] || $_[0] || (return undef)
ref $_[0] $_[0]
Truth table33%1/3
A or B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
434 195 ▶ unless ( $TRIED_CLASS{$class} or $LOADED{$class} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Class::Autouse::TRIED_CLASS{$class} or $Class::Autouse::LOADED{$class}) 192 3 195
Condition66%2/3
$Class::Autouse::TRIED_CLASS{$class} or $Class::Autouse::LOADED{$class}
l!l&&r!l&&!r
30192
MC/DC50%1/2
$Class::Autouse::TRIED_CLASS{$class} or $Class::Autouse::LOADED{$class}
$Class::Autouse::TRIED_CLASS{$class} $Class::Autouse::LOADED{$class}
Truth table66%2/3
A or B
A= $Class::Autouse::TRIED_CLASS{$class}B= $Class::Autouse::LOADED{$class}
ABresult
1X1
011
000
435 192 _preload($_[0]);
436 }
437  
438 195 goto &{$ORIGINAL_ISA};
439 }
440  
441 # This is the replacement for UNIVERSAL::can
442 971635 ▶sub _can {
Subroutine _can: called CC=7 SCAR=20.4
443 # Optional performance hack
444 971635 ▶ goto $ORIGINAL_CAN if ref $_[0] and $NOPREBLESS;
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] and $Class::Autouse::NOPREBLESS 0 971635 971635
Condition66%2/3
ref $_[0] and $Class::Autouse::NOPREBLESS
!ll&&!rl&&r
1919714440
MC/DC0%0/2
ref $_[0] and $Class::Autouse::NOPREBLESS
ref $_[0] $Class::Autouse::NOPREBLESS
Truth table66%2/3
A and B
A= ref $_[0]B= $Class::Autouse::NOPREBLESS
ABresult
0X0
100
111
445  
446 # Load the class, unless we are sure it is already
447 971635 ▶ my $class = ref $_[0] || $_[0] || return undef;
Condition60%3/5
ref $_[0] || $_[0] || (return undef)
l!l
9716350
ref $_[0] or $_[0]
l!l&&r!l&&!r
9714441910
MC/DC0%0/2
ref $_[0] || $_[0] || (return undef)
ref $_[0] $_[0]
Truth table66%2/3
A or B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
448 971635 ▶ unless ( $TRIED_CLASS{$class} or $LOADED{$class} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Class::Autouse::TRIED_CLASS{$class} or $Class::Autouse::LOADED{$class}) 214 971421 971635
Condition66%2/3
$Class::Autouse::TRIED_CLASS{$class} or $Class::Autouse::LOADED{$class}
l!l&&r!l&&!r
9714210214
MC/DC50%1/2
$Class::Autouse::TRIED_CLASS{$class} or $Class::Autouse::LOADED{$class}
$Class::Autouse::TRIED_CLASS{$class} $Class::Autouse::LOADED{$class}
Truth table66%2/3
A or B
A= $Class::Autouse::TRIED_CLASS{$class}B= $Class::Autouse::LOADED{$class}
ABresult
1X1
011
000
449 214 _preload($_[0]);
450 }
451  
452 971635 goto &{$ORIGINAL_CAN};
453 }
454  
455  
456  
457  
458  
459 #####################################################################
460 # Support Functions
461  
462 2099 ▶sub _preload {
Subroutine _preload: called CC=12 SCAR=25.3
463 2099 _debug(\@_) if DEBUG;
464  
465 # Does it look like a package?
466 2099 ▶ my $class = ref $_[0] || $_[0];
Condition66%2/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
2320760
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
467 2099 ▶ unless ( $class and $class =~ /^[^\W\d]\w*(?:(?:\'|::)[^\W]\w*)*$/o ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class and $class =~ /^[^\W\d]\w*(?:(?:\'|::)[^\W]\w*)*$/o) 2 2097 2099
Condition66%2/3
$class and $class =~ /^[^\W\d]\w*(?:(?:\'|::)[^\W]\w*)*$/o
!ll&&!rl&&r
022097
MC/DC50%1/2
$class and $class =~ /^[^\W\d]\w*(?:(?:\'|::)[^\W]\w*)*$/o
$class $class =~ /^[^\W\d]\w*(?:(?:\'|::)[^\W]\w*)*$/o
Truth table66%2/3
A and B
A= $classB= $class =~ /^[^\W\d]\w*(?:(?:\'|::)[^\W]\w*)*$/o
ABresult
0X0
100
111
468 2 return $LOADED{$class} = 1;
469 }
470  
471 # Do we try to load the class
472 2097 my $load = 0;
473 2097 my $file = _class_file($class);
474 2097 ▶ if ( defined $INC{$file} and $INC{$file} eq 'Class::Autouse' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $INC{$file} and $INC{$file} eq 'Class::Autouse') { } 447 1650 2097
elsif (not $Class::Autouse::SUPERLOAD) { } 1650 0 1650
elsif (&_namespace_occupied($class)) { } 0 0 0
Condition100%3/3
defined $INC{$file} and $INC{$file} eq "Class::Autouse"
!ll&&!rl&&r
1086564447
MC/DC100%2/2
defined $INC{$file} and $INC{$file} eq "Class::Autouse"
defined $INC{$file} $INC{$file} eq "Class::Autouse"
Truth table100%3/3
A and B
A= defined $INC{$file}B= $INC{$file} eq "Class::Autouse"
ABresult
0X0
100
111
475 # It's an autoused class
476 447 $load = 1;
477 } elsif ( ! $SUPERLOAD ) {
478 # Superloader isn't on, don't load
479 1650 $load = 0;
480 } elsif ( _namespace_occupied($class) ) {
481 # Superloader is on, but there is something already in the class
482 # This can't be the autouse loader, because we would have caught
483 # that case already.
484 0 $load = 0;
485 } else {
486 # The rules of the superloader say we assume loaded unless we can
487 # tell otherwise. Thus, we have to have a go at loading.
488 0 $load = 1;
489 }
490  
491 # If needed, load the class and all its dependencies.
492 2097 ▶ Class::Autouse->load($class) if $load;
Branch: 1 branch
BranchTrueFalseTotal
if $load 447 1650 2097
493  
494 2097 ▶ unless ( $LOADED{$class} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Class::Autouse::LOADED{$class}) 1427 670 2097
495 1427 _try_loaders($class);
496 1427 ▶ unless ( $LOADED{$class} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Class::Autouse::LOADED{$class}) 28 1399 1427
497 28 ▶ if ( _namespace_occupied($class) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_namespace_occupied($class)) 1 27 28
498 # The class is not flagged as loaded by autouse, but exists
499 # to ensure its ancestry is loaded before calling $orig
500 1 $LOADED{$class} = 1;
501 1 _load_ancestors($class);
502 }
503 }
504 }
505  
506 2097 return 1;
507 }
508  
509 1655 ▶sub _try_loaders {
Subroutine _try_loaders: called CC=10 SCAR=23.0
510 1655 _debug(\@_, 0) if DEBUG;
511 1655 my ($class, $function, @optional_args) = @_;
512 # The function and args are only present to help callbacks whose main goal is to
513 # do "syntactic sugar" instead of really writing a class
514  
515 # This allows us to shortcut out of re-checking a class
516 1655 $TRIED_CLASS{$class}++;
517  
518 1655 ▶ if ( _namespace_occupied($class) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_namespace_occupied($class)) 511 1144 1655
519 511 $LOADED{$class} = 1;
520 511 _load_ancestors($class);
521 511 return 1;
522 }
523  
524 # Try each of the special loaders, if there are any.
525 1144 for my $loader ( @LOADERS ) {
526 645555 my $ref = ref($loader);
527 645555 ▶ if ( $ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 645555 0 645555
528 645555 ▶ if ( $ref eq "Regexp" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'Regexp') { } 275585 369970 645555
elsif ($ref eq 'CODE') { } 369970 0 369970
529 275585 ▶ next unless $class =~ $loader;
Branch: 1 branch
BranchTrueFalseTotal
unless $class =~ /$loader/ 275000 585 275585
530 585 my $file = _class_file($class);
531 585 ▶ next unless grep { -e $_ . '/' . $file } @INC;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {-e $_ . '/' . $file;} @INC 27 558 585
532 558 local $^W = 0;
533 558 local $@;
534 558 ▶ eval "use $class";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
535 558 ▶ die "Class::Autouse found module $file for class $class matching regex '$loader',"
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 558 558
536 . " but it failed to compile with the following error: $@" if $@;
537 } elsif ( $ref eq "CODE" ) {
538 369970 ▶ unless ( $loader->( $class,$function,@optional_args ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$loader($class, $function, @optional_args)) 369412 558 369970
539 369412 next;
540 }
541 } else {
542 0 die "Unexpected loader. Expected qr//, sub{}, or class name string."
543 }
544 1116 $LOADED{$class} = 1;
545 1116 _load_ancestors($class);
546 1116 return 1;
547 } else {
548 0 die "Odd loader $loader passed to " . __PACKAGE__;
549 }
550 }
551  
552 28 return;
553 }
554  
555 # This is called after any class is hit by load/preload to ensure that parent classes are also loaded
556 2196 ▶sub _load_ancestors {
Subroutine _load_ancestors: called CC=4 SCAR=17.0
557 2196 _debug(\@_, 0) if DEBUG;
558 2196 my $class = $_[0];
559 2196 my ($this_class,@ancestors) = _super($class);
560 2196 for my $ancestor ( @ancestors ) {
561 # this is a bit ugly, _preload presumes either isa or can is being called,
562 # and does a goto at the end of it, we just want the core logic, not the redirection
563 # so we pass undef as the subref parameter
564 1693 _preload($ancestor);
565 }
566 2196 ▶ if ( $STATICISA ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Class::Autouse::STATICISA) 0 2196 2196
567 # Optional performance optimization.
568 # After we have the entire ancestry,
569 # set the greatest grandparent's can/isa to the originals.
570 # This keeps the versions in this module from being used where they're not needed.
571 0 ▶ my $final_parent = $ancestors[-1] || $this_class;
Condition0%0/3
$ancestors[-1] || $this_class
l!l&&r!l&&!r
000
MC/DC0%0/2
$ancestors[-1] || $this_class
$ancestors[-1] $this_class
Truth table0%0/3
A || B
A= $ancestors[-1]B= $this_class
ABresult
1X1
011
000
572 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
573 0 *{ $final_parent . '::can'} = $ORIGINAL_CAN;
574 0 *{ $final_parent . '::isa'} = $ORIGINAL_ISA;
575 }
576 2196 return 1;
577 }
578  
579 # This walks the @ISA tree, optionally calling a subref on each class
580 # and returns the inherited classes in a list, including $class itself.
581 2879 ▶sub _super {
Subroutine _super: called CC=5 SCAR=16.1
582 2879 _debug(\@_) if DEBUG;
583 2879 my $class = shift;
584 2879 my $load = shift;
585 2879 my @stack = ( $class );
586 2879 my %seen = ( UNIVERSAL => 1 );
587 2879 my @search = ();
588  
589 2879 ▶ while ( my $c = shift @stack ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = shift @stack) 5412 2879 8291
590 5412 ▶ next if $seen{$c}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$c}++ 20 5392 5412
591  
592 # This may load the class in question, so
593 # we call it before checking @ISA.
594 5392 ▶ if ( $load and not $LOADED{$c} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($load and not $Class::Autouse::LOADED{$c}) 590 4802 5392
Condition100%3/3
$load and not $Class::Autouse::LOADED{$c}
!ll&&!rl&&r
4231571590
MC/DC100%2/2
$load and not $Class::Autouse::LOADED{$c}
$load not $Class::Autouse::LOADED{$c}
Truth table100%3/3
A and not(B)
A= $loadB= not $Class::Autouse::LOADED{$c}
ABresult
0X0
100
111
595 590 $load->($c);
596 }
597  
598 # Add the class to the search list,
599 # and add the @ISA to the load stack.
600 5392 push @search, $c;
601 5392 unshift @stack, @{"${c}::ISA"};
602 }
603  
604 2879 return @search;
605 }
606  
607 # Load a single class
608 590 ▶sub _load ($) {
Subroutine _load: called CC=10 SCAR=26.0
609 590 _debug(\@_) if DEBUG;
610  
611 # Don't attempt to load special classes
612 590 ▶ my $class = shift or _cry('Did not specify a class to load');
Branch: 1 branch
BranchTrueFalseTotal
my $class = shift() or _cry("Did not specify a class to load") 590 0 590
613 590 $TRIED_CLASS{$class}++;
614  
615 590 ▶ return 1 if $SPECIAL{$class};
Branch: 1 branch
BranchTrueFalseTotal
if $Class::Autouse::SPECIAL{$class} 0 590 590
616  
617 # Run some checks
618 590 my $file = _class_file($class);
619 590 ▶ if ( defined $INC{$file} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $INC{$file}) { } 589 1 590
elsif (not &_file_exists($file)) { } 0 1 1
620 # If the %INC lock is set to any other value, the file is
621 # already loaded. We do not need to do anything.
622 589 ▶ if ( $INC{$file} ne 'Class::Autouse') {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{$file} ne "Class::Autouse") 22 567 589
623 22 return $LOADED{$class} = 1;
624 }
625  
626 # Because we autoused it earlier, we know the file for this
627 # class MUST exist.
628 # Removing the AUTOLOAD hook and %INC lock is all we have to do
629 567 delete ${"${class}::"}{'AUTOLOAD'};
630 567 delete $INC{$file};
631  
632 } elsif ( not _file_exists($file) ) {
633 # We might still be loaded, if the class was defined
634 # in some other module without it's own file.
635 0 ▶ if ( _namespace_occupied($class) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_namespace_occupied($class)) 0 0 0
636 0 return $LOADED{$class} = 1;
637 }
638  
639 # Not loaded and no file either.
640 # Try to generate the class instead.
641 0 ▶ if ( _try_loaders($class) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_try_loaders($class)) 0 0 0
642 0 return 1;
643 }
644  
645 # We've run out of options, it just doesn't exist
646 0 my $inc = join ', ', @INC;
647 0 _cry("Can't locate $file in \@INC (\@INC contains: $inc)");
648 }
649  
650 # Load the file for this class
651 568 print _depth(1) . " Class::Autouse::load -> Loading in $file\n" if DEBUG;
652 568 eval {
653 568 CORE::require($file);
654 };
655 568 ▶ _cry($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 568 568
656  
657 # Give back UNIVERSAL::can/isa if there are no other hooks
658 568 ▶ --$HOOKS or _UPDATE_HOOKS();
Branch: 1 branch
BranchTrueFalseTotal
--$Class::Autouse::HOOKS or &_UPDATE_HOOKS() 557 11 568
659  
660 568 $LOADED{$class} = 1;
661 568 _load_ancestors($class);
662 568 return 1;
663 }
664  
665 # Find all the child classes for a parent class.
666 # Returns in the list context.
667 2 ▶sub _children ($) {
Subroutine _children: called CC=11 SCAR=24.4
668 2 _debug(\@_) if DEBUG;
669  
670 # Find where it is in @INC
671 2 my $base_file = _class_file(shift);
672 2 ▶ my $inc_path = List::Util::first {
Subroutine __ANON__: called CC=1 SCAR=0.0
673 2 -f File::Spec->catfile($_, $base_file)
674 2 ▶ } @INC or return;
Branch: 1 branch
BranchTrueFalseTotal
my $inc_path = &List::Util::first(sub { -f "File::Spec"->catfile($_, $base_file); } , @INC) or return 2 0 2
675  
676 # Does the file have a subdirectory
677 # i.e. Are there child classes
678 2 my $child_path = substr( $base_file, 0, length($base_file) - 3 );
679 2 my $child_path_full = File::Spec->catdir( $inc_path, $child_path );
680 2 ▶ return 0 unless -d $child_path_full and -r _;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $child_path_full and -r _ 0 2 2
Condition33%1/3
-d $child_path_full and -r _
!ll&&!rl&&r
002
MC/DC0%0/2
-d $child_path_full and -r _
-d $child_path_full -r _
Truth table33%1/3
A and B
A= -d $child_path_fullB= -r _
ABresult
0X0
100
111
681  
682 # Main scan loop
683 2 local *FILELIST;
684 2 my ($dir, @files, @modules) = ();
685 2 my @queue = ( $child_path );
686 2 ▶ while ( $dir = pop @queue ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir = pop @queue) 3 2 5
687 3 my $full_dir = File::Spec->catdir($inc_path, $dir);
688  
689 # Read in the raw file list
690 # Skip directories we can't open
691 3 ▶ opendir( FILELIST, $full_dir ) or next;
Branch: 1 branch
BranchTrueFalseTotal
opendir FILELIST, $full_dir or next 3 0 3
692 3 @files = readdir FILELIST;
693 3 closedir FILELIST;
694  
695 # Iterate over them
696 5 @files = map { File::Spec->catfile($dir, $_) } # Full relative path
697 3 grep { ! /^\./ } @files; # Ignore hidden files
698 3 foreach my $file ( @files ) {
699 5 my $full_file = File::Spec->catfile($inc_path, $file);
700  
701 # Add to the queue if its a directory we can descend
702 5 ▶ if ( -d $full_file and -r _ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $full_file and -r _) 1 4 5
Condition66%2/3
-d $full_file and -r _
!ll&&!rl&&r
401
MC/DC50%1/2
-d $full_file and -r _
-d $full_file -r _
Truth table66%2/3
A and B
A= -d $full_fileB= -r _
ABresult
0X0
100
111
703 1 push @queue, $file;
704 1 next;
705 }
706  
707 # We only want .pm files we can read
708 4 ▶ next unless substr( $file, length($file) - 3 ) eq '.pm';
Branch: 1 branch
BranchTrueFalseTotal
unless substr($file, length($file) - 3) eq ".pm" 0 4 4
709 4 ▶ next unless -f _;
Branch: 1 branch
BranchTrueFalseTotal
unless -f _ 0 4 4
710  
711 4 push @modules, $file;
712 }
713 }
714  
715 # Convert the file names into modules
716 4 map { join '::', File::Spec->splitdir($_) }
717 2 map { substr($_, 0, length($_) - 3) } @modules;
718 }
719  
720  
721  
722  
723  
724 #####################################################################
725 # Private support methods
726  
727 # Does a class or file exists somewhere in our include path. For
728 # convenience, returns the unresolved file name ( even if passed a class )
729 586 ▶sub _file_exists ($) {
Subroutine _file_exists: called CC=7 SCAR=21.8
730 586 _debug(\@_) if DEBUG;
731  
732 # What are we looking for?
733 586 ▶ my $file = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $file = shift() or return undef 586 0 586
734 586 ▶ return undef if $file =~ m/(?:\012|\015)/o;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /(?:\012|\015)/o 0 586 586
735  
736 # If provided a class name, convert it
737 586 ▶ $file = _class_file($file) if $file =~ /::/o;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /::/o 0 586 586
738  
739 # Scan @INC for the file
740 586 foreach ( @INC ) {
741 586 ▶ next if ref $_ eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ eq "CODE" 0 586 586
742 586 ▶ return $file if -f File::Spec->catfile($_, $file);
Branch: 1 branch
BranchTrueFalseTotal
if -f "File::Spec"->catfile($_, $file) 586 0 586
743 }
744  
745 0 undef;
746 }
747  
748 # Is a namespace occupied by anything significant
749 1683 ▶sub _namespace_occupied ($) {
Subroutine _namespace_occupied: called CC=8 SCAR=21.1
750 1683 _debug(\@_) if DEBUG;
751  
752 # Handle the most likely case
753 1683 ▶ my $class = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $class = shift() or return undef 1683 0 1683
754 1683 ▶ return 1 if @{"${class}::ISA"};
Branch: 1 branch
BranchTrueFalseTotal
if @{"${class}::ISA";} 323 1360 1683
755  
756 # Get the list of glob names, ignoring namespaces
757 1360 foreach ( keys %{"${class}::"} ) {
758 1485 ▶ next if substr($_, -2) eq '::';
Branch: 1 branch
BranchTrueFalseTotal
if substr($_, -2) eq "::" 5 1480 1485
759  
760 # Only check for methods, since that's all that's reliable
761 1480 ▶ if (defined *{"${class}::$_"}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{"${class}::$_";}{"CODE"}) 189 1291 1480
762 189 ▶ if ($_ eq 'AUTOLOAD' and \&{"${class}::$_"} == \&_AUTOLOAD) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "AUTOLOAD" and \&{"${class}::$_";} == \&Class::Autouse::_AUTOLOAD) 0 189 189
Condition66%2/3
$_ eq "AUTOLOAD" and \&{"${class}::$_";} == \&Class::Autouse::_AUTOLOAD
!ll&&!rl&&r
18450
MC/DC0%0/2
$_ eq "AUTOLOAD" and \&{"${class}::$_";} == \&Class::Autouse::_AUTOLOAD
$_ eq "AUTOLOAD" \&{"${class}::$_";} == \&Class::Autouse::_AUTOLOAD
Truth table66%2/3
A and B
A= $_ eq "AUTOLOAD"B= \&{"${class}::$_";} == \&Class::Autouse::_AUTOLOAD
ABresult
0X0
100
111
763 # This is a Class::Autouse hook. Ignore.
764 0 next;
765 }
766 189 return 1;
767 }
768 }
769  
770 1171 '';
771 }
772  
773 # For a given class, get the file name
774 4237 ▶sub _class_file ($) {
Subroutine _class_file: called CC=1 SCAR=0.0
775 4237 join( '/', split /(?:\'|::)/, shift ) . '.pm';
776 }
777  
778 # Establish our call depth
779 0 ▶sub _depth {
Subroutine _depth: not called CC=6 SCAR=37.4
780 0 my $spaces = shift;
781 0 if ( DEBUG and ! $spaces ) {
782 _debug(\@_);
783 }
784  
785 # Search up the caller stack to find the first call that isn't us.
786 0 my $level = 0;
787 0 ▶ while( $level++ < 1000 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level++ < 1000) 0 0 0
788 0 my @call = caller($level);
789 0 ▶ if ( @call ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@call) 0 0 0
790 0 ▶ next if $call[3] eq '(eval)';
Branch: 1 branch
BranchTrueFalseTotal
if $call[3] eq "(eval)" 0 0 0
791 0 ▶ next if $call[3] =~ /^Class::Autouse::\w+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $call[3] =~ /^Class::Autouse::\w+\z/ 0 0 0
792 }
793  
794 # Subtract 1 for this sub's call
795 0 $level -= 1;
796 0 ▶ return $spaces ? join( '', (' ') x ($level - 2)) : $level;
Branch: 1 branch
BranchTrueFalseTotal
$spaces ? : 0 0 0
797 }
798  
799 0 Carp::croak('Infinite loop trying to find call depth');
800 }
801  
802 # Die gracefully
803 0 ▶sub _cry {
Subroutine _cry: not called CC=1 SCAR=6.9
804 0 _debug() if DEBUG;
805 0 local $Carp::CarpLevel = $Carp::CarpLevel;
806 0 $Carp::CarpLevel += _depth();
807 0 $_[0] =~ s/\s+at\s+\S+Autouse\.pm line \d+\.$//;
808 0 Carp::croak($_[0]);
809 }
810  
811 # Adaptive debug print generation
812 8 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
813 8 eval <<'END_DEBUG' if DEBUG;
814  
815 sub _debug {
816 my $args = shift;
817 my $method = !! shift;
818 my $message = shift || '';
819 my @c = caller(1);
820 my $msg = _depth(1) . $c[3];
821 if ( ref $args ) {
822 my @mapped = map { defined $_ ? "'$_'" : 'undef' } @$args;
823 shift @mapped if $method;
824 $msg .= @mapped ? '( ' . ( join ', ', @mapped ) . ' )' : '()';
825 }
826 print "$msg$message\n";
827 }
828  
829 END_DEBUG
830 }
831  
832  
833  
834  
835  
836 #####################################################################
837 # Final Initialisation
838  
839 # The _UPDATE_HOOKS function is intended to turn our hijacking of UNIVERSAL::can
840 # on or off, depending on whether we have any live hooks. The idea being, if we
841 # don't have any live hooks, why bother intercepting UNIVERSAL::can calls?
842 24 ▶sub _UPDATE_HOOKS () {
Subroutine _UPDATE_HOOKS: called CC=3 SCAR=11.0
843 24 local $^W = 0;
844 24 ▶ *UNIVERSAL::can = $HOOKS ? \&_can : $ORIGINAL_CAN;
Branch: 1 branch
BranchTrueFalseTotal
$Class::Autouse::HOOKS ? : 13 11 24
845 24 ▶ *UNIVERSAL::isa = $HOOKS ? \&_isa : $ORIGINAL_ISA;
Branch: 1 branch
BranchTrueFalseTotal
$Class::Autouse::HOOKS ? : 13 11 24
846 }
847  
848 # The _GLOBAL_HOOKS function turns on the universal autoloader hooks
849 1153 ▶sub _GLOBAL_HOOKS () {
Subroutine _GLOBAL_HOOKS: called CC=3 SCAR=11.0
850 1153 ▶ return if \&UNIVERSAL::AUTOLOAD == \&_UNIVERSAL_AUTOLOAD;
Branch: 1 branch
BranchTrueFalseTotal
if \&UNIVERSAL::AUTOLOAD == \&Class::Autouse::_UNIVERSAL_AUTOLOAD 1151 2 1153
851  
852 # Overwrite UNIVERSAL::AUTOLOAD and catch any
853 # UNIVERSAL::DESTROY calls so they don't trigger
854 # UNIVERSAL::AUTOLOAD. Anyone handling DESTROY calls
855 # via an AUTOLOAD should be summarily shot.
856 2 *UNIVERSAL::AUTOLOAD = \&_UNIVERSAL_AUTOLOAD;
857 2 *UNIVERSAL::DESTROY = \&_UNIVERSAL_DESTROY;
858  
859 # Because this will never go away, we increment $HOOKS such
860 # that it will never be decremented, and thus the
861 # UNIVERSAL::can/isa hijack will never be removed.
862 2 ▶ _UPDATE_HOOKS() unless $HOOKS++;
Branch: 1 branch
BranchTrueFalseTotal
unless $Class::Autouse::HOOKS++ 1 1 2
863 }
864  
865 8 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=15.2
866 # Optional integration with prefork.pm (if installed)
867 8 local $@;
868 8 eval { require prefork };
869 8 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 8 8
870 # prefork is not installed.
871 # Do manual detection of mod_perl
872 0 ▶ $DEVEL = 1 if $ENV{MOD_PERL};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"MOD_PERL"} 0 0 0
873 } else {
874 # Go into devel mode when prefork is enabled
875 8 $LOADED{prefork} = 1;
876 8 local $@;
877 8 eval "prefork::notify( sub { Class::Autouse->devel(1) } )";
878 8 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 8 8
879 }
880 }
881  
882 8 1;
883  
884 __END__
↑ Summary Autouse/Parent.pm »