Set/Union.pm

filter: Statementstmt 77.2% 34 / 44 Branchbran 50.0% 7 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 5 / 5 totaltotal 74.2% 52 / 70 CC 13 SCAR 19.8
CC
13
Cov
71%
has_property
20.0
get_property
6.0
_lookup_parents
3.1
CRAP 7.3
↑ Summary Set/Manager.pm »
1 package Context::Set::Union;
2 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 4 extends qw/Context::Set/;
5  
6 4 has 'contexts' => ( is => 'ro' , isa => 'ArrayRef[Context::Set]' , required => 1);
7  
8 =head2 name
9  
10 Dies all the time. Using name makes no sense on a Context::Set::Union
11  
12 =cut
13  
14 12 ▶sub name{
Subroutine name: called CC=1 SCAR=0.0
Pod documented
15 12 my ($self) = @_;
16 12 return;
17 }
18  
19 =head1 NAME
20  
21 Context::Set::Union - A union of Contexts.
22  
23 =cut
24  
25 =head2 fullname
26  
27 See superclass.
28  
29 =cut
30  
31 41 ▶sub fullname{
Subroutine fullname: called CC=1 SCAR=0.0
Pod documented
32 41 my ($self) = @_;
33 41 return 'union('.join(',', map{ $_->fullname() } @{$self->contexts} ).')';
34 }
35  
36 =head2 is_inside
37  
38 Only operates on the parent context in order.
39  
40 =cut
41  
42 3 ▶sub is_inside{
Subroutine is_inside: called CC=3 SCAR=11.1
Pod documented
43 3 my ($self,$name) = @_;
44  
45 3 foreach my $context ( @{$self->contexts()} ){
46 3 ▶ if( $context->is_inside($name) ){
Branch: 1 branch
BranchTrueFalseTotal
if ($context->is_inside($name)) 3 0 3
47 3 return 1;
48 }
49 }
50 }
51  
52 =head2 has_property
53  
54 See superclass Context::Set.
55  
56 =cut
57  
58 0 ▶sub has_property{
Subroutine has_property: not called CC=4 SCAR=30.0
Pod documented
59 0 my ($self, $prop_name) = @_;
60 0 ▶ if( exists $self->properties()->{$prop_name} ){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->properties->{$prop_name}) 0 0 0
61 0 return 1;
62 }
63 ## Try to hit the property in the contexts.
64 0 foreach my $context ( @{$self->contexts()} ){
65 0 ▶ if( $context->has_property($prop_name) ){
Branch: 1 branch
BranchTrueFalseTotal
if ($context->has_property($prop_name)) 0 0 0
66 0 return 1;
67 }
68 }
69 ## No hit, that's a no
70 0 return 0;
71 }
72  
73  
74 =head2 get_property
75  
76 See Super Class.
77  
78 =cut
79  
80 17 ▶sub get_property{
Subroutine get_property: called CC=6 SCAR=18.0
Pod documented
81 17 my ($self, $prop_name) = @_;
82 17 ▶ if( exists $self->properties()->{$prop_name} ){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->properties->{$prop_name}) 4 13 17
83 4 return $self->properties()->{$prop_name};
84 }
85  
86 ## Make a fist loop through the lower level properties only of
87 ## the contexts.
88 13 foreach my $context ( @{$self->contexts()} ){
89 22 ▶ if( exists $context->properties()->{$prop_name} ){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $context->properties->{$prop_name}) 7 15 22
90 7 return $context->properties()->{$prop_name};
91 }
92 }
93  
94 ## No direct properties found, try to find
95 ## properties in general.
96 ## This will try to go up each context if necessary
97 6 foreach my $context ( @{$self->contexts()} ){
98 6 ▶ if( $context->has_property($prop_name) ){
Branch: 1 branch
BranchTrueFalseTotal
if ($context->has_property($prop_name)) 6 0 6
99 6 return $context->get_property($prop_name);
100 }
101 }
102 0 confess("Cannot find property $prop_name anywhere in ".$self->fullname());
103 }
104  
105 1 ▶sub _lookup_parents{
Subroutine _lookup_parents: called CC=3 SCAR=11.4
106 1 my ($self,$pname) = @_;
107 1 foreach my $context ( @{$self->contexts()} ){
108 1 ▶ if( my $hit = $context->lookup($pname) ){
Branch: 1 branch
BranchTrueFalseTotal
if (my $hit = $context->lookup($pname)) 1 0 1
109 1 return $hit;
110 }
111 }
112 0 return undef;
113 }
114  
115 4 __PACKAGE__->meta->make_immutable();
116 4 1;
↑ Summary Set/Manager.pm »