Test/Weaken/ExtraBits.pm

filter: Statementstmt 71.7% 33 / 46 Branchbran 64.2% 9 / 14 Conditioncond 22.2% 4 / 18 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 70.0% 7 / 10 Podpod 100% 5 / 5 totaltotal 58.2% 60 / 103 CC 14 SCAR 20.2
CC
14
Cov
59%
ignore_Class_Singleton
20.0
ignore_DBI_globals
12.0
contents_glob_IO
6.0
CRAP 7.6
« Test/Without/Shm.pm ↑ Summary Module/Util/Masked.pm »
1 # Copyright 2008, 2009, 2010, 2011, 2012, 2015, 2017 Kevin Ryde
2  
3 # This file is part of Test-VariousBits.
4 #
5 # Test-VariousBits is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 3, or (at your option) any
8 # later version.
9 #
10 # Test-VariousBits is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Test-VariousBits. If not, see <http://www.gnu.org/licenses/>.
17  
18 package Test::Weaken::ExtraBits;
19 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use vars '$VERSION', '@ISA', '@EXPORT_OK';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 $VERSION = 8;
24  
25 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 @ISA = ('Exporter');
27 1 @EXPORT_OK = qw(
28 contents_glob_IO
29 ignore_Class_Singleton
30 ignore_DBI_globals
31 ignore_global_functions
32 ignore_functions
33 );
34  
35 1 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 #------------------------------------------------------------------------------
38 0 ▶sub contents_glob_IO {
Subroutine contents_glob_IO: not called CC=2 SCAR=17.9
Pod documented
39 0 my ($ref) = @_;
40 0 ▶ ref($ref) eq 'GLOB' || return;
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq "GLOB" or return 0 0 0
41 0 return *$ref{IO};
42 }
43  
44 #------------------------------------------------------------------------------
45  
46 0 ▶sub ignore_Class_Singleton {
Subroutine ignore_Class_Singleton: not called CC=4 SCAR=30.0
Pod documented
47 0 my ($ref) = @_;
48 0 my $class;
49 0 require Scalar::Util;
50 0 ▶ return (($class = Scalar::Util::blessed($ref))
Condition0%0/9
($class = builtin::blessed($ref)) && $ref->isa('Class::Singleton') && $class->has_instance && $class->instance == $ref
!ll&&!rl&&r
000
$class = builtin::blessed($ref) and $ref->isa("Class::Singleton") and $class->has_instance
!ll&&!rl&&r
000
$class = builtin::blessed($ref) and $ref->isa("Class::Singleton")
!ll&&!rl&&r
000
MC/DC0%0/4
($class = builtin::blessed($ref)) && $ref->isa('Class::Singleton') && $class->has_instance && $class->instance == $ref
$class = builtin::blessed($ref) $ref->isa("Class::Singleton") $class->has_instance $class->instance == $ref
Truth table0%0/5
A and B and C && D
A= $class = builtin::blessed($ref)B= $ref->isa("Class::Singleton")C= $class->has_instanceD= $class->instance == $ref
ABCDresult
0XXX0
10XX0
110X0
11100
11111
51 && $ref->isa('Class::Singleton')
52 && $class->has_instance
53 && $class->instance == $ref);
54 }
55  
56 0 ▶sub ignore_DBI_globals {
Subroutine ignore_DBI_globals: not called CC=3 SCAR=24.8
Pod documented
57 0 my ($ref) = @_;
58 0 require Scalar::Util;
59  
60 0 ▶ if (Scalar::Util::blessed($ref)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($ref) and $ref->isa("DBI::dr")) 0 0 0
Condition0%0/3
builtin::blessed($ref) and $ref->isa("DBI::dr")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($ref) and $ref->isa("DBI::dr")
builtin::blessed($ref) $ref->isa("DBI::dr")
Truth table0%0/3
A and B
A= builtin::blessed($ref)B= $ref->isa("DBI::dr")
ABresult
0X0
100
111
61 && $ref->isa('DBI::dr')) {
62 0 if (DEBUG) { Test::More::diag ("ignore DBI::dr object -- $ref\n"); }
63 0 return 1;
64 }
65  
66 0 return 0;
67 }
68  
69 7 ▶sub ignore_global_functions {
Subroutine ignore_global_functions: called CC=4 SCAR=14.0
Pod documented
70 7 my ($ref) = @_;
71 7 ▶ ref $ref eq 'CODE' or return;
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq "CODE" or return 4 3 7
72  
73 # could use Sub::Identify, but B comes with perl already
74 4 require B;
75 4 my $cv = B::svref_2object($ref);
76 4 my $gv = $cv->GV;
77 # as per Sub::Identify, for some sort of undefined GV
78 4 ▶ return if $gv->isa('B::SPECIAL');
Branch: 1 branch
BranchTrueFalseTotal
if $gv->isa("B::SPECIAL") 0 4 4
79  
80 4 my $fullname = $gv->STASH->NAME . '::' . $gv->NAME;
81 # Test::More::diag "ignore_global_functions() fullname $fullname";
82  
83 4 ▶ return (defined &$fullname && $ref == \&$fullname);
Condition66%2/3
defined &$fullname && $ref == \&$fullname
!ll&&!rl&&r
202
MC/DC50%1/2
defined &$fullname && $ref == \&$fullname
defined &$fullname $ref == \&$fullname
Truth table66%2/3
A && B
A= defined &$fullnameB= $ref == \&$fullname
ABresult
0X0
100
111
84 }
85 # require Sub::Identify;
86 # my $fullname = Sub::Identify::sub_fullname ($ref);
87 # return (defined &$fullname
88 # && $ref == \&$fullname);
89  
90 9 ▶sub ignore_functions {
Subroutine ignore_functions: called CC=5 SCAR=16.1
Pod documented
91 9 my $ref = shift;
92 9 ▶ ref $ref eq 'CODE' or return;
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq "CODE" or return 6 3 9
93  
94 6 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 8 2 10
95 8 my $funcname = shift;
96 8 ▶ if (defined &$funcname && $ref == \&$funcname) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &$funcname and $ref == \&$funcname) 4 4 8
Condition66%2/3
defined &$funcname and $ref == \&$funcname
!ll&&!rl&&r
044
MC/DC50%1/2
defined &$funcname and $ref == \&$funcname
defined &$funcname $ref == \&$funcname
Truth table66%2/3
A and B
A= defined &$funcnameB= $ref == \&$funcname
ABresult
0X0
100
111
97 4 return 1;
98 }
99 }
100 2 return 0;
101 }
102  
103 #------------------------------------------------------------------------------
104 # =item C<$bool = Test::Weaken::ExtraBits::contents_glob ($ref)>
105 #
106 # If C<$ref> is a globref then return the contents of all of its slots,
107 # which means refs to
108 #
109 # SCALAR ARRAY HASH CODE IO GLOB FORMAT
110 #
111 # C<Test::Weaken>, as of version 3.006, doesn't descend into globs. This
112 # contents func can be used if that's desired. Usually
113 #
114 # sub contents_glob {
115 # my ($ref) = @_;
116 # if (ref $ref eq 'GLOB') {
117 # return map {*$ref{$_}} qw(SCALAR ARRAY HASH CODE IO GLOB FORMAT);
118 # } else {
119 # return;
120 # }
121 # }
122  
123 # =item C<$bool = ignore_module_functions ($ref, $module, $module, ...)>
124 #
125 # Return true if C<$ref> is a coderef to any function in any of the given
126 # modules.
127 #
128 # Each C<$module> is a string like C<My::Module>. If a module doesn't exist
129 # then it's skipped, so it doesn't matter if the C<My::Module> package is
130 # actually loaded yet.
131 #
132 # sub ignore_module_functions {
133 # my $ref = shift;
134 # ref $ref eq 'CODE' or return;
135 #
136 # while (@_) {
137 # my $module = shift;
138 # my $symtabname = "${module}::";
139 # no strict 'refs';
140 # %$symtabname or next;
141 # foreach my $name (keys %$symtabname) {
142 # my $fullname = "${module}::$name";
143 # if (defined &$fullname && $ref == \&$fullname) {
144 # return 1;
145 # }
146 # }
147 # }
148 # return 0;
149 # }
150  
151 1 1;
152 __END__
« Test/Without/Shm.pm ↑ Summary Module/Util/Masked.pm »