Board/Traversable.pm

filter: Statementstmt 91.3% 53 / 58 Branchbran 85.0% 34 / 40 Conditioncond 75.0% 6 / 8 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 87.1% 102 / 117 CC 24 SCAR 24.7
CC
24
Cov
88%
_get_container_or_service
14.2
fetch
13.0
get_root_container
2.0
CRAP 11.8
« Board/Service/Inferred.pm ↑ Summary Board.pm »
1 package Bread::Board::Traversable;
2 81 our $AUTHORITY = 'cpan:STEVAN';
3 # ABSTRACT: role for traversing a container service tree
4 81 $Bread::Board::Traversable::VERSION = '0.37';
5 81 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 81 with 'MooseX::Clone' => { -version => 0.05 };
8  
9 81 has 'parent' => (
10 is => 'rw',
11 isa => 'Bread::Board::Traversable',
12 weak_ref => 1,
13 clearer => 'detach_from_parent',
14 predicate => 'has_parent',
15 );
16  
17 43 ▶sub get_root_container {
Subroutine get_root_container: called CC=2 SCAR=6.9
Pod documented
18 43 my $c = shift;
19 43 ▶ while ($c->has_parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->has_parent) 33 43 76
20 33 $c = $c->parent;
21 }
22 43 return $c;
23 }
24  
25 373 ▶sub fetch {
Subroutine fetch: called CC=13 SCAR=25.7
Pod documented
26 373 my ($self, $path) = @_;
27  
28 373 my $root;
29 373 ▶ if ($path =~ /^\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[^/]) { } 43 330 373
30 43 $root = $self->get_root_container;
31 }
32 else {
33 330 $root = $self;
34 330 ▶ while (!$root->isa('Bread::Board::Container')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($root->isa("Bread::Board::Container")) 228 330 558
35 228 $root = $root->parent;
36 }
37 }
38  
39 373 my @path = grep { $_ } split /\// => $path;
40  
41 373 ▶ if ($path[0] eq '..') {
Branch: 1 branch
BranchTrueFalseTotal
if ($path[0] eq "..") 14 359 373
42 14 my $c = $root;
43 14 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
defined $path[0] and $path[0] eq ".." and $c->has_parent and do { do { shift @path; $c = $c->parent || confess('Expected parent for ' . $c->name . ' but found none') } } 2 14 16
Condition83%5/6
defined $path[0] and $path[0] eq ".." and $c->has_parent
!ll&&!rl&&r
1402
defined $path[0] and $path[0] eq ".."
!ll&&!rl&&r
2122
MC/DC66%2/3
defined $path[0] and $path[0] eq ".." and $c->has_parent
defined $path[0] $path[0] eq ".." $c->has_parent
Truth table75%3/4
A and B and C
A= defined $path[0]B= $path[0] eq ".."C= $c->has_parent
ABCresult
0XX0
10X0
1100
1111
44 16 shift @path;
45 16 ▶ $c = $c->parent
Condition50%1/2
$c->parent || confess('Expected parent for ' . $c->name . ' but found none')
l!l
160
MC/DC0%0/1
$c->parent || confess('Expected parent for ' . $c->name . ' but found none')
$c->parent
Truth table50%1/2
A
A= $c->parent
Aresult
11
00
46 || confess "Expected parent for " . $c->name . " but found none";
47 } while (defined $path[0] && $path[0] eq '..' && $c->has_parent);
48 14 $root = $c;
49 }
50  
51 373 ▶ return $root unless @path;
Branch: 1 branch
BranchTrueFalseTotal
unless @path 2 371 373
52  
53 371 my $c = $root;
54 371 ▶ while (my $h = shift @path) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $h = shift @path) 467 368 835
55 467 $c = _get_container_or_service($c, $h);
56 }
57 368 ▶ if (!$self->isa('Bread::Board::Service::Alias')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->isa("Bread::Board::Service::Alias")) 345 23 368
58 345 my %seen;
59 345 ▶ while ($c->isa('Bread::Board::Service::Alias')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->isa("Bread::Board::Service::Alias")) 48 338 386
60 48 $c = $c->aliased_from;
61 47 ▶ confess "Cycle detected in aliases" if exists $seen{$c};
Branch: 1 branch
BranchTrueFalseTotal
if exists $seen{$c} 6 41 47
62 41 $seen{$c}++;
63 }
64 }
65 361 return $c;
66 }
67  
68 467 ▶sub _get_container_or_service {
Subroutine _get_container_or_service: called CC=11 SCAR=26.5
69 467 my ($c, $name) = @_;
70  
71 467 ▶ (blessed $c)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($c) or confess("Expected object, got $c") 467 0 467
72 || confess "Expected object, got $c";
73  
74 467 ▶ if ($c->isa('Bread::Board::Dependency')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->isa("Bread::Board::Dependency")) 0 467 467
75 # make sure to evaluate this from the parent
76 0 return _get_container_or_service($c->parent->parent, $name);
77 }
78  
79 467 ▶ if ($c->does('Bread::Board::Service::WithDependencies')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->does("Bread::Board::Service::WithDependencies")) 35 432 467
80 35 ▶ return $c->get_dependency($name) if $c->has_dependency($name);
Branch: 1 branch
BranchTrueFalseTotal
if $c->has_dependency($name) 35 0 35
81 0 confess "Could not find dependency ($name) from service " . $c->name;
82 }
83  
84 # name() is implemented in Service and Container
85 # get_sub_container and get_service is implemented in Container
86 # there must be a better way to do this
87  
88 432 ▶ if ($c->does('Bread::Board::Service')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c->does('Bread::Board::Service')) { } 0 432 432
elsif ($c->isa('Bread::Board::Container')) { } 431 1 432
89 0 ▶ if ($c->name eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->name eq $name) 0 0 0
90 0 warn "Traversing into the current service ($name) is deprecated."
91 . " You should remove the $name component from the path.";
92 0 return $c;
93 }
94 }
95 elsif ($c->isa('Bread::Board::Container')) {
96 431 ▶ if ($c->name eq $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->name eq $name) 1 430 431
97 1 warn "Traversing into the current container ($name) is deprecated;"
98 . " you should remove the $name component from the path";
99 1 return $c;
100 }
101 430 ▶ return $c->get_sub_container($name) if $c->has_sub_container($name);
Branch: 1 branch
BranchTrueFalseTotal
if $c->has_sub_container($name) 85 345 430
102 345 ▶ return $c->get_service($name) if $c->has_service($name);
Branch: 1 branch
BranchTrueFalseTotal
if $c->has_service($name) 343 2 345
103 }
104  
105 3 confess "Could not find container or service for $name in " . $c->name;
106 }
107  
108 81 ▶no Moose::Role; 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 __END__
« Board/Service/Inferred.pm ↑ Summary Board.pm »