lib/Chj/Class/methodnames.pm

filter: Statementstmt 45.0% 27 / 60 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 3 totaltotal 26.1% 34 / 130 CC 18 SCAR 48.2
CC
18
Cov
27%
methods_of_class
211.5
methodnames
12.0
set_stoplist
2.0
CRAP 123.8
« lib/Chj/Class/Array.pm ↑ Summary .htmlgen/FunctionalPerl/Htmlgen/Linking.pm »
1 #
2 # Copyright (c) 2004-2020 Christian Jaeger, copying@christianjaeger.ch
3 #
4 # This is free software, offered under either the same terms as perl 5
5 # or the terms of the Artistic License version 2 or the terms of the
6 # MIT License (Expat version). See the file COPYING.md that came
7 # bundled with this file.
8 #
9  
10 =head1 NAME
11  
12 Chj::Class::methodnames
13  
14 =head1 SYNOPSIS
15  
16 use FP::Equal 'is_equal';
17 use Chj::Class::methodnames;
18 {
19 package Foo123; sub foo { }; sub bar { };
20 }
21 is_equal [ methodnames bless {}, Foo123 ],
22 [ "bar", "foo" ];
23  
24  
25 =head1 DESCRIPTION
26  
27 Return all names of methods, except for those in a stoplist; also
28 recurses into parent packages following @ISA.
29  
30  
31 =head1 FUNCTIONS
32  
33 set_stoplist(list of methodnames not to return)
34 set another list than BEGIN and Dumper.
35 (It sets a new hashref at $Chj::Class::methodnames::stop.)
36  
37 =head1 NOTE
38  
39 This is alpha software! Read the status section in the package README
40 or on the L<website|http://functional-perl.org/>.
41  
42 =cut
43  
44 package Chj::Class::methodnames;
45 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 2 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 2 ▶use Exporter "import";
Subroutine BEGIN: called CC=1 SCAR=0.0
50 2 our @EXPORT = qw(methodnames);
51  
52 2 ▶use FP::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 2 our $stop = {};
55  
56 2 ▶sub set_stoplist {
Subroutine set_stoplist: called CC=2 SCAR=6.9
Pod undocumented
57  
58 #my $class = shift; eh we are not a class here
59 2 my $newstop = {};
60 2 for (@_) {
61 4 $newstop->{$_} = undef
62 }
63 2 $stop = $newstop;
64 }
65  
66 2 set_stoplist(
67 qw(
68 BEGIN
69 Dumper
70 )
71 );
72  
73 0 ▶sub methods_of_class {
Subroutine methods_of_class: not called CC=15 SCAR=53.5
Pod undocumented
74 0 my ($class, $maybe_ignore_codes) = @_;
75 0 ▶ if ($class eq 'Chj::Class::Array') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "Chj::Class::Array") 0 0 0
76  
77 # since I have such a mess there, I exclude that one, and
78 # return a list of only some of it's methods.
79 0 return qw(clone )
80 }
81 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
82 0 my $class_array_namehash = do {
83 0 ▶ if (defined *{ $class . "::_CLASS_ARRAY_COUNTER" }{SCALAR}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *{$class . '::_CLASS_ARRAY_COUNTER';}{'SCALAR'}) { } 0 0 0
84 +{
85 0 map { $_ => 1 } (
86 0 @{ $class . "::_CLASS_ARRAY_PUBLIC_FIELDS" },
87 0 @{ $class . "::_CLASS_ARRAY_PUBLICA_FIELDS" },
88 0 @{ $class . "::_CLASS_ARRAY_PROTECTED_FIELDS" },
89 0 @{ $class . "::_CLASS_ARRAY_PRIVATE_FIELDS" }
90 )
91 }
92 } else {
93 undef
94 0 }
95 };
96 my $ignore_codes = defined $maybe_ignore_codes ? $maybe_ignore_codes : +{
97 0 ▶ map { $_ => 1 } (
Condition0%0/15
*Data::Dumper::Dumper{'CODE'} || ()
l!l&&r!l&&!r
000
*Carp::croak{'CODE'} || ()
l!l&&r!l&&!r
000
*Carp::carp{'CODE'} || ()
l!l&&r!l&&!r
000
*Carp::confess{'CODE'} || ()
l!l&&r!l&&!r
000
*Carp::cluck{'CODE'} || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
*Data::Dumper::Dumper{'CODE'} || ()
*Data::Dumper::Dumper{'CODE'} ()
MC/DC0%0/2
*Carp::croak{'CODE'} || ()
*Carp::croak{'CODE'} ()
MC/DC0%0/2
*Carp::carp{'CODE'} || ()
*Carp::carp{'CODE'} ()
MC/DC0%0/2
*Carp::confess{'CODE'} || ()
*Carp::confess{'CODE'} ()
MC/DC0%0/2
*Carp::cluck{'CODE'} || ()
*Carp::cluck{'CODE'} ()
Truth table0%0/3
A || B
A= *Data::Dumper::Dumper{'CODE'}B= ()
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= *Carp::croak{'CODE'}B= ()
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= *Carp::carp{'CODE'}B= ()
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= *Carp::confess{'CODE'}B= ()
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= *Carp::cluck{'CODE'}B= ()
ABresult
1X1
011
000
98 (*Data::Dumper::Dumper{CODE} || ()),
99 (*Carp::croak{CODE} || ()),
100 (*Carp::carp{CODE} || ()),
101 (*Carp::confess{CODE} || ()),
102 0 ▶ (*Carp::cluck{CODE} || ())
Branch: 1 branch
BranchTrueFalseTotal
defined $maybe_ignore_codes ? : 0 0 0
103 )
104 };
105 0 ▶ if (my $hash = *{ $class . "::" }{HASH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hash = *{$class . '::';}{'HASH'}) { } 0 0 0
106 0 my $code; # (ugly?)
107 (
108 (
109 grep {
110 (
111 not(exists $stop->{$_}) and not do {
112  
113 # constant name of class array based class.
114 # or: constant at all?. how to find out if it's a constant?
115 $class_array_namehash
116 0 ▶ and exists $class_array_namehash->{$_}
Condition0%0/3
$class_array_namehash && exists $class_array_namehash->{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
$class_array_namehash && exists $class_array_namehash->{$_}
$class_array_namehash exists $class_array_namehash->{$_}
Truth table0%0/3
A && B
A= $class_array_namehashB= exists $class_array_namehash->{$_}
ABresult
0X0
100
111
117 }
118 0 and $code = *{ $class . "::" . $_ }{CODE}
119 0 ▶ and not do {
Condition0%0/8
!(exists $Chj::Class::methodnames::stop->{$_} || do { $class_array_namehash and exists $class_array_namehash->{$_} }) && ($code = *{$class . '::' . $_;}{'CODE'}) && !do { $ignore_codes->{$code} }
!ll&&!rl&&r
000
not exists $Chj::Class::methodnames::stop->{$_} || do { $class_array_namehash and exists $class_array_namehash->{$_} } and $code = *{$class . '::' . $_;}{"CODE"}
!ll
00
exists $Chj::Class::methodnames::stop->{$_} || do { $class_array_namehash and exists $class_array_namehash->{$_} }
l!l&&r!l&&!r
000
MC/DC0%0/3
!(exists $Chj::Class::methodnames::stop->{$_} || do { $class_array_namehash and exists $class_array_namehash->{$_} }) && ($code = *{$class . '::' . $_;}{'CODE'}) && !do { $ignore_codes->{$code} }
exists $Chj::Class::methodnames::stop->{$_} do { $class_array_namehash and exists $class_array_namehash->{$_} } !do { $ignore_codes->{$code} }
Truth table0%0/4
not(A || B) && not(C)
A= exists $Chj::Class::methodnames::stop->{$_}B= do { $class_array_namehash and exists $class_array_namehash->{$_} }C= !do { $ignore_codes->{$code} }
ABCresult
1XX0
01X0
0000
0011
120  
121 # exclude carp/croak, Dumper etc.
122 0 $ignore_codes->{$code}
123 }
124 )
125 } keys %$hash
126 ),
127 0 do {
128 0 ▶ if (my $isa = *{ $class . "::ISA" }{ARRAY}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $isa = *{$class . '::ISA';}{'ARRAY'}) { } 0 0 0
129 0 map { methods_of_class($_, $ignore_codes) } @$isa
130 } else {
131 ()
132 0 }
133 }
134 )
135 } else {
136 () # or exception?
137 0 }
138 }
139  
140 0 ▶sub methodnames {
Subroutine methodnames: not called CC=3 SCAR=24.8
Pod undocumented
141 0 ▶ @_ == 1 or fp_croak_arity 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or fp_croak_arity(1) 0 0 0
142 0 my ($obj_or_class) = @_;
143 0 ▶ my $class = ref($obj_or_class) || $obj_or_class;
Condition0%0/3
ref $obj_or_class || $obj_or_class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $obj_or_class || $obj_or_class
ref $obj_or_class $obj_or_class
Truth table0%0/3
A || B
A= ref $obj_or_classB= $obj_or_class
ABresult
1X1
011
000
144 0 methods_of_class $class;
145 }
146  
147 2 *Chj::Class::methodnames = \&methodnames;
148  
149 2 1
« lib/Chj/Class/Array.pm ↑ Summary .htmlgen/FunctionalPerl/Htmlgen/Linking.pm »