Data/Printer/Filter/GenericClass.pm

filter: Statementstmt 85.1% 178 / 209 Branchbran 77.1% 91 / 118 Conditioncond 71.6% 58 / 81 MC/DCmcdc 50.0% 24 / 48 Subroutinesub 87.5% 14 / 16 Podpod n/a totaltotal 77.3% 365 / 472 CC 99 SCAR 41.1
CC
99
Cov
80%
__ANON__
123.8
_show_methods
30.0
__ANON__
12.0
CRAP 61.1
« Data/Printer/Filter/DateTime.pm ↑ Summary Data/Printer/Config.pm »
1 package Data::Printer::Filter::GenericClass;
2 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use Data::Printer::Filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use Data::Printer::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 35 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 52 ▶filter '-class' => sub {
Subroutine __ANON__: called CC=47 SCAR=48.2
9 52 my ($object, $ddp) = @_;
10  
11 # if the class implements its own Data::Printer method, we use it!
12 52 ▶ if ($ddp->class_method and my $method = $object->can( $ddp->class_method )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ddp->class_method and my $method = $object->can($ddp->class_method)) 0 52 52
Condition33%1/3
$ddp->class_method and my $method = $object->can($ddp->class_method)
!ll&&!rl&&r
0520
MC/DC0%0/2
$ddp->class_method and my $method = $object->can($ddp->class_method)
$ddp->class_method my $method = $object->can($ddp->class_method)
Truth table33%1/3
A and B
A= $ddp->class_methodB= my $method = $object->can($ddp->class_method)
ABresult
0X0
100
111
13 0 ▶ return $method->($object, $ddp) if ref $method eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $method eq "CODE" 0 0 0
14 }
15  
16 52 my $class_name = ref $object;
17  
18 # there are many parts of the class filter that require the object's
19 # linear ISA, so we declare it earlier and load it only once:
20 52 my $linear_ISA = Data::Printer::Common::_linear_ISA_for($class_name, $ddp);
21  
22 # if the object overloads stringification, use it!
23 # except for PDF::API2 which has a destructive stringify()
24 52 ▶ if ($ddp->class->stringify && $class_name ne 'PDF::API2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ddp->class->stringify and $class_name ne "PDF::API2") 51 1 52
Condition66%2/3
$ddp->class->stringify and $class_name ne "PDF::API2"
!ll&&!rl&&r
1051
MC/DC50%1/2
$ddp->class->stringify and $class_name ne "PDF::API2"
$ddp->class->stringify $class_name ne "PDF::API2"
Truth table66%2/3
A and B
A= $ddp->class->stringifyB= $class_name ne "PDF::API2"
ABresult
0X0
100
111
25 51 my $str = _get_stringification($ddp, $object, $class_name);
26 51 ▶ return $ddp->maybe_colorize("$str ($class_name)", 'class')
Branch: 1 branch
BranchTrueFalseTotal
if defined $str 5 46 51
27 if defined $str;
28 }
29  
30 # otherwise, do our generic object representation:
31 47 my $show_reftype = $ddp->class->show_reftype;
32 47 my $show_internals = $ddp->class->internals;
33 47 my $reftype;
34 47 ▶ if ($show_reftype || $show_internals) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show_reftype or $show_internals) 46 1 47
Condition100%3/3
$show_reftype or $show_internals
l!l&&r!l&&!r
1451
MC/DC100%2/2
$show_reftype or $show_internals
$show_reftype $show_internals
Truth table100%3/3
A or B
A= $show_reftypeB= $show_internals
ABresult
1X1
011
000
35 46 $reftype = Scalar::Util::reftype($object);
36 46 ▶ $reftype = 'Regexp' if $reftype eq 'REGEXP';
Branch: 1 branch
BranchTrueFalseTotal
if $reftype eq "REGEXP" 0 46 46
37 }
38  
39 47 $ddp->{_class_depth}++;
40 47 my $string = $ddp->maybe_colorize( $class_name, 'class' );
41  
42 47 ▶ if ($show_reftype) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show_reftype) 1 46 47
43 1 $string .= ' '
44 . $ddp->maybe_colorize('(', 'brackets')
45 . $ddp->maybe_colorize( $reftype, 'class' )
46 . $ddp->maybe_colorize(')', 'brackets');
47 }
48  
49 47 ▶ if ($ddp->class->expand eq 'all' || $ddp->class->expand >= $ddp->{_class_depth}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ddp->class->expand eq "all" or $ddp->class->expand >= $ddp->{"_class_depth"}) 39 8 47
Condition100%3/3
$ddp->class->expand eq "all" or $ddp->class->expand >= $ddp->{"_class_depth"}
l!l&&r!l&&!r
2378
MC/DC100%2/2
$ddp->class->expand eq "all" or $ddp->class->expand >= $ddp->{"_class_depth"}
$ddp->class->expand eq "all" $ddp->class->expand >= $ddp->{"_class_depth"}
Truth table100%3/3
A or B
A= $ddp->class->expand eq "all"B= $ddp->class->expand >= $ddp->{"_class_depth"}
ABresult
1X1
011
000
50 39 $ddp->indent;
51 39 $string .= ' ' . $ddp->maybe_colorize('{', 'brackets');
52  
53 39 my @superclasses = Data::Printer::Common::_get_superclasses_for($class_name);
54 39 ▶ if (@superclasses && $ddp->class->parents) {
Branch: 1 branch
BranchTrueFalseTotal
if (@superclasses and $ddp->class->parents) 23 16 39
Condition100%3/3
@superclasses and $ddp->class->parents
!ll&&!rl&&r
15123
MC/DC100%2/2
@superclasses and $ddp->class->parents
@superclasses $ddp->class->parents
Truth table100%3/3
A and B
A= @superclassesB= $ddp->class->parents
ABresult
0X0
100
111
55 23 $string .= $ddp->newline . 'parents: '
56 . join(', ', map $ddp->maybe_colorize($_, 'class'), @superclasses)
57 ;
58 }
59 39 my (%roles, %attributes);
60 39 ▶ if ($INC{'Role/Tiny.pm'} && exists $Role::Tiny::APPLIED_TO{$class_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Role/Tiny.pm"} and exists $Role::Tiny::APPLIED_TO{$class_name}) 2 37 39
Condition66%2/3
$INC{"Role/Tiny.pm"} and exists $Role::Tiny::APPLIED_TO{$class_name}
!ll&&!rl&&r
3702
MC/DC50%1/2
$INC{"Role/Tiny.pm"} and exists $Role::Tiny::APPLIED_TO{$class_name}
$INC{"Role/Tiny.pm"} exists $Role::Tiny::APPLIED_TO{$class_name}
Truth table66%2/3
A and B
A= $INC{"Role/Tiny.pm"}B= exists $Role::Tiny::APPLIED_TO{$class_name}
ABresult
0X0
100
111
61 2 %roles = %{ $Role::Tiny::APPLIED_TO{$class_name} };
62 }
63 39 my $is_moose = 0;
64  
65 39 foreach my $parent (@$linear_ISA) {
66 74 ▶ if ($parent eq 'Moo::Object') {
Branch: 3 branches
BranchTrueFalseTotal
if ($parent eq 'Moo::Object') { } 2 72 74
elsif ($parent eq 'Moose::Object') { } 0 72 72
elsif ($parent eq 'Object::Pad::UNIVERSAL') { } 0 72 72
67 2 ▶ Data::Printer::Common::_tryme(sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
68 2 my $moo_maker = 'Moo'->_constructor_maker_for($class_name);
69 2 ▶ if (defined $moo_maker) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $moo_maker) 2 0 2
70 2 %attributes = %{ $moo_maker->all_attribute_specs };
71 }
72 2 });
73 2 last;
74 }
75 elsif ($parent eq 'Moose::Object') {
76 0 ▶ Data::Printer::Common::_tryme(sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
77 0 my $class_meta = $class_name->meta;
78 0 $is_moose = 1;
79 %attributes = map {
80 0 ▶ $_->name => {
Branch: 1 branch
BranchTrueFalseTotal
defined $_->writer ? : 0 0 0
81 index => $_->insertion_order,
82 init_arg => $_->init_arg,
83 is => (defined $_->writer ? 'rw' : 'ro'),
84 reader => $_->reader,
85 required => $_->is_required,
86 }
87 } $class_meta->get_all_attributes();
88 0 foreach my $role ($class_meta->calculate_all_roles()) {
89 0 $roles{ $role->name } = 1;
90 }
91 0 });
92 0 last;
93 }
94 elsif ($parent eq 'Object::Pad::UNIVERSAL') {
95 0 ▶ Data::Printer::Common::_tryme(sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 0 my $meta = Object::Pad::MOP::Class->for_class( $class_name );
97 %attributes = map {
98 0 $_->name . $_->value($class_name) => {
99 }
100 } $meta->fields;
101 0 %roles = map { $_->name => 1 } $meta->direct_roles;
102 0 });
103 }
104 }
105 39 ▶ if ($ddp->class->show_methods ne 'none') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ddp->class->show_methods ne "none") 38 1 39
106 38 ▶ if (my @role_list = keys %roles) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@role_list) = keys %roles) 2 36 38
107 2 ▶ @role_list = Data::Printer::Common::_nsort(@role_list)
Branch: 1 branch
BranchTrueFalseTotal
if @role_list and $ddp->class->sort_methods 2 0 2
Condition33%1/3
@role_list and $ddp->class->sort_methods
!ll&&!rl&&r
002
MC/DC0%0/2
@role_list and $ddp->class->sort_methods
@role_list $ddp->class->sort_methods
Truth table33%1/3
A and B
A= @role_listB= $ddp->class->sort_methods
ABresult
0X0
100
111
108 if @role_list && $ddp->class->sort_methods;
109 2 $string .= $ddp->newline . 'roles (' . scalar(@role_list) . '): '
110 . join(', ' => map $ddp->maybe_colorize($_, 'class'), @role_list)
111 ;
112 }
113  
114 38 ▶ if (my @attr_list = keys %attributes) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@attr_list) = keys %attributes) 2 36 38
115 2 ▶ @attr_list = Data::Printer::Common::_nsort(@attr_list)
Branch: 1 branch
BranchTrueFalseTotal
if @attr_list and $ddp->class->sort_methods 2 0 2
Condition33%1/3
@attr_list and $ddp->class->sort_methods
!ll&&!rl&&r
002
MC/DC0%0/2
@attr_list and $ddp->class->sort_methods
@attr_list $ddp->class->sort_methods
Truth table33%1/3
A and B
A= @attr_listB= $ddp->class->sort_methods
ABresult
0X0
100
111
116 if @attr_list && $ddp->class->sort_methods;
117 2 $string .= $ddp->newline . 'attributes (' . scalar(@attr_list) . '): '
118 . join(', ' => map $ddp->maybe_colorize($_, 'method'), @attr_list)
119 ;
120 }
121 }
122  
123 39 ▶ my $show_linear_isa = $ddp->class->linear_isa && (
Condition100%9/9
$ddp->class->linear_isa && ($ddp->class->linear_isa eq 'auto' && @superclasses > 1 || $ddp->class->linear_isa ne 'auto')
!ll&&!rl&&r
1344
$ddp->class->linear_isa eq "auto" and @superclasses > 1 or $ddp->class->linear_isa ne "auto"
l!l&&r!l&&!r
3134
$ddp->class->linear_isa eq "auto" and @superclasses > 1
!ll&&!rl&&r
1343
MC/DC50%2/4
$ddp->class->linear_isa && ($ddp->class->linear_isa eq 'auto' && @superclasses > 1 || $ddp->class->linear_isa ne 'auto')
$ddp->class->linear_isa $ddp->class->linear_isa eq "auto" @superclasses > 1 $ddp->class->linear_isa ne "auto"
Truth table66%4/6
A && B and C or D
A= $ddp->class->linear_isaB= $ddp->class->linear_isa eq "auto"C= @superclasses > 1D= $ddp->class->linear_isa ne "auto"
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
124 ($ddp->class->linear_isa eq 'auto' and @superclasses > 1)
125 or ($ddp->class->linear_isa ne 'auto')
126 );
127  
128 39 ▶ if ($show_linear_isa && @$linear_ISA) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show_linear_isa and @$linear_ISA) 4 35 39
Condition66%2/3
$show_linear_isa and @$linear_ISA
!ll&&!rl&&r
3504
MC/DC50%1/2
$show_linear_isa and @$linear_ISA
$show_linear_isa @$linear_ISA
Truth table66%2/3
A and B
A= $show_linear_isaB= @$linear_ISA
ABresult
0X0
100
111
129 4 $string .= $ddp->newline . 'linear @ISA: '
130 . join(', ' => map $ddp->maybe_colorize($_, 'class'), @$linear_ISA)
131 ;
132 }
133  
134 39 ▶ if ($ddp->class->show_methods ne 'none') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ddp->class->show_methods ne "none") 38 1 39
135 38 $string .= _show_methods($class_name, $linear_ISA, \%attributes, $ddp);
136 38 ▶ if ($is_moose && $ddp->class->show_wrapped) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_moose and $ddp->class->show_wrapped) 0 38 38
Condition33%1/3
$is_moose and $ddp->class->show_wrapped
!ll&&!rl&&r
3800
MC/DC0%0/2
$is_moose and $ddp->class->show_wrapped
$is_moose $ddp->class->show_wrapped
Truth table33%1/3
A and B
A= $is_mooseB= $ddp->class->show_wrapped
ABresult
0X0
100
111
137 0 my $modified = '';
138 0 my $modified_count = 0;
139 0 $ddp->indent;
140 0 for my $method ($class_name->meta->get_all_methods) {
141 0 ▶ if (ref $method eq 'Class::MOP::Method::Wrapped') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $method eq "Class::MOP::Method::Wrapped") 0 0 0
142 0 foreach my $kind (qw(before around after)) {
143 0 my $getter_method = $kind . '_modifiers';
144 0 ▶ if (my @modlist = $method->$getter_method) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@modlist) = $method->$getter_method) 0 0 0
145 0 ▶ $modified .= $ddp->newline . $kind . ' ' . $method->name . ': '
Branch: 1 branch
BranchTrueFalseTotal
@modlist > 1 ? : 0 0 0
146 . (@modlist > 1 ? $ddp->parse(\@modlist) : $ddp->parse($modlist[0]));
147 0 $modified_count++;
148 }
149 }
150 }
151 }
152 0 $ddp->outdent;
153 0 ▶ if ($modified_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modified_count) 0 0 0
154 0 $string .= $ddp->newline . 'method modifiers (' . $modified_count . '):'
155 . $modified;
156 }
157 }
158 }
159  
160 39 ▶ if ($ddp->class->show_overloads) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ddp->class->show_overloads) 38 1 39
161 38 my @overloads = _get_overloads($object);
162 38 ▶ if (@overloads) {
Branch: 1 branch
BranchTrueFalseTotal
if (@overloads) 2 36 38
163 2 $string .= $ddp->newline . 'overloads: ' . join(', ' => @overloads);
164 }
165 }
166  
167 39 ▶ if ($show_internals) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show_internals) 38 1 39
168 38 $string .= $ddp->newline
169 . 'internals: '
170 . $ddp->parse_as($reftype, $object)
171 ;
172 }
173  
174 39 $ddp->outdent;
175 39 $string .= $ddp->newline . $ddp->maybe_colorize('}', 'brackets');
176 }
177 47 $ddp->{_class_depth}--;
178  
179 47 ▶ if ($ddp->show_tied and my $tie = ref tied $object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ddp->show_tied and my $tie = ref tied $object) 0 47 47
Condition33%1/3
$ddp->show_tied and my $tie = ref tied $object
!ll&&!rl&&r
0470
MC/DC0%0/2
$ddp->show_tied and my $tie = ref tied $object
$ddp->show_tied my $tie = ref tied $object
Truth table33%1/3
A and B
A= $ddp->show_tiedB= my $tie = ref tied $object
ABresult
0X0
100
111
180 0 $string .= " (tied to $tie)";
181 }
182  
183 47 return $string;
184 35 };
185  
186 #######################################
187 ### Private auxiliary helpers below ###
188 #######################################
189  
190 51 ▶sub _get_stringification {
Subroutine _get_stringification: called CC=8 SCAR=20.9
191 51 my ($ddp, $object, $class_name) = @_;
192 51 require overload;
193 51 ▶ if (overload::Overloaded($object)
Branch: 1 branch
BranchTrueFalseTotal
if (overload::Overloaded($object) and overload::Method($object, "\"\"") || overload::Method($object, "0+")) 3 48 51
Condition100%6/6
overload::Overloaded($object) and overload::Method($object, "\"\"") || overload::Method($object, "0+")
!ll&&!rl&&r
4533
overload::Method($object, "\"\"") or overload::Method($object, "0+")
l!l&&r!l&&!r
123
MC/DC100%3/3
overload::Overloaded($object) and overload::Method($object, "\"\"") || overload::Method($object, "0+")
overload::Overloaded($object) overload::Method($object, "\"\"") overload::Method($object, "0+")
Truth table100%4/4
A and B or C
A= overload::Overloaded($object)B= overload::Method($object, "\"\"")C= overload::Method($object, "0+")
ABCresult
0XX0
1000
11X1
1011
194 && (overload::Method($object, q(""))
195 || overload::Method($object, q(0+))
196 )
197 ) {
198 3 my $string;
199 3 ▶ my $error = Data::Printer::Common::_tryme(sub { $string = '' . $object });
Subroutine __ANON__: called CC=1 SCAR=0.0
200 3 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) { } 0 3 3
201 0 Data::Printer::Common::_warn(
202 $ddp,
203 "string/number overload error for object $class_name: $error"
204 );
205 }
206 else {
207 3 return $string;
208 }
209 }
210 48 foreach my $method (qw(as_string stringify to_string)) {
211 141 ▶ if ($object->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can($method)) 2 139 141
212 2 my $string;
213 2 ▶ my $error = Data::Printer::Common::_tryme(sub { $string = $object->$method });
Subroutine __ANON__: called CC=1 SCAR=0.0
214 2 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) { } 0 2 2
215 0 Data::Printer::Common::_warn(
216 $ddp,
217 "error stringifying object $class_name with $method\(\): $error"
218 );
219 }
220 else {
221 2 return $string;
222 }
223 }
224 }
225 46 return;
226 }
227  
228 # returns array of all overloads in class;
229 38 ▶sub _get_overloads {
Subroutine _get_overloads: called CC=2 SCAR=6.9
230 38 my ($object) = @_;
231 38 require overload;
232 38 ▶ return () unless overload::Overloaded($object);
Branch: 1 branch
BranchTrueFalseTotal
unless overload::Overloaded($object) 36 2 38
233 2 return sort grep overload::Method($object, $_),
234 map split(/\s+/), values %overload::ops;
235 }
236  
237 38 ▶sub _show_methods {
Subroutine _show_methods: called CC=30 SCAR=34.0
238 38 my ($class_name, $linear_ISA, $attributes, $ddp) = @_;
239  
240 38 my %methods = ( public => {}, private => {} );
241 38 my @all_methods = map _methods_of(
242 $_, Data::Printer::Common::_get_namespace($_)
243 ), @$linear_ISA;
244 38 my $show_methods = $ddp->class->show_methods;
245 38 my $show_inherited = $ddp->class->inherited;
246 38 my %seen_method_name;
247 38 foreach my $method (@all_methods) {
248 235 my ($package_string, $method_string) = @$method;
249 235 ▶ next if exists $attributes->{$method_string};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attributes->{$method_string} 2 233 235
250 233 ▶ next if $seen_method_name{$method_string}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_method_name{$method_string}++ 27 206 233
251 206 ▶ next if $method_string eq '__ANON__'; # anonymous subs don't matter here.
Branch: 1 branch
BranchTrueFalseTotal
if $method_string eq "__ANON__" 1 205 206
252 205 ▶ my $type = substr($method_string, 0, 1) eq '_' ? 'private' : 'public';
Branch: 1 branch
BranchTrueFalseTotal
substr($method_string, 0, 1) eq '_' ? : 40 165 205
253 205 ▶ if ($package_string eq $class_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package_string eq $class_name) { } 107 98 205
254 107 ▶ next unless $show_methods eq 'all' || $show_methods eq $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $show_methods eq "all" or $show_methods eq $type 13 94 107
Condition100%3/3
$show_methods eq "all" or $show_methods eq $type
l!l&&r!l&&!r
87713
MC/DC100%2/2
$show_methods eq "all" or $show_methods eq $type
$show_methods eq "all" $show_methods eq $type
Truth table100%3/3
A or B
A= $show_methods eq "all"B= $show_methods eq $type
ABresult
1X1
011
000
255 94 $methods{$type}{$method_string} = undef;
256 }
257 else {
258 98 ▶ next unless $show_inherited eq 'all' || $show_inherited eq $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $show_inherited eq "all" or $show_inherited eq $type 46 52 98
Condition100%3/3
$show_inherited eq "all" or $show_inherited eq $type
l!l&&r!l&&!r
232946
MC/DC100%2/2
$show_inherited eq "all" or $show_inherited eq $type
$show_inherited eq "all" $show_inherited eq $type
Truth table100%3/3
A or B
A= $show_inherited eq "all"B= $show_inherited eq $type
ABresult
1X1
011
000
259 52 $methods{$type}{$method_string} = $package_string;
260 }
261 }
262 38 my $string = '';
263 38 foreach my $type (qw(public private)) {
264 76 ▶ next unless $show_methods eq 'all' or $show_methods eq $type
Branch: 1 branch
BranchTrueFalseTotal
unless $show_methods eq "all" or $show_methods eq $type or $show_inherited eq "all" or $show_inherited eq $type 3 73 76
Condition88%8/9
$show_methods eq "all" or $show_methods eq $type or $show_inherited eq "all" or $show_inherited eq $type
l!l&&r!l&&!r
7213
$show_methods eq "all" or $show_methods eq $type or $show_inherited eq "all"
l!l&&r!l&&!r
7204
$show_methods eq "all" or $show_methods eq $type
l!l&&r!l&&!r
6844
MC/DC75%3/4
$show_methods eq "all" or $show_methods eq $type or $show_inherited eq "all" or $show_inherited eq $type
$show_methods eq "all" $show_methods eq $type $show_inherited eq "all" $show_inherited eq $type
Truth table80%4/5
A or B or C or D
A= $show_methods eq "all"B= $show_methods eq $typeC= $show_inherited eq "all"D= $show_inherited eq $type
ABCDresult
1XXX1
01XX1
001X1
00011
00000
265 or $show_inherited eq 'all' or $show_inherited eq $type
266 ;
267 73 ▶ if ($ddp->class->format_inheritance eq 'string') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ddp->class->format_inheritance eq 'string') { } 4 69 73
268 4 my @method_list = keys %{$methods{$type}};
269 4 ▶ @method_list = Data::Printer::Common::_nsort(@method_list)
Branch: 1 branch
BranchTrueFalseTotal
if @method_list and $ddp->class->sort_methods 3 1 4
Condition66%2/3
@method_list and $ddp->class->sort_methods
!ll&&!rl&&r
103
MC/DC50%1/2
@method_list and $ddp->class->sort_methods
@method_list $ddp->class->sort_methods
Truth table66%2/3
A and B
A= @method_listB= $ddp->class->sort_methods
ABresult
0X0
100
111
270 if @method_list && $ddp->class->sort_methods;
271  
272 4 $string .= $ddp->newline . "$type methods (" . scalar(@method_list) . ')';
273 4 ▶ if (@method_list) {
Branch: 1 branch
BranchTrueFalseTotal
if (@method_list) 3 1 4
274 $string .= ': '
275 . join(', ' => map {
276 3 $ddp->maybe_colorize(
277 14 ▶ $_ . (defined $methods{$type}{$_} ? " ($methods{$type}{$_})" : ''),
Branch: 1 branch
BranchTrueFalseTotal
defined $methods{$type}{$_} ? : 8 6 14
278 'method'
279 )
280 } @method_list)
281 ;
282 }
283 }
284 else { # 'lines'
285 # first we convert our hash to { pkg => [ @methods ] }
286 69 my %lined_methods;
287 my @base_methods;
288 69 my $total_methods = 0;
289 69 foreach my $method (keys %{$methods{$type}}) {
290 132 my $pkg_name = $methods{$type}{$method};
291 132 ▶ if (defined $pkg_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pkg_name) { } 44 88 132
292 44 push @{ $lined_methods{$pkg_name} }, $method;
293 }
294 else {
295 88 push @base_methods, $method;
296 }
297 132 $total_methods++;
298 }
299  
300 # then we print them, starting with our own methods:
301 69 ▶ @base_methods = Data::Printer::Common::_nsort(@base_methods)
Branch: 1 branch
BranchTrueFalseTotal
if @base_methods and $ddp->class->sort_methods 40 29 69
Condition66%2/3
@base_methods and $ddp->class->sort_methods
!ll&&!rl&&r
29040
MC/DC50%1/2
@base_methods and $ddp->class->sort_methods
@base_methods $ddp->class->sort_methods
Truth table66%2/3
A and B
A= @base_methodsB= $ddp->class->sort_methods
ABresult
0X0
100
111
302 if @base_methods && $ddp->class->sort_methods;
303  
304 69 ▶ $string .= $ddp->newline . "$type methods ($total_methods)"
Branch: 1 branch
BranchTrueFalseTotal
$total_methods ? : 42 27 69
305 . ($total_methods ? ':' : '')
306 ;
307 69 ▶ if (@base_methods) {
Branch: 1 branch
BranchTrueFalseTotal
if (@base_methods) 40 29 69
308 my $base_string = join(', ' => map {
309 40 $ddp->maybe_colorize($_, 'method')
310 } @base_methods);
311 40 $ddp->indent;
312 # newline only if we have parent methods to show:
313 40 ▶ $string .= (keys %lined_methods ? $ddp->newline : ' ') . $base_string;
Branch: 1 branch
BranchTrueFalseTotal
keys %lined_methods ? : 16 24 40
314 40 $ddp->outdent;
315 }
316 69 foreach my $pkg (sort keys %lined_methods) {
317 23 $ddp->indent;
318 23 $string .= $ddp->newline . "$pkg:";
319 23 ▶ @{$lined_methods{$pkg}} = Data::Printer::Common::_nsort(@{$lined_methods{$pkg}})
Branch: 1 branch
BranchTrueFalseTotal
if $ddp->class->sort_methods 23 0 23
320 if $ddp->class->sort_methods;
321 23 $ddp->indent;
322 $string .= $ddp->newline . join(', ' => map {
323 44 $ddp->maybe_colorize($_, 'method')
324 23 } @{$lined_methods{$pkg}}
325 );
326 23 $ddp->outdent;
327 23 $ddp->outdent;
328 }
329 }
330 }
331  
332 38 return $string;
333 }
334  
335 72 ▶sub _methods_of {
Subroutine _methods_of: called CC=8 SCAR=23.7
336 72 require B;
337 72 my ($class_name, $namespace) = @_;
338 72 my @methods;
339 72 foreach my $subref (_get_all_subs_from($class_name, $namespace)) {
340 235 ▶ next unless $subref;
Branch: 1 branch
BranchTrueFalseTotal
unless $subref 0 235 235
341 235 my $m = B::svref_2object($subref);
342 235 ▶ next unless $m && $m->isa('B::CV');
Branch: 1 branch
BranchTrueFalseTotal
unless $m and $m->isa("B::CV") 0 235 235
Condition33%1/3
$m and $m->isa("B::CV")
!ll&&!rl&&r
00235
MC/DC0%0/2
$m and $m->isa("B::CV")
$m $m->isa("B::CV")
Truth table33%1/3
A and B
A= $mB= $m->isa("B::CV")
ABresult
0X0
100
111
343 235 my $gv = $m->GV;
344 235 ▶ next unless $gv && !$gv->isa('B::Special') && $gv->NAME;
Branch: 1 branch
BranchTrueFalseTotal
unless $gv and not $gv->isa("B::Special") and $gv->NAME 0 235 235
Condition33%2/6
$gv and not $gv->isa("B::Special") and $gv->NAME
!ll&&!rl&&r
00235
$gv and not $gv->isa("B::Special")
!ll&&!rl&&r
00235
MC/DC0%0/3
$gv and not $gv->isa("B::Special") and $gv->NAME
$gv not $gv->isa("B::Special") $gv->NAME
Truth table25%1/4
A and not(B) and C
A= $gvB= not $gv->isa("B::Special")C= $gv->NAME
ABCresult
0XX0
10X0
1100
1111
345 235 push @methods, [ $gv->STASH->NAME, $gv->NAME ];
346 }
347 72 return @methods;
348 }
349  
350 72 ▶sub _get_all_subs_from {
Subroutine _get_all_subs_from: called CC=6 SCAR=17.9
351 72 my ($class_name, $namespace) = @_;
352 72 my @subs;
353 72 foreach my $key (keys %$namespace) {
354 # perlsub says any sub starting with '(' is reserved for overload,
355 # so we skip those:
356 530 ▶ next if substr($key, 0, 1) eq '(';
Branch: 1 branch
BranchTrueFalseTotal
if substr($key, 0, 1) eq "(" 9 521 530
357 521 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (ref \$namespace->{$key} ne "GLOB" or defined *{$namespace->{$key};}{"CODE"}) 235 286 521
Condition66%2/3
ref \$namespace->{$key} ne "GLOB" or defined *{$namespace->{$key};}{"CODE"}
l!l&&r!l&&!r
0235286
MC/DC50%1/2
ref \$namespace->{$key} ne "GLOB" or defined *{$namespace->{$key};}{"CODE"}
ref \$namespace->{$key} ne "GLOB" defined *{$namespace->{$key};}{"CODE"}
Truth table66%2/3
A or B
A= ref \$namespace->{$key} ne "GLOB"B= defined *{$namespace->{$key};}{"CODE"}
ABresult
1X1
011
000
358 # any non-typeglob in the symbol table is a constant or stub
359 ref(\$namespace->{$key}) ne 'GLOB'
360 # regular subs are stored in the CODE slot of the typeglob
361 521 || defined(*{$namespace->{$key}}{CODE})
362 ) {
363 235 push @subs, $key;
364 }
365 }
366 72 my @symbols;
367 72 foreach my $sub (@subs) {
368 235 push @symbols, Data::Printer::Common::_get_symbol($class_name, $namespace, $sub, 'CODE');
369 }
370 72 return @symbols;
371 }
372  
373 35 1;
« Data/Printer/Filter/DateTime.pm ↑ Summary Data/Printer/Config.pm »