lib/Badger/Factory.pm

filter: Statementstmt 90.2% 139 / 154 Branchbran 64.0% 41 / 64 Conditioncond 53.8% 28 / 52 MC/DCmcdc 14.2% 4 / 28 Subroutinesub 95.4% 21 / 22 Podpod 93.7% 15 / 16 totaltotal 73.8% 248 / 336 CC 55 SCAR 19.9
CC
55
Cov
77%
init_factory
14.2
items
12.0
can
10.5
CRAP 7.3
« lib/Badger/Debug.pm ↑ Summary lib/Badger/Base.pm »
1 #========================================================================
2 #
3 # Badger::Factory
4 #
5 # DESCRIPTION
6 # Factory module for loading and instantiating other modules.
7 #
8 # NOTE
9 # This module has grown organically to fit a number of (possibly
10 # conflicting) needs. It needs to be completely refactored, and
11 # probably split into a number of different factory modules. The
12 # TT3 code on which this was originally based had separate base class
13 # factory modules for modules (that just got loaded), objects (that
14 # got loaded and instantiated) and single objects (that got loaded,
15 # created and cached). With hindsight, it was a mistake to try and
16 # cram all that functionality into one module. It should be separated
17 # into a base class module/API and a number of specialised subclasses.
18 #
19 # AUTHOR
20 # Andy Wardley <abw@wardley.org>
21 #
22 #========================================================================
23  
24 package Badger::Factory;
25  
26 24 ▶use Badger::Debug ':dump';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 use Badger::Class
28 24 version => 0.01,
29 debug => 0,
30 base => 'Badger::Prototype Badger::Exporter',
31 import => 'class',
32 utils => 'plural blessed textlike dotid camel_case',
33 words => 'ITEM ITEMS ISA',
34 constants => 'PKG ARRAY HASH REFS ONCE DEFAULT LOADED',
35 constant => {
36 OBJECT => 'object',
37 FOUND => 'found',
38 FOUND_REF => 'found_ref',
39 PATH_SUFFIX => '_PATH',
40 NAMES_SUFFIX => '_NAMES',
41 DEFAULT_SUFFIX => '_DEFAULT',
42 },
43 messages => {
44 no_item => 'No item(s) specified for factory to manage',
45 no_default => 'No default defined for %s factory',
46 bad_ref => 'Invalid reference for %s factory item %s: %s',
47 bad_method => qq{Can't locate object method "%s" via package "%s" at %s line %s},
48 24 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 24 our $RUNAWAY = 0;
51 24 our $AUTOLOAD;
52  
53 24 *init = \&init_factory;
54  
55  
56 sub init_factory {
57 25 ▶ my ($self, $config) = @_;
Subroutine init_factory: called CC=12 SCAR=26.6
Pod undocumented
58 25 my $class = $self->class;
59 25 my ($item, $items, $path, $map, $default);
60  
61 # 'item' and 'items' can be specified as config params or we look for
62 # $ITEM and $ITEMS variables in the current package or those of any
63 # base classes. NOTE: $ITEM and $ITEMS must be in the same package
64 25 ▶ unless ($item = $config->{ item }) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($item = $config->{"item"}) 24 1 25
65 24 foreach my $pkg ($class->heritage) {
66 24 ▶ no strict REFS;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 24 ▶ no warnings ONCE;
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 24 ▶ if (defined ($item = ${ $pkg.PKG.ITEM })) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($item = ${$pkg . '::' . "ITEM";})) 24 0 24
70 24 $items = ${ $pkg.PKG.ITEMS };
71 24 last;
72 }
73 }
74 }
75 25 ▶ return $self->error_msg('no_item')
Branch: 1 branch
BranchTrueFalseTotal
unless $item 0 25 25
76 unless $item;
77  
78 # use 'items' in config, or grokked from $ITEMS, or guess plural
79 25 ▶ $items = $config->{ items } || $items || plural($item);
Condition33%2/6
$config->{'items'} || $items || plural($item)
l!l&&r!l&&!r
0250
$config->{"items"} or $items
l!l&&r!l&&!r
0025
MC/DC0%0/3
$config->{'items'} || $items || plural($item)
$config->{"items"} $items plural($item)
Truth table25%1/4
A or B || C
A= $config->{"items"}B= $itemsC= plural($item)
ABCresult
1XX1
01X1
0011
0000
80  
81 25 my $ipath = $item.PATH_SUFFIX;
82 25 my $inames = $item.NAMES_SUFFIX;
83 25 my $idefault = $item.DEFAULT_SUFFIX;
84  
85 # Merge all XXXX_PATH package vars with any 'xxxx_path' or 'path' config
86 # items. Ditto for XXXX_NAME / 'xxxx_name' / 'aka' and XXXXS/ 'xxxxs'
87  
88 25 my @path = @$config{ path => lc $ipath };
89 25 my @names = @$config{ names => lc $inames };
90  
91 25 $self->{ path } = $class->list_vars(uc $ipath, @path);
92 25 $self->{ names } = $class->hash_vars(uc $inames, @names);
93 25 $self->{ $items } = $class->hash_vars(uc $items, $config->{ $items });
94 25 $self->{ items } = $items;
95 25 $self->{ item } = $item;
96 25 $self->{ loaded } = { };
97 $self->{ no_cache } = defined $config->{ no_cache } # quick hack
98 ? $config->{ no_cache }
99 25 ▶ : $class->any_var('NO_CACHE') || 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $config->{'no_cache'} ? : 0 25 25
Condition50%1/2
$class->any_var("NO_CACHE") or 0
l!l
025
MC/DC0%0/1
$class->any_var("NO_CACHE") or 0
$class->any_var("NO_CACHE")
Truth table50%1/2
A
A= $class->any_var("NO_CACHE")
Aresult
11
00
100  
101 # see if a 'xxxx_default' or 'default' configuration option is specified
102 # or look for the first XXXX_DEFAULT or DEFAULT package variable.
103 $default = $config->{ $idefault }
104 || $config->{ default }
105 25 ▶ || $class->any_var_in( uc $idefault, uc DEFAULT );
Condition33%2/6
$config->{$idefault} || $config->{'default'} || $class->any_var_in(uc $idefault, 'DEFAULT')
l!l&&r!l&&!r
0025
$config->{$idefault} or $config->{"default"}
l!l&&r!l&&!r
0025
MC/DC0%0/3
$config->{$idefault} || $config->{'default'} || $class->any_var_in(uc $idefault, 'DEFAULT')
$config->{$idefault} $config->{"default"} $class->any_var_in(uc $idefault, 'DEFAULT')
Truth table25%1/4
A or B || C
A= $config->{$idefault}B= $config->{"default"}C= $class->any_var_in(uc $idefault, 'DEFAULT')
ABCresult
1XX1
01X1
0011
0000
106 25 ▶ if ($default) {
Branch: 1 branch
BranchTrueFalseTotal
if ($default) 0 25 25
107 0 $self->debug("Setting default to $default") if DEBUG;
108 0 $self->{ default } = $self->{ names }->{ default } = $default;
109 }
110  
111 $self->debug(
112 "Initialised $item/$items factory\n",
113 " Path: ", $self->dump_data($self->{ path }), "\n",
114 "Names: ", $self->dump_data($self->{ names })
115 25 ) if DEBUG;
116  
117 25 return $self;
118 }
119  
120 sub path {
121 46 ▶ my $self = shift->prototype;
Subroutine path: called CC=3 SCAR=14.2
Pod documented
122 return @_
123 ? ($self->{ path } = ref $_[0] eq ARRAY ? shift : [ @_ ])
124 46 ▶ : $self->{ path };
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 46 46
ref $_[0] eq 'ARRAY' ? : 0 0 0
125 }
126  
127 sub default {
128 1 ▶ my $self = shift->prototype;
Subroutine default: called CC=2 SCAR=7.2
Pod documented
129 return @_
130 ? ($self->{ default } = $self->{ names }->{ default } = shift)
131 1 ▶ : $self->{ default };
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 0 1
132 }
133  
134 sub items {
135 0 ▶ my $self = shift->prototype;
Subroutine items: not called CC=3 SCAR=24.8
Pod documented
136 0 my $items = $self->{ $self->{ items } };
137 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
138 0 ▶ my $args = ref $_[0] eq HASH ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
139 0 @$items{ keys %$args } = values %$args;
140 }
141 0 return $items;
142 }
143  
144 sub item {
145 85 ▶ my $self = shift; $self = $self->prototype unless ref $self;
Subroutine item: called CC=9 SCAR=22.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 24 61 85
146 85 my ($type, @args) = $self->type_args(@_);
147  
148 # In most cases we're expecting $type to be a name (e.g. Table) which we
149 # lookup in the items hash, or tack onto one of the module bases in the
150 # path (e.g. Template::Plugin) to create a full module name which we load
151 # and instantiate (e.g. Template::Plugin::Table). However, the name might
152 # be explicitly mapped to a reference of some kind, or the $type passed
153 # in could already be a reference (e.g. Template::TT2::Filters allow the
154 # first argument to be a code ref or object which implements the required
155 # filtering behaviour). In which case, we bypass any name-based lookup
156 # and skip straight onto the "look what I found!" phase
157  
158 85 ▶ return $self->found($type, $type, \@args)
Branch: 1 branch
BranchTrueFalseTotal
unless &textlike($type) 2 83 85
159 unless textlike $type;
160  
161 83 $type = $type . ''; # auto-stringify any textlike objects
162  
163 # OK, so $type is a string. We'll also create a canonical version of the
164 # name (lower case dotted) to provide a case/syntax insensitve fallback
165 # (e.g. so "foo.bar" can match against "Foo.Bar", "Foo::Bar" and so on)
166  
167 83 my $items = $self->{ $self->{ items } };
168 83 my $canon = dotid $type;
169  
170 83 $self->debug("Looking for '$type' or '$canon' in $self->{ items }") if DEBUG;
171 # $self->debug("types: ", $self->dump_data($self->{ types })) if DEBUG;
172  
173 # false but defined entry indicates the item is not found
174 return $self->not_found($type, \@args)
175 if exists $items->{ $type }
176 83 ▶ && not $items->{ $type };
Branch: 1 branch
BranchTrueFalseTotal
if exists $items->{$type} and not $items->{$type} 0 83 83
Condition66%2/3
exists $items->{$type} and not $items->{$type}
!ll&&!rl&&r
39440
MC/DC0%0/2
exists $items->{$type} and not $items->{$type}
exists $items->{$type} not $items->{$type}
Truth table66%2/3
A and not(B)
A= exists $items->{$type}B= not $items->{$type}
ABresult
0X0
100
111
177  
178 my $item = $items->{ $type }
179 83 ▶ || $items->{ $canon }
Condition100%8/8
$items->{$type} || $items->{$canon} || $self->find($type, \@args) || (return $self->not_found($type, \@args))
l!l
812
$items->{$type} or $items->{$canon} or $self->find($type, \@args)
l!l&&r!l&&!r
47342
$items->{$type} or $items->{$canon}
l!l&&r!l&&!r
44336
MC/DC100%3/3
$items->{$type} || $items->{$canon} || $self->find($type, \@args) || (return $self->not_found($type, \@args))
$items->{$type} $items->{$canon} $self->find($type, \@args)
Truth table100%4/4
A or B or C
A= $items->{$type}B= $items->{$canon}C= $self->find($type, \@args)
ABCresult
1XX1
01X1
0011
0000
180 # TODO: this needs to be defined-or, like //
181 # Plugins can return an empty string to indicate that they
182 # do nothing.
183 # HMMM.... or does it?
184 || $self->find($type, \@args)
185 # || $self->default($type, \@args)
186 || return $self->not_found($type, \@args);
187  
188 $items->{ $type } = $item
189 81 ▶ unless $self->{ no_cache };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"no_cache"} 81 0 81
190  
191 81 return $self->found($type, $item, \@args);
192 }
193  
194 sub type_args {
195 # Simple method to grok $type and @args from argument list. The only
196 # processing it does is to set $type to 'default' if it is undefined or
197 # false. Subclasses can re-define this to insert their own type mapping or
198 # argument munging, e.g. to inject values into the configuration params
199 # for an object
200 65 ▶ shift;
Subroutine type_args: called CC=4 SCAR=15.5
Pod documented
201 65 ▶ my $type = shift || DEFAULT;
Condition100%2/2
shift() || 'default'
l!l
632
MC/DC100%1/1
shift() || 'default'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
202 65 my @args;
203  
204 65 ▶ if (ref $type eq HASH) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $type eq 'HASH') { } 0 65 65
205 0 @args = ($type, @_);
206 0 ▶ $type = $type->{ type } || DEFAULT;
Condition0%0/2
$type->{'type'} || 'default'
l!l
00
MC/DC0%0/1
$type->{'type'} || 'default'
$type->{'type'}
Truth table0%0/2
A
A= $type->{'type'}
Aresult
11
00
207 }
208 else {
209 65 @args = @_;
210 }
211  
212 65 return ($type, @args);
213 }
214  
215 sub find {
216 46 ▶ my $self = shift;
Subroutine find: called CC=4 SCAR=13.9
Pod documented
217 46 my $type = shift;
218 46 my $bases = $self->path;
219 46 my $module;
220  
221 # run the type through the type map to handle any unusual capitalisation,
222 # spelling, aliases, etc.
223 46 ▶ $type = $self->{ names }->{ $type } || $type;
Condition66%2/3
$self->{'names'}{$type} || $type
l!l&&r!l&&!r
1450
MC/DC0%0/2
$self->{'names'}{$type} || $type
$self->{'names'}{$type} $type
Truth table66%2/3
A || B
A= $self->{'names'}{$type}B= $type
ABresult
1X1
011
000
224  
225 46 foreach my $base (@$bases) {
226 54 ▶ return $module
Branch: 1 branch
BranchTrueFalseTotal
if $module = $self->load($self->module_names($base, $type)) 44 10 54
227 if $module = $self->load( $self->module_names($base, $type) );
228 }
229  
230 2 return undef;
231 }
232  
233 sub load {
234 54 ▶ my $self = shift;
Subroutine load: called CC=5 SCAR=16.1
Pod documented
235 54 my $loaded = $self->{ loaded };
236  
237 54 foreach my $module (@_) {
238 # see if we've previously loaded a module with this name (true
239 # value) or failed to load a module (defined but false value)
240  
241 64 ▶ if ($loaded->{ $module }) {
Branch: 2 branches
BranchTrueFalseTotal
if ($loaded->{$module}) { } 12 52 64
elsif (defined $loaded->{$module}) { } 0 52 52
242 12 $self->debug("$module has been previously loaded") if DEBUG;
243 12 return $module;
244 }
245 elsif (defined $loaded->{ $module }) {
246 0 next;
247 }
248  
249 24 ▶ no strict REFS;
Subroutine BEGIN: called CC=1 SCAR=0.0
250 52 $self->debug("attempting to load $module") if DEBUG;
251  
252 # Some filesystems are case-insensitive (like Apple's HFS), so an
253 # attempt to load Badger::Example::foo may succeed, when the correct
254 # package name is actually Badger::Example::Foo. We double-check
255 # by looking for $VERSION or @ISA. This is a bit dodgy because we might be
256 # loading something that has no ISA. Need to cross-check with
257 # what's going on in Badger::Class _autoload()
258  
259 52 my $loadname;
260 52 ▶ if ( ($loadname = class($module)->maybe_load) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loadname = Badger::Factory::class($module)->maybe_load) 32 20 52
261 32 $self->debug("loaded $module") if DEBUG;
262 32 $loaded->{ $module } = $loadname;
263 32 return $module
264 }
265  
266 20 $self->debug("failed to load $module") if DEBUG;
267 }
268  
269 10 return undef;
270 }
271  
272  
273 sub found {
274 83 ▶ my ($self, $type, $item, $args) = @_;
Subroutine found: called CC=6 SCAR=18.3
Pod documented
275  
276 83 ▶ if (ref $item) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item) { } 29 54 83
277 # if it's a reference we found then forward it onto the appropriate
278 # method, e.g found_array(), found_hash(), found_code(). Fall back
279 # on found_ref()
280 29 ▶ my $iref = blessed($item)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($item) ? : 25 4 29
281 ? OBJECT
282 : lc ref $item;
283  
284 29 $self->debug(
285 "Looking for handler methods: ",
286 FOUND,'_'.$iref, "() or ",
287 FOUND_REF, "()"
288 ) if DEBUG;
289  
290 my $method
291 = $self->can(FOUND . '_' . $iref)
292 || $self->can(FOUND_REF)
293 29 ▶ || return $self->error_msg( bad_ref => $self->{ item }, $type, $iref );
Condition40%2/5
$self->can('found_' . $iref) || $self->can('found_ref') || (return $self->error_msg('bad_ref', $self->{'item'}, $type, $iref))
l!l
290
$self->can('found_' . $iref) or $self->can("found_ref")
l!l&&r!l&&!r
2900
MC/DC0%0/2
$self->can('found_' . $iref) || $self->can('found_ref') || (return $self->error_msg('bad_ref', $self->{'item'}, $type, $iref))
$self->can('found_' . $iref) $self->can("found_ref")
Truth table33%1/3
A or B
A= $self->can('found_' . $iref)B= $self->can("found_ref")
ABresult
1X1
011
000
294  
295 29 $item = $method->($self, $type, $item, $args);
296 }
297 else {
298 # otherwise it's the name of a module
299 54 $item = $self->found_module($type, $item, $args);
300 }
301  
302 # NOTE: an item can be defined but false, e.g. a Template::Plugin which
303 # return '' from its new() method to indicate it does nothing objecty
304 83 ▶ return unless defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 0 83 83
305  
306 83 $self->debug("Found result: $type => $item") if DEBUG;
307  
308 # TODO: what about caching result? Do we always leave that to subclasses?
309 83 return $self->result($type, $item, $args);
310 }
311  
312 sub found_module {
313 # This method is called when a module name is found, either by being
314 # predefined in the factory entry table, or loaded on demand from disk.
315 # It ensures the module is loaded and and instantiates an object from the
316 # class name
317 54 ▶ my ($self, $type, $module, $args) = @_;
Subroutine found_module: called CC=2 SCAR=7.0
Pod documented
318 54 $self->debug("Found module: $type => $module") if DEBUG;
319 54 ▶ $self->{ loaded }->{ $module } ||= class($module)->load;
Condition66%2/3
$self->{"loaded"}{$module} ||= Badger::Factory::class($module)->load
l!l&&r!l&&!r
4770
MC/DC0%0/2
$self->{"loaded"}{$module} ||= Badger::Factory::class($module)->load
$self->{"loaded"}{$module} Badger::Factory::class($module)->load
Truth table66%2/3
A ||= B
A= $self->{"loaded"}{$module}B= Badger::Factory::class($module)->load
ABresult
1X1
011
000
320 54 return $self->construct($type, $module, $args);
321 }
322  
323 sub found_array {
324 # This method is called when an ARRAY reference is found. We assume that
325 # the first item is the module name (which needs to be loaded) and the
326 # second item is the class name (which needs to be instantiated).
327 4 ▶ my ($self, $type, $item, $args) = @_;
Subroutine found_array: called CC=2 SCAR=7.0
Pod documented
328 4 my ($module, $class) = @$item;
329 4 ▶ $self->{ loaded }->{ $module } ||= class($module)->load;
Condition66%2/3
$self->{"loaded"}{$module} ||= Badger::Factory::class($module)->load
l!l&&r!l&&!r
130
MC/DC0%0/2
$self->{"loaded"}{$module} ||= Badger::Factory::class($module)->load
$self->{"loaded"}{$module} Badger::Factory::class($module)->load
Truth table66%2/3
A ||= B
A= $self->{"loaded"}{$module}B= Badger::Factory::class($module)->load
ABresult
1X1
011
000
330 4 return $self->construct($type, $class, $args);
331 }
332  
333 sub not_found {
334 2 ▶ my ($self, $type, @args) = @_;
Subroutine not_found: called CC=2 SCAR=6.9
Pod documented
335  
336 return $type eq DEFAULT
337 ? $self->error_msg( no_default => $self->{ item } )
338 2 ▶ : $self->error_msg( not_found => $self->{ item }, $type );
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'default' ? : 1 1 2
339 }
340  
341 sub construct {
342 59 ▶ my ($self, $type, $class, $args) = @_;
Subroutine construct: called CC=1 SCAR=0.0
Pod documented
343 59 $self->debug("constructing class: $type => $class") if DEBUG;
344 59 return $class->new(@$args);
345 }
346  
347 sub module_names {
348 54 ▶ my $self = shift;
Subroutine module_names: called CC=1 SCAR=0.0
Pod documented
349 my @bits =
350 119 map { camel_case($_) }
351 54 map { split /[\.]+/ } @_;
352  
353 return (
354 54 join( PKG, map { ucfirst $_ } @bits ),
355 join( PKG, @bits )
356 );
357 }
358  
359  
360 sub can {
361 35 ▶ my ($self, $name) = @_;
Subroutine can: called CC=6 SCAR=23.5
Pod documented
362  
363 # upgrade class methods to calls on prototype
364 35 ▶ $self = $self->prototype unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 35 35
365  
366 # NOTE: this method can get called before we've called init_factory()
367 # to define the item/items members, so we tread carefully.
368 35 ▶ if ($self->{ item } && $self->{ item } eq $name) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'item'} and $self->{'item'} eq $name) { } 0 35 35
elsif ($self->{'items'} and $self->{'items'} eq $name) { } 0 35 35
Condition33%1/3
$self->{"item"} and $self->{"item"} eq $name
!ll&&!rl&&r
0350
MC/DC0%0/2
$self->{"item"} and $self->{"item"} eq $name
$self->{"item"} $self->{"item"} eq $name
Truth table33%1/3
A and B
A= $self->{"item"}B= $self->{"item"} eq $name
ABresult
0X0
100
111
369 0 return $self->SUPER::can('item');
370 }
371 ▶ elsif ($self->{ items } && $self->{ items } eq $name) {
Condition33%1/3
$self->{"items"} and $self->{"items"} eq $name
!ll&&!rl&&r
0350
MC/DC0%0/2
$self->{"items"} and $self->{"items"} eq $name
$self->{"items"} $self->{"items"} eq $name
Truth table33%1/3
A and B
A= $self->{"items"}B= $self->{"items"} eq $name
ABresult
0X0
100
111
372 0 return $self->SUPER::can('items');
373 }
374 else {
375 35 return $self->SUPER::can($name);
376 }
377 }
378  
379 sub result {
380 33 ▶ $_[2];
Subroutine result: called CC=1 SCAR=0.0
Pod documented
381 }
382  
383 sub AUTOLOAD {
384 12 ▶ my ($self, @args) = @_;
Subroutine AUTOLOAD: called CC=8 SCAR=21.7
385 12 my ($name) = ($AUTOLOAD =~ /([^:]+)$/ );
386 12 ▶ return if $name eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "DESTROY" 5 7 12
387  
388 7 $self->debug("AUTOLOAD $name") if DEBUG;
389  
390 7 local $RUNAWAY = $RUNAWAY;
391 7 ▶ $self->error("AUTOLOAD went runaway on $name")
Branch: 1 branch
BranchTrueFalseTotal
if ++$Badger::Factory::RUNAWAY > 10 0 7 7
392 if ++$RUNAWAY > 10;
393  
394 # upgrade class methods to calls on prototype
395 7 ▶ $self = $self->prototype unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 4 3 7
396  
397 7 $self->debug("factory item: $self->{ item }") if DEBUG;
398  
399 7 ▶ if ($name eq $self->{ item }) {
Branch: 3 branches
BranchTrueFalseTotal
if ($name eq $self->{'item'}) { } 6 1 7
elsif ($name eq $self->{'items'}) { } 0 1 1
elsif (my $item = $self->try('item', $name, @args)) { } 0 1 1
400 6 $self->class->method( $name => $self->can('item') );
401 }
402 elsif ($name eq $self->{ items }) {
403 0 $self->class->method( $name => $self->can('items') )
404 }
405 elsif (my $item = $self->try( item => $name, @args )) {
406 0 return $item;
407 }
408 else {
409 1 my ($pkg, $file, $line) = caller;
410 1 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
411 1 die $self->message( bad_method => $name, $class, $file, $line ), "\n";
412 }
413  
414 # should be installed now
415 6 $self->$name(@args);
416 }
417  
418  
419 24 1;
420  
421 __END__
« lib/Badger/Debug.pm ↑ Summary lib/Badger/Base.pm »