IOC/Visitor/ServiceLocator.pm

filter: Statementstmt 100% 50 / 50 Branchbran 100% 14 / 14 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 95.2% 80 / 84 CC 12 SCAR 18.0
CC
12
Cov
97%
visit
10.0
new
3.1
BEGIN
1.0
CRAP 6.1
↑ Summary IOC/Service.pm »
1  
2 package IOC::Visitor::ServiceLocator;
3  
4 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 23 our $VERSION = '0.02';
8  
9 23 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 23 ▶use IOC::Interfaces;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 23 ▶use IOC::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 23 ▶use base 'IOC::Visitor';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 32 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod documented
17 32 my ($_class, $path, $extra_args) = @_;
18 32 ▶ ($path)
Branch: 1 branch
BranchTrueFalseTotal
$path or "IOC::InsufficientArguments"->throw("You must provide an path to locate a container") 31 1 32
19 || throw IOC::InsufficientArguments "You must provide an path to locate a container";
20 31 ▶ my $class = ref($_class) || $_class;
Condition33%1/3
ref $_class || $_class
l!l&&r!l&&!r
0310
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 31 my $visitor = {
22 path => $path,
23 extra_args => $extra_args
24 };
25 31 bless($visitor, $class);
26 31 return $visitor;
27 }
28  
29 34 ▶sub visit {
Subroutine visit: called CC=10 SCAR=23.0
Pod documented
30 34 my ($self, $container) = @_;
31 34 ▶ (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 as a sub-container") 30 4 34
Condition100%3/3
builtin::blessed($container) and $container->isa("IOC::Container")
!ll&&!rl&&r
3130
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
32 || throw IOC::InsufficientArguments "You must provide an IOC::Container object as a sub-container";
33 30 my $service;
34 30 ▶ my @extra_args = (defined $self->{extra_args} ? @{$self->{extra_args}} : ());
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'extra_args'} ? : 17 13 30
35 30 my @path = grep { $_ } split /\// => $self->{path};
36 30 my $service_name = pop @path;
37 30 ▶ if ($self->{path} =~ /^\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'path'} =~ m[^/]) { } 8 22 30
38 # start at the root
39 8 my $current = $container->findRootContainer();
40 8 foreach my $container_name (@path) {
41 11 eval {
42 11 $current = $current->getSubContainer($container_name);
43 };
44 11 ▶ throw IOC::UnableToLocateService "Could not locate the service at path '" . $self->{path} . "' failed at '$container_name'", $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 10 11
45 }
46 7 $service = $current->get($service_name, @extra_args);
47 }
48 else {
49 22 my $current = $container;
50 22 foreach my $container_name (@path) {
51 12 ▶ if ($container_name eq '..') {
Branch: 1 branch
BranchTrueFalseTotal
if ($container_name eq '..') { } 4 8 12
52 4 $current = $current->getParentContainer();
53 }
54 else {
55 8 eval {
56 8 $current = $current->getSubContainer($container_name);
57 };
58 8 ▶ throw IOC::UnableToLocateService "Could not locate the service at path '" . $self->{path} . "' failed at '$container_name'", $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 7 8
59 }
60 }
61 21 $service = $current->get($service_name, @extra_args);
62 }
63 27 return $service;
64 }
65  
66 23 1;
67  
68 __END__
↑ Summary IOC/Service.pm »