Object/InsideOut/Dynamic.pm

filter: Statementstmt 73.4% 72 / 98 Branchbran 50.0% 22 / 44 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 62.9% 102 / 162 CC 29 SCAR 33.6
CC
29
Cov
64%
__ANON__
43.7
__ANON__
16.1
__ANON__
1.1
CRAP 28.9
« Object/InsideOut/Metadata.pm ↑ Summary Object/InsideOut/Chained.pm »
1 package Object::InsideOut; {
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 sub create_field
8 {
9 my ($GBL, $call, @args) = @_;
10 push(@{$$GBL{'export'}}, 'create_field');
11 if ($call eq 'create_field') {
12 $$GBL{'init'} = 1;
13 }
14  
15 # Dynamically create a new object field
16 *Object::InsideOut::create_field = sub
17 4 ▶ {
Subroutine __ANON__: called CC=11 SCAR=27.8
18 # Handle being called as a method or subroutine
19 4 ▶ if ($_[0] eq 'Object::InsideOut') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] eq "Object::InsideOut") 1 3 4
20 1 shift;
21 }
22  
23 4 my ($class, $field, @attrs) = @_;
24  
25 # Verify valid class
26 4 ▶ if (! $class->isa('Object::InsideOut')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->isa("Object::InsideOut")) 0 4 4
27 0 OIO::Args->die(
28 'message' => 'Not an Object::InsideOut class',
29 'Arg' => $class);
30 }
31  
32 # Check for valid field
33 4 ▶ if ($field !~ /^\s*[@%]\s*[a-zA-Z_]\w*\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($field =~ /^\s*[\@%]\s*[a-zA-Z_]\w*\s*$/) 0 4 4
34 0 OIO::Args->die(
35 'message' => 'Not an array or hash declaration',
36 'Arg' => $field);
37 }
38  
39 # Convert attributes to single string
40 4 my $attr;
41 4 ▶ if (@attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@attrs) { } 4 0 4
42 4 s/^\s*(.*?)\s*$/$1/ foreach @attrs;
43 4 $attr = join(',', @attrs);
44 4 $attr =~ s/[\r\n]/ /sg;
45 4 $attr =~ s/,\s*,/,/g;
46 4 $attr =~ s/\s*,\s*:/ :/g;
47 4 ▶ if ($attr !~ /^\s*:/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attr =~ /^\s*:/) 1 3 4
48 1 $attr = ":Field($attr)";
49 }
50 } else {
51 0 $attr = ':Field';
52 }
53  
54 # Create the declaration
55 4 my @errs;
56 0 ▶ local $SIG{'__WARN__'} = sub { push(@errs, @_); };
Subroutine __ANON__: not called CC=1 SCAR=1.2
57  
58 4 my $code = "package $class; my $field $attr;";
59 4 eval $code;
60 4 ▶ if (my $e = Exception::Class::Base->caught()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = "Exception::Class::Base"->caught) 0 4 4
61 0 die($e);
62 }
63 4 ▶ if ($@ || @errs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or @errs) 0 4 4
Condition33%1/3
$@ or @errs
l!l&&r!l&&!r
004
MC/DC0%0/2
$@ or @errs
$@ @errs
Truth table33%1/3
A or B
A= $@B= @errs
ABresult
1X1
011
000
64 0 ▶ my ($err) = split(/ at /, $@ || join(" | ", @errs));
Condition0%0/3
$@ || join(' | ', @errs)
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || join(' | ', @errs)
$@ join(' | ', @errs)
Truth table0%0/3
A || B
A= $@B= join(' | ', @errs)
ABresult
1X1
011
000
65 0 OIO::Code->die(
66 'message' => 'Failure creating field',
67 'Error' => $err,
68 'Code' => $code);
69 }
70  
71 # Invalidate object initialization activity cache
72 4 delete($$GBL{'cache'});
73  
74 # Process the declaration
75 4 process_fields();
76 };
77  
78  
79 # Runtime hierarchy building
80 *Object::InsideOut::add_class = sub
81 1 ▶ {
Subroutine __ANON__: called CC=19 SCAR=37.8
82 1 my $class = shift;
83 1 ▶ if (ref($class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 0 1 1
84 0 OIO::Method->die('message' => q/'add_class' called as an object method/);
85 }
86 1 ▶ if ($class eq 'Object::InsideOut') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "Object::InsideOut") 0 1 1
87 0 OIO::Method->die('message' => q/'add_class' called on non-class 'Object::InsideOut'/);
88 }
89 1 ▶ if (! $class->isa('Object::InsideOut')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->isa("Object::InsideOut")) 0 1 1
90 0 OIO::Method->die('message' => "'add_class' called on non-Object::InsideOut class '$class'");
91 }
92  
93 1 my $pkg = shift;
94 1 ▶ if (! $pkg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pkg) 0 1 1
95 0 OIO::Args->die(
96 'message' => 'Missing argument',
97 'Usage' => "$class\->add_class(\$class)");
98 }
99  
100 # Already in the hierarchy - ignore
101 1 ▶ return if ($class->isa($pkg));
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa($pkg) 0 1 1
102  
103 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
104  
105 # If no package symbols, then load it
106 1 ▶ if (! grep { $_ !~ /::$/ } keys(%{$pkg.'::'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {not $_ =~ /::$/;} keys %{$pkg . '::';}) 0 1 1
107 0 eval "require $pkg";
108 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
109 0 OIO::Code->die(
110 'message' => "Failure loading package '$pkg'",
111 'Error' => $@);
112 }
113 # Empty packages make no sense
114 0 ▶ if (! grep { $_ !~ /::$/ } keys(%{$pkg.'::'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {not $_ =~ /::$/;} keys %{$pkg . '::';}) 0 0 0
115 0 OIO::Code->die('message' => "Package '$pkg' is empty");
116 }
117 }
118  
119 # Import the package, if needed
120 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
121 0 eval { $pkg->import(@_); };
122 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
123 0 OIO::Code->die(
124 'message' => "Failure running 'import' on package '$pkg'",
125 'Error' => $@);
126 }
127 }
128  
129 1 my $tree_bu = $$GBL{'tree'}{'bu'};
130 1 my $tree_td = $$GBL{'tree'}{'td'};
131  
132 # Foreign class added
133 1 ▶ if (! exists($$tree_bu{$pkg})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $tree_bu->{$pkg}) 0 1 1
134 # Get inheritance 'classes' hash
135 0 ▶ if (! exists($$GBL{'heritage'}{$class})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $GBL->{"heritage"}{$class}) 0 0 0
136 0 create_heritage($class);
137 }
138 # Add package to inherited classes
139 0 $$GBL{'heritage'}{$class}{'cl'}{$pkg} = undef;
140 0 return;
141 }
142  
143 # Add to class trees
144 1 foreach my $cl (keys(%{$tree_bu})) {
145 3 ▶ next if (! grep { $_ eq $class } @{$$tree_bu{$cl}});
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $class;} @{$$tree_bu{$cl};} 1 2 3
146  
147 # Splice in the added class's tree
148 2 my @tree;
149 2 foreach (@{$$tree_bu{$cl}}) {
150 3 push(@tree, $_);
151 3 ▶ if ($_ eq $class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq $class) 2 1 3
152 2 my %seen;
153 2 @seen{@{$$tree_bu{$cl}}} = undef;
154 2 foreach (@{$$tree_bu{$pkg}}) {
155 2 ▶ push(@tree, $_) if (! exists($seen{$_}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $seen{$_} 2 0 2
156 }
157 }
158 }
159  
160 # Add to @ISA array
161 2 push(@{$cl.'::ISA'}, $pkg);
162  
163 # Save revised trees
164 2 $$tree_bu{$cl} = \@tree;
165 2 @{$$tree_td{$cl}} = reverse(@tree);
166 }
167 1 $$GBL{'asi'}{$pkg}{$class} = undef;
168 };
169  
170 # Invalidate object initialization activity cache
171 delete($$GBL{'cache'});
172  
173 # Do the original call
174 @_ = @args;
175 goto &$call;
176 }
177  
178 } # End of package's lexical scope
179  
180  
181 # Ensure correct versioning
182 4 ▶($Object::InsideOut::VERSION eq '4.05')
Condition50%1/2
$VERSION eq '4.05' || die("Version mismatch\n")
l!l
40
MC/DC0%0/1
$VERSION eq '4.05' || die("Version mismatch\n")
$VERSION eq '4.05'
Truth table50%1/2
A
A= $VERSION eq '4.05'
Aresult
11
00
183 or die("Version mismatch\n");
184  
185 # EOF
« Object/InsideOut/Metadata.pm ↑ Summary Object/InsideOut/Chained.pm »