blib/lib/Rose/HTML/Object/Exporter.pm

filter: Statementstmt 69.7% 67 / 96 Branchbran 43.7% 21 / 48 Conditioncond 26.6% 12 / 45 MC/DCmcdc 4.7% 1 / 21 Subroutinesub 85.7% 12 / 14 Podpod 0.0% 0 / 6 totaltotal 49.1% 113 / 230 CC 44 SCAR 38.8
CC
44
Cov
53%
import
84.5
pre_import_hook
38.1
export_tag
18.2
CRAP 48.2
↑ Summary blib/lib/Rose/HTML/Form/Field/Time/Hours.pm »
1 package Rose::HTML::Object::Exporter;
2  
3 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 47 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 47 our $VERSION = '0.605';
8  
9 47 our $Debug = 0;
10  
11 use Rose::Class::MakeMethods::Generic
12 47 ▶(
Subroutine BEGIN: called CC=1 SCAR=0.0
13 47 inheritable_hash =>
14 [
15 export_tags => { interface => 'get_set_all', hash_key => 'export_tags' },
16 _export_tag => { interface => 'get_set', hash_key => 'export_tags' },
17 clear_export_tags => { interface => 'clear', hash_key => 'export_tags' },
18 delete_export_tags => { interface => 'delete', hash_key => 'export_tags' },
19  
20 _pre_import_hooks => { interface => 'get_set_all', hash_key => 'pre_import_hooks' },
21 _pre_import_hook => { interface => 'get_set', hash_key => 'pre_import_hooks' },
22 clear_pre_import_hooks => { interface => 'clear', hash_key => 'pre_import_hooks' },
23 delete_pre_import_hooks => { interface => 'delete', hash_key => 'pre_import_hooks' },
24 ],
25 47 );
26  
27 47 our %Imported;
28  
29 sub imported
30 3763 ▶{
Subroutine imported: called CC=2 SCAR=7.6
Pod undocumented
31 3763 my($class, $symbol) = (shift, shift);
32  
33 3763 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 3763 3763
34 {
35 0 return $Imported{$class}{$symbol}{'from'} = shift;
36 }
37  
38 3763 return $Imported{$class}{$symbol};
39 }
40  
41 47 our $Target_Class;
42  
43 sub import
44 332 ▶{
Subroutine import: called CC=26 SCAR=44.4
45 332 my($class) = shift;
46  
47 332 ▶ my $target_class = $Target_Class || (caller)[0];
Condition33%1/3
$Rose::HTML::Object::Exporter::Target_Class || (caller)[0]
l!l&&r!l&&!r
33200
MC/DC0%0/2
$Rose::HTML::Object::Exporter::Target_Class || (caller)[0]
$Rose::HTML::Object::Exporter::Target_Class (caller)[0]
Truth table33%1/3
A || B
A= $Rose::HTML::Object::Exporter::Target_ClassB= (caller)[0]
ABresult
1X1
011
000
48  
49 332 my($force, @symbols, %import_as, $imported);
50  
51 332 foreach my $arg (@_)
52 {
53 344 ▶ if($arg =~ /^-?-force$/)
Branch: 3 branches
BranchTrueFalseTotal
if ($arg =~ /^-?-force$/) { } 0 344 344
elsif ($arg =~ /^:(.+)/) { } 232 112 344
elsif (ref $arg eq 'HASH') { } 0 112 112
54 {
55 0 $force = 1;
56 }
57 elsif($arg =~ /^:(.+)/)
58 {
59 232 ▶ my $symbols = $class->export_tag($1) or
Branch: 1 branch
BranchTrueFalseTotal
my $symbols = $class->export_tag($1) or croak("Unknown export tag - '${arg}'") 232 0 232
60 croak "Unknown export tag - '$arg'";
61  
62 232 push(@symbols, @$symbols);
63 }
64 elsif(ref $arg eq 'HASH')
65 {
66 0 ▶ while(my($symbol, $name) = each(%$arg))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$arg) 0 0 0
67 {
68 0 push(@symbols, $symbol);
69 0 $import_as{$symbol} = $name;
70 }
71 }
72 else
73 {
74 112 push(@symbols, $arg);
75 }
76 }
77  
78 332 foreach my $symbol (@symbols)
79 {
80 2831 ▶ my $code = $class->can($symbol) or
Branch: 1 branch
BranchTrueFalseTotal
my $code = $class->can($symbol) or croak("Could not import symbol '${symbol}' from $class into $target_class - no such symbol") 2831 0 2831
81 croak "Could not import symbol '$symbol' from $class into $target_class - no such symbol";
82  
83 2831 ▶ my $is_constant = (defined prototype($code) && !length(prototype($code))) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined prototype $code && !length(prototype $code) ? : 2831 0 2831
Condition33%1/3
defined prototype $code and not length prototype $code
!ll&&!rl&&r
002831
MC/DC0%0/2
defined prototype $code and not length prototype $code
defined prototype $code not length prototype $code
Truth table33%1/3
A and not(B)
A= defined prototype $codeB= not length prototype $code
ABresult
0X0
100
111
84  
85 2831 ▶ my $import_as = $import_as{$symbol} || $symbol;
Condition33%1/3
$import_as{$symbol} || $symbol
l!l&&r!l&&!r
028310
MC/DC0%0/2
$import_as{$symbol} || $symbol
$import_as{$symbol} $symbol
Truth table33%1/3
A || B
A= $import_as{$symbol}B= $symbol
ABresult
1X1
011
000
86  
87 2831 my $existing_code = $target_class->can($import_as);
88  
89 47 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
90 47 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 2831 ▶ if($existing_code && !$force && (
Branch: 1 branch
BranchTrueFalseTotal
if ($existing_code and not $force and $is_constant && $existing_code eq \&{"${target_class}::$import_as";} || !$is_constant && $existing_code) 299 2532 2831
Condition50%6/12
$existing_code and not $force and $is_constant && $existing_code eq \&{"${target_class}::$import_as";} || !$is_constant && $existing_code
!ll&&!rl&&r
25320299
$existing_code and not $force
!ll&&!rl&&r
25320299
$is_constant and $existing_code eq \&{"${target_class}::$import_as";} or not $is_constant and $existing_code
l!l&&r!l&&!r
29900
$is_constant and $existing_code eq \&{"${target_class}::$import_as";}
!ll&&!rl&&r
00299
MC/DC20%1/5
$existing_code and not $force and $is_constant && $existing_code eq \&{"${target_class}::$import_as";} || !$is_constant && $existing_code
$existing_code not $force $is_constant $existing_code eq \&{"${target_class}::$import_as";} not $is_constant and $existing_code
Truth table28%2/7
A and not(B) and C and D or E
A= $existing_codeB= not $forceC= $is_constantD= $existing_code eq \&{"${target_class}::$import_as";}E= not $is_constant and $existing_code
ABCDEresult
0XXXX0
10XXX0
110X00
111000
1111X1
110X11
111011
93 299 ▶ ($is_constant && $existing_code eq \&{"${target_class}::$import_as"}) ||
Condition0%0/3
not $is_constant and $existing_code
!ll&&!rl&&r
000
MC/DC0%0/2
not $is_constant and $existing_code
not $is_constant $existing_code
Truth table0%0/3
not(A) and B
A= not $is_constantB= $existing_code
ABresult
0X0
100
111
94 (!$is_constant && $existing_code)))
95 {
96 299 ▶ next if($Imported{$target_class}{$import_as});
Branch: 1 branch
BranchTrueFalseTotal
if $Rose::HTML::Object::Exporter::Imported{$target_class}{$import_as} 299 0 299
97  
98 0 croak "Could not import symbol '$import_as' from $class into ",
99 "$target_class - a symbol by that name already exists. ",
100 "Pass a '--force' argument to import() to override ",
101 "existing symbols."
102 }
103  
104 2532 ▶ if(my $hooks = $class->pre_import_hooks($symbol))
Branch: 1 branch
BranchTrueFalseTotal
if (my $hooks = $class->pre_import_hooks($symbol)) 2532 0 2532
105 {
106 2532 foreach my $code (@$hooks)
107 {
108 0 my $error;
109  
110 TRY:
111 {
112 0 local $@;
113 0 eval { $code->($class, $symbol, $target_class, $import_as) };
114 0 $error = $@;
115 }
116  
117 0 ▶ if($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
118 {
119 0 croak "Could not import symbol '$import_as' from $class into ",
120 "$target_class - $error";
121 }
122 }
123 }
124  
125 2532 ▶ if($is_constant)
Branch: 1 branch
BranchTrueFalseTotal
if ($is_constant) { } 2532 0 2532
126 {
127 47 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
128 2532 ▶ $Debug && warn "${target_class}::$import_as = ${class}::$symbol\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Object::Exporter::Debug and warn "${target_class}::$import_as = ${class}::$symbol\n" 0 2532 2532
129 2532 *{$target_class . '::' . $import_as} = *{"${class}::$symbol"};
130 }
131 else
132 {
133 47 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
134 0 ▶ $Debug && warn "${target_class}::$import_as = ${class}->$symbol\n";
Branch: 1 branch
BranchTrueFalseTotal
$Rose::HTML::Object::Exporter::Debug and warn "${target_class}::$import_as = $class->$symbol\n" 0 0 0
135 0 *{$target_class . '::' . $import_as} = $code;
136 }
137  
138 2532 $Imported{$target_class}{$import_as}{'from'} = $class;
139 }
140 }
141  
142 sub export_tag
143 232 ▶{
Subroutine export_tag: called CC=8 SCAR=29.0
Pod undocumented
144 232 my($class, $tag) = (shift, shift);
145  
146 232 ▶ if(index($tag, ':') == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (index($tag, ":") == 0) 0 232 232
147 {
148 0 croak 'Tag name arguments to export_tag() should not begin with ":"';
149 }
150  
151 232 ▶ if(@_ && (@_ > 1 || (ref $_[0] || '') ne 'ARRAY'))
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and @_ > 1 || (ref $_[0] || "") ne "ARRAY") 0 232 232
Condition12%1/8
@_ and @_ > 1 || (ref $_[0] || "") ne "ARRAY"
!ll&&!rl&&r
23200
@_ > 1 or (ref $_[0] || "") ne "ARRAY"
l!l&&r!l&&!r
000
ref $_[0] || ''
l!l
00
MC/DC0%0/3
@_ and @_ > 1 || (ref $_[0] || "") ne "ARRAY"
@_ @_ > 1 ref $_[0]
Truth table25%1/4
A and B or C
A= @_B= @_ > 1C= ref $_[0]
ABCresult
0XX0
1000
11X1
1011
152 {
153 0 croak 'export_tag() expects either a single tag name argument, ',
154 'or a tag name and a reference to an array of symbol names';
155 }
156  
157 232 my $ret = $class->_export_tag($tag, @_);
158  
159 232 ▶ croak "No such tag: $tag" unless($ret);
Branch: 1 branch
BranchTrueFalseTotal
unless $ret 0 232 232
160  
161 232 ▶ return wantarray ? @$ret : $ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 232 232
162 }
163  
164 sub add_export_tags
165 0 ▶{
Subroutine add_export_tags: not called CC=2 SCAR=17.9
Pod undocumented
166 0 my($class) = shift;
167  
168 0 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
169 {
170 0 my($tag, $arg) = (shift, shift);
171 0 $class->export_tag($tag, $arg);
172 }
173 }
174  
175 sub add_to_export_tag
176 0 ▶{
Subroutine add_to_export_tag: not called CC=1 SCAR=6.9
Pod undocumented
177 0 my($class, $tag) = (shift, shift);
178 0 my $list = $class->export_tag($tag);
179 0 push(@$list, @_);
180 }
181  
182 47 *delete_export_tag = \&delete_export_tags;
183  
184 sub pre_import_hook
185 2532 ▶{
Subroutine pre_import_hook: called CC=10 SCAR=36.4
Pod undocumented
186 2532 my($class, $symbol) = (shift, shift);
187  
188 2532 ▶ 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 2532 2532
Condition9%1/11
@_ and @_ > 1 || ref $_[0] && !((ref $_[0] || "") =~ /\A(?:ARRAY|CODE)\z/)
!ll&&!rl&&r
253200
@_ > 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
189 {
190 0 croak 'pre_import_hook() expects either a single symbol name argument, ',
191 'or a symbol name and a code reference or a reference to an array ',
192 'of code references';
193 }
194  
195 2532 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2532 2532
196 {
197 0 ▶ unless(ref $_[0] eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_[0] eq "ARRAY") 0 0 0
198 {
199 0 $_[0] = [ $_[0] ];
200 }
201 }
202  
203 2532 ▶ my $ret = $class->_pre_import_hook($symbol, @_) || [];
Condition50%1/2
$class->_pre_import_hook($symbol, @_) || []
l!l
02532
MC/DC0%0/1
$class->_pre_import_hook($symbol, @_) || []
$class->_pre_import_hook($symbol, @_)
Truth table50%1/2
A
A= $class->_pre_import_hook($symbol, @_)
Aresult
11
00
204  
205 2532 ▶ return wantarray ? @$ret : $ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2532 2532
206 }
207  
208 2532 ▶sub pre_import_hooks { shift->pre_import_hook(shift) }
Subroutine pre_import_hooks: called CC=1 SCAR=0.0
Pod undocumented
209  
210 47 *delete_pre_import_hook = \&delete_pre_import_hooks;
211  
212 47 1;
↑ Summary blib/lib/Rose/HTML/Form/Field/Time/Hours.pm »