IOC/Visitor/SearchForContainer.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 8 / 8 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 93.8% 61 / 65 CC 8 SCAR 9.2
CC
8
Cov
96%
_recursiveSearch
4.0
new
3.1
visit
3.0
CRAP 2.5
« Test/IOC.pm ↑ Summary IOC/Container/MethodResolution.pm »
1  
2 package IOC::Visitor::SearchForContainer;
3  
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 our $VERSION = '0.03';
8  
9 12 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 12 ▶use IOC::Interfaces;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use IOC::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 12 ▶use base 'IOC::Visitor';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 6 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod documented
17 6 my ($_class, $container_name) = @_;
18 6 ▶ ($container_name)
Branch: 1 branch
BranchTrueFalseTotal
$container_name or "IOC::InsufficientArguments"->throw("You must provide a name of a container to find") 5 1 6
19 || throw IOC::InsufficientArguments "You must provide a name of a container to find";
20 5 ▶ my $class = ref($_class) || $_class;
Condition33%1/3
ref $_class || $_class
l!l&&r!l&&!r
050
MC/DC0%0/2
ref $_class || $_class
ref $_class $_class
Truth table33%1/3
A || B
A= ref $_classB= $_class
ABresult
1X1
011
000
21 5 my $visitor = {
22 container_to_find => $container_name
23 };
24 5 bless($visitor, $class);
25 5 return $visitor;
26 }
27  
28 8 ▶sub visit {
Subroutine visit: called CC=3 SCAR=11.0
Pod documented
29 8 my ($self, $container) = @_;
30 8 ▶ (blessed($container) && $container->isa('IOC::Container'))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($container) and $container->isa("IOC::Container") or "IOC::InsufficientArguments"->throw("You must provide an IOC::Container object to search") 4 4 8
Condition100%3/3
builtin::blessed($container) and $container->isa("IOC::Container")
!ll&&!rl&&r
314
MC/DC100%2/2
builtin::blessed($container) and $container->isa("IOC::Container")
builtin::blessed($container) $container->isa("IOC::Container")
Truth table100%3/3
A and B
A= builtin::blessed($container)B= $container->isa("IOC::Container")
ABresult
0X0
100
111
31 || throw IOC::InsufficientArguments "You must provide an IOC::Container object to search";
32 4 my $container_to_find = $self->{container_to_find};
33 4 return $self->_recursiveSearch($container, $container_to_find);
34 }
35  
36 6 ▶sub _recursiveSearch {
Subroutine _recursiveSearch: called CC=4 SCAR=13.9
37 6 my ($self, $container, $container_to_find) = @_;
38 # if we have it stored, then return it
39 6 ▶ return $container->getSubContainer($container_to_find)
Branch: 1 branch
BranchTrueFalseTotal
if $container->hasSubContainer($container_to_find) 1 5 6
40 if $container->hasSubContainer($container_to_find);
41 # otherwise, loop through all the sub-containers
42 # sort the names too, which will make sure the
43 # search will roughly take the same amount of time
44 # each time we do it, otherwise we are at the
45 # mercy of the hash ordering
46 5 foreach my $sub_container_name (sort $container->getSubContainerList()) {
47 # otherwise we need to search the next level
48 8 my $sub_container = $container->getSubContainer($sub_container_name);
49 8 ▶ $self->_recursiveSearch($sub_container, $container_to_find)
Branch: 1 branch
BranchTrueFalseTotal
if $sub_container->hasSubContainers 2 6 8
50 if $sub_container->hasSubContainers();
51 }
52 5 return undef;
53 }
54  
55 12 1;
56  
57 __END__
« Test/IOC.pm ↑ Summary IOC/Container/MethodResolution.pm »