Object/MixIn.pm

filter: Statementstmt 79.7% 63 / 79 Branchbran 60.4% 29 / 48 Conditioncond 38.8% 14 / 36 MC/DCmcdc 16.6% 3 / 18 Subroutinesub 100% 10 / 10 Podpod 40.0% 2 / 5 totaltotal 61.7% 121 / 196 CC 41 SCAR 32.7
CC
41
Cov
65%
pre_import_hook
49.6
import
29.7
export_tag
14.5
CRAP 26.3
« Object/MakeMethods/DateTime.pm ↑ Summary Class/MakeMethods/Generic.pm »
1 package Rose::Object::MixIn;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $Debug = 0;
8  
9 1 our $VERSION = '0.856';
10  
11 use Rose::Class::MakeMethods::Set
12 1 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 inheritable_set =>
14 [
15 '_export_tag' =>
16 {
17 list_method => '_export_tags',
18 clear_method => 'clear_export_tags',
19 add_method => '_add_export_tag',
20 delete_method => 'delete_export_tag',
21 deletes_method => 'delete_export_tags',
22 },
23  
24 '_pre_import_hook',
25 {
26 clear_method => 'clear_pre_import_hooks',
27 add_method => 'add_pre_import_hook',
28 adds_method => 'add_pre_import_hooks',
29 delete_method => 'delete_pre_import_hook',
30 deletes_method => 'delete_pre_import_hooks',
31 },
32 ],
33 1 );
34  
35 sub import
36 3 ▶{
Subroutine import: called CC=19 SCAR=33.9
37 3 my($class) = shift;
38  
39 3 my $target_class = (caller)[0];
40  
41 3 my($force, @methods, %import_as);
42  
43 3 foreach my $arg (@_)
44 {
45 7 ▶ if(!defined $target_class && $arg !~ /^-/)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $target_class or $arg =~ /^-/) 1 6 7
Condition66%2/3
defined $target_class or $arg =~ /^-/
l!l&&r!l&&!r
601
MC/DC50%1/2
defined $target_class or $arg =~ /^-/
defined $target_class $arg =~ /^-/
Truth table66%2/3
A or B
A= defined $target_classB= $arg =~ /^-/
ABresult
1X1
011
000
46 {
47 1 $target_class = $arg;
48 1 next;
49 }
50  
51 6 ▶ if($arg =~ /^-?-force$/)
Branch: 4 branches
BranchTrueFalseTotal
if ($arg =~ /^-?-force$/) { } 0 6 6
elsif ($arg =~ /^-?-target[-_]class$/) { } 1 5 6
elsif ($arg =~ /^:(.+)/) { } 1 4 5
elsif (ref $arg eq 'HASH') { } 2 2 4
52 {
53 0 $force = 1;
54 }
55 elsif($arg =~ /^-?-target[-_]class$/)
56 {
57 1 $target_class = undef; # set on next iteration...lame
58 1 next;
59 }
60 elsif($arg =~ /^:(.+)/)
61 {
62 1 ▶ my $methods = $class->export_tag($1) or
Branch: 1 branch
BranchTrueFalseTotal
my $methods = $class->export_tag($1) or croak("Unknown export tag - '${arg}'") 1 0 1
63 croak "Unknown export tag - '$arg'";
64  
65 1 push(@methods, @$methods);
66 }
67 elsif(ref $arg eq 'HASH')
68 {
69 2 ▶ while(my($method, $name) = each(%$arg))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$arg) 2 2 4
70 {
71 2 push(@methods, $method);
72 2 $import_as{$method} = $name;
73 }
74 }
75 else
76 {
77 2 push(@methods, $arg);
78 }
79 }
80  
81 3 foreach my $method (@methods)
82 {
83 5 ▶ my $code = $class->can($method) or
Branch: 1 branch
BranchTrueFalseTotal
my $code = $class->can($method) or croak("Could not import method '${method}' from $class - no such method") 5 0 5
84 croak "Could not import method '$method' from $class - no such method";
85  
86 5 ▶ my $import_as = $import_as{$method} || $method;
Condition66%2/3
$import_as{$method} || $method
l!l&&r!l&&!r
230
MC/DC0%0/2
$import_as{$method} || $method
$import_as{$method} $method
Truth table66%2/3
A || B
A= $import_as{$method}B= $method
ABresult
1X1
011
000
87  
88 5 ▶ if($target_class->can($import_as) && !$force)
Branch: 1 branch
BranchTrueFalseTotal
if ($target_class->can($import_as) and not $force) 0 5 5
Condition33%1/3
$target_class->can($import_as) and not $force
!ll&&!rl&&r
500
MC/DC0%0/2
$target_class->can($import_as) and not $force
$target_class->can($import_as) not $force
Truth table33%1/3
A and not(B)
A= $target_class->can($import_as)B= not $force
ABresult
0X0
100
111
89 {
90 0 croak "Could not import method '$import_as' from $class into ",
91 "$target_class - a method by that name already exists. ",
92 "Pass a '-force' argument to import() to override ",
93 "existing methods."
94 }
95  
96 5 ▶ if(my $hooks = $class->pre_import_hooks($method))
Branch: 1 branch
BranchTrueFalseTotal
if (my $hooks = $class->pre_import_hooks($method)) 5 0 5
97 {
98 5 foreach my $code (@$hooks)
99 {
100 0 my $error;
101  
102 TRY:
103 {
104 0 local $@;
105 0 eval { $code->($class, $method, $target_class, $import_as) };
106 0 $error = $@;
107 }
108  
109 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
110 {
111 0 croak "Could not import method '$import_as' from $class into ",
112 "$target_class - $error";
113 }
114 }
115 }
116  
117 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
118 5 ▶ $Debug && warn "${target_class}::$import_as = ${class}->$method\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::Object::MixIn::Debug and warn "${target_class}::$import_as = $class->$method\n" 0 5 5
119 5 *{$target_class . '::' . $import_as} = $code;
120 }
121 }
122  
123 sub export_tag
124 4 ▶{
Subroutine export_tag: called CC=10 SCAR=26.7
Pod documented
125 4 my($class, $tag) = (shift, shift);
126  
127 4 ▶ if(index($tag, ':') == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (index($tag, ":") == 0) 0 4 4
128 {
129 0 croak 'Tag name arguments to export_tag() should not begin with ":"';
130 }
131  
132 4 ▶ if(@_ && !$class->_export_tag_value($tag))
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and not $class->_export_tag_value($tag)) 3 1 4
Condition66%2/3
@_ and not $class->_export_tag_value($tag)
!ll&&!rl&&r
103
MC/DC50%1/2
@_ and not $class->_export_tag_value($tag)
@_ not $class->_export_tag_value($tag)
Truth table66%2/3
A and not(B)
A= @_B= not $class->_export_tag_value($tag)
ABresult
0X0
100
111
133 {
134 3 $class->_add_export_tag($tag);
135 }
136  
137 4 ▶ if(@_ && (@_ > 1 || (ref $_[0] || '') ne 'ARRAY'))
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and @_ > 1 || (ref $_[0] || "") ne "ARRAY") 0 4 4
Condition50%4/8
@_ and @_ > 1 || (ref $_[0] || "") ne "ARRAY"
!ll&&!rl&&r
130
@_ > 1 or (ref $_[0] || "") ne "ARRAY"
l!l&&r!l&&!r
003
ref $_[0] || ''
l!l
30
MC/DC33%1/3
@_ and @_ > 1 || (ref $_[0] || "") ne "ARRAY"
@_ @_ > 1 ref $_[0]
Truth table50%2/4
A and B or C
A= @_B= @_ > 1C= ref $_[0]
ABCresult
0XX0
1000
11X1
1011
138 {
139 0 croak 'export_tag() expects either a single tag name argument, ',
140 'or a tag name and a reference to an array of method names';
141 }
142  
143 4 my $ret = $class->_export_tag_value($tag, @_);
144  
145 4 ▶ croak "No such tag: $tag" unless($ret);
Branch: 1 branch
BranchTrueFalseTotal
unless $ret 0 4 4
146  
147 4 ▶ return wantarray ? @$ret : $ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
148 }
149  
150 sub export_tags
151 2 ▶{
Subroutine export_tags: called CC=2 SCAR=7.0
Pod documented
152 2 my($class) = shift;
153 2 ▶ return $class->_export_tags unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 2 2
154 2 $class->clear_export_tags;
155 2 $class->add_export_tags(@_);
156 }
157  
158 sub add_export_tags
159 2 ▶{
Subroutine add_export_tags: called CC=2 SCAR=6.9
Pod undocumented
160 2 my($class) = shift;
161  
162 2 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 2 5
163 {
164 3 my($tag, $arg) = (shift, shift);
165 3 $class->export_tag($tag, $arg);
166 }
167 }
168  
169 sub pre_import_hook
170 5 ▶{
Subroutine pre_import_hook: called CC=12 SCAR=39.0
Pod undocumented
171 5 my($class, $method) = (shift, shift);
172  
173 5 ▶ if(@_ && !$class->_pre_import_hook_value($method))
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and not $class->_pre_import_hook_value($method)) 0 5 5
Condition33%1/3
@_ and not $class->_pre_import_hook_value($method)
!ll&&!rl&&r
500
MC/DC0%0/2
@_ and not $class->_pre_import_hook_value($method)
@_ not $class->_pre_import_hook_value($method)
Truth table33%1/3
A and not(B)
A= @_B= not $class->_pre_import_hook_value($method)
ABresult
0X0
100
111
174 {
175 0 $class->add_pre_import_hook($method);
176 }
177  
178 5 ▶ if(@_ && (@_ > 1 || (ref $_[0] && (ref $_[0] || '') !~ /\A(?:ARRAY|CODE)\z/)))
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and @_ > 1 || ref $_[0] && !((ref $_[0] || "") =~ /\A(?:ARRAY|CODE)\z/)) 0 5 5
Condition9%1/11
@_ and @_ > 1 || ref $_[0] && !((ref $_[0] || "") =~ /\A(?:ARRAY|CODE)\z/)
!ll&&!rl&&r
500
@_ > 1 or ref $_[0] and not +(ref $_[0] || "") =~ /\A(?:ARRAY|CODE)\z/
l!l&&r!l&&!r
000
ref $_[0] and not +(ref $_[0] || "") =~ /\A(?:ARRAY|CODE)\z/
!ll&&!rl&&r
000
ref $_[0] || ''
l!l
00
MC/DC0%0/4
@_ and @_ > 1 || ref $_[0] && !((ref $_[0] || "") =~ /\A(?:ARRAY|CODE)\z/)
@_ @_ > 1 ref $_[0] ref $_[0]
Truth table20%1/5
A and B or C and not(D)
A= @_B= @_ > 1C= ref $_[0]D= ref $_[0]
ABCDresult
0XXX0
100X0
10110
11XX1
10101
179 {
180 0 croak 'pre_import_hook() expects either a single method name argument, ',
181 'or a method name and a code reference or a reference to an array ',
182 'of code references';
183 }
184  
185 5 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 5 5
186 {
187 0 ▶ unless(ref $_[0] eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_[0] eq "ARRAY") 0 0 0
188 {
189 0 $_[0] = [ $_[0] ];
190 }
191 }
192  
193 5 ▶ my $ret = $class->_pre_import_hook_value($method, @_) || [];
Condition50%1/2
$class->_pre_import_hook_value($method, @_) || []
l!l
05
MC/DC0%0/1
$class->_pre_import_hook_value($method, @_) || []
$class->_pre_import_hook_value($method, @_)
Truth table50%1/2
A
A= $class->_pre_import_hook_value($method, @_)
Aresult
11
00
194  
195 5 ▶ return wantarray ? @$ret : $ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 5 5
196 }
197  
198 5 ▶sub pre_import_hooks { shift->pre_import_hook(shift) }
Subroutine pre_import_hooks: called CC=1 SCAR=0.0
Pod undocumented
199  
200 1 1;
201  
202 __END__
« Object/MakeMethods/DateTime.pm ↑ Summary Class/MakeMethods/Generic.pm »