/usr/local/lib/perl5/5.44.0/overload.pm

filter: Statementstmt 55.4% 56 / 101 Branchbran 19.0% 8 / 42 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 50.0% 9 / 18 Podpod 30.0% 3 / 10 totaltotal 41.0% 76 / 185 CC 29 SCAR 29.9
CC
29
Cov
42%
constant
72.0
OverloadedStringify
30.0
Overloaded
12.0
CRAP 19.9
« /usr/local/lib/perl5/5.44.0/parent.pm ↑ Summary /usr/local/lib/perl5/5.44.0/strict.pm »
1 package overload;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 our $VERSION = '1.40';
7  
8 7 our %ops = (
9 with_assign => "+ - * / % ** << >> x .",
10 assign => "+= -= *= /= %= **= <<= >>= x= .=",
11 num_comparison => "< <= > >= == !=",
12 '3way_comparison' => "<=> cmp",
13 str_comparison => "lt le gt ge eq ne",
14 binary => '& &= | |= ^ ^= &. &.= |. |.= ^. ^.=',
15 unary => "neg ! ~ ~.",
16 mutators => '++ --',
17 func => "atan2 cos sin exp abs log sqrt int",
18 conversion => 'bool "" 0+ qr',
19 iterators => '<>',
20 filetest => "-X",
21 dereferencing => '${} @{} %{} &{} *{}',
22 matching => '~~',
23 special => 'nomethod fallback =',
24 );
25  
26 7 my %ops_seen;
27 7 @ops_seen{ map split(/ /), values %ops } = ();
28  
29 0 ▶sub nil {}
Subroutine nil: not called CC=1 SCAR=0.0
Pod undocumented
30  
31 42 ▶sub OVERLOAD {
Subroutine OVERLOAD: called CC=6 SCAR=17.9
Pod undocumented
32 42 my $package = shift;
33 42 my %arg = @_;
34 42 my $sub;
35 42 *{$package . "::(("} = \&nil; # Make it findable via fetchmethod.
36 42 for (keys %arg) {
37 133 ▶ if ($_ eq 'fallback') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq 'fallback') { } 35 98 133
38 35 for my $sym (*{$package . "::()"}) {
39 35 *$sym = \&nil; # Make it findable via fetchmethod.
40 35 $$sym = $arg{$_};
41 }
42 } else {
43 warnings::warnif("overload arg '$_' is invalid")
44 98 ▶ unless exists $ops_seen{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ops_seen{$_} 0 98 98
45 98 $sub = $arg{$_};
46 98 ▶ if (not ref $sub) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $sub) 7 91 98
47 7 $ {$package . "::(" . $_} = $sub;
48 7 $sub = \&nil;
49 }
50 #print STDERR "Setting '$ {'package'}::\cO$_' to \\&'$sub'.\n";
51 98 *{$package . "::(" . $_} = \&{ $sub };
52 }
53 }
54 }
55  
56 42 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
57 42 my $package = caller();
58 # *{$package . "::OVERLOAD"} = \&OVERLOAD;
59 42 shift;
60 42 $package->overload::OVERLOAD(@_);
61 }
62  
63 21 ▶sub unimport {
Subroutine unimport: called CC=4 SCAR=13.9
64 21 my $package = caller();
65 21 shift;
66 21 *{$package . "::(("} = \&nil;
67 21 for (@_) {
68 warnings::warnif("overload arg '$_' is invalid")
69 70 ▶ unless exists $ops_seen{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ops_seen{$_} 0 70 70
70 70 ▶ delete $ {$package . "::"}{$_ eq 'fallback' ? '()' : "(" .$_};
Branch: 1 branch
BranchTrueFalseTotal
$_ eq 'fallback' ? : 7 63 70
71 }
72 }
73  
74 0 ▶sub Overloaded {
Subroutine Overloaded: not called CC=3 SCAR=24.8
Pod documented
75 0 my $package = shift;
76 0 ▶ $package = ref $package if ref $package;
Branch: 1 branch
BranchTrueFalseTotal
if ref $package 0 0 0
77 0 ▶ mycan ($package, '()') || mycan ($package, '((');
Branch: 1 branch
BranchTrueFalseTotal
mycan($package, "()") or mycan($package, "((") 0 0 0
78 }
79  
80 0 ▶sub ov_method {
Subroutine ov_method: not called CC=3 SCAR=20.0
Pod undocumented
81 0 my $globref = shift;
82 0 ▶ return undef unless $globref;
Branch: 1 branch
BranchTrueFalseTotal
unless $globref 0 0 0
83 0 my $sub = \&{*$globref};
84 7 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 0 ▶ return $sub if $sub != \&nil;
Branch: 1 branch
BranchTrueFalseTotal
if $sub != \&overload::nil 0 0 0
86 0 return shift->can($ {*$globref});
87 }
88  
89 0 ▶sub OverloadedStringify {
Subroutine OverloadedStringify: not called CC=5 SCAR=34.0
Pod undocumented
90 0 my $package = shift;
91 0 ▶ $package = ref $package if ref $package;
Branch: 1 branch
BranchTrueFalseTotal
if ref $package 0 0 0
92 #$package->can('(""')
93 0 ▶ ov_method mycan($package, '(""'), $package
Branch: 1 branch
BranchTrueFalseTotal
ov_method(mycan($package, "(\"\""), $package) or ov_method(mycan($package, "(0+"), $package) or ov_method(mycan($package, "(bool"), $package) or ov_method(mycan($package, "(nomethod"), $package) 0 0 0
Condition0%0/6
ov_method(mycan($package, "(\"\""), $package) or ov_method(mycan($package, "(0+"), $package) or ov_method(mycan($package, "(bool"), $package)
l!l&&r!l&&!r
000
ov_method(mycan($package, "(\"\""), $package) or ov_method(mycan($package, "(0+"), $package)
l!l&&r!l&&!r
000
MC/DC0%0/3
ov_method(mycan($package, "(\"\""), $package) or ov_method(mycan($package, "(0+"), $package) or ov_method(mycan($package, "(bool"), $package)
ov_method(mycan($package, "(\"\""), $package) ov_method(mycan($package, "(0+"), $package) ov_method(mycan($package, "(bool"), $package)
Truth table0%0/4
A or B or C
A= ov_method(mycan($package, "(\"\""), $package)B= ov_method(mycan($package, "(0+"), $package)C= ov_method(mycan($package, "(bool"), $package)
ABCresult
1XX1
01X1
0011
0000
94 or ov_method mycan($package, '(0+'), $package
95 or ov_method mycan($package, '(bool'), $package
96 or ov_method mycan($package, '(nomethod'), $package;
97 }
98  
99 0 ▶sub Method {
Subroutine Method: not called CC=3 SCAR=19.2
Pod documented
100 0 my $package = shift;
101 0 ▶ if (ref $package) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $package) 0 0 0
102 7 ▶ no warnings 'experimental::builtin';
Subroutine BEGIN: called CC=1 SCAR=0.0
103 0 $package = builtin::blessed($package);
104 0 ▶ return undef if !defined $package;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $package 0 0 0
105 }
106 #my $meth = $package->can('(' . shift);
107 0 ov_method mycan($package, '(' . shift), $package;
108 #return $meth if $meth ne \&nil;
109 #return $ {*{$meth}};
110 }
111  
112 0 ▶sub AddrRef {
Subroutine AddrRef: not called CC=1 SCAR=0.2
Pod undocumented
113 7 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 0 "$_[0]";
115 }
116  
117 7 *StrVal = *AddrRef;
118  
119 0 ▶sub mycan { # Real can would leave stubs.
Subroutine mycan: not called CC=3 SCAR=24.8
Pod undocumented
120 0 my ($package, $meth) = @_;
121  
122 0 local $@;
123 0 local $!;
124 0 require mro;
125  
126 0 my $mro = mro::get_linear_isa($package);
127 0 foreach my $p (@$mro) {
128 0 my $fqmeth = $p . q{::} . $meth;
129 0 ▶ return \*{$fqmeth} if defined &{$fqmeth};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$fqmeth;} 0 0 0
130 }
131  
132 0 return undef;
133 }
134  
135 7 my %constants = (
136 'integer' => 0x1000, # HINT_NEW_INTEGER
137 'float' => 0x2000, # HINT_NEW_FLOAT
138 'binary' => 0x4000, # HINT_NEW_BINARY
139 'q' => 0x8000, # HINT_NEW_STRING
140 'qr' => 0x10000, # HINT_NEW_RE
141 );
142  
143 7 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
144 0 ▶sub constant {
Subroutine constant: not called CC=8 SCAR=42.8
Pod documented
145 # Arguments: what, sub
146 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
147 0 ▶ if (@_ == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
elsif (not exists $constants{$_[0]}) { } 0 0 0
elsif (not ref $_[1] && "$_[1]" =~ /(^|=)CODE\(0x[0-9a-f]+\)$/) { } 0 0 0
148 0 warnings::warnif ("Odd number of arguments for overload::constant");
149 0 last;
150 }
151 elsif (!exists $constants {$_ [0]}) {
152 0 warnings::warnif ("'$_[0]' is not an overloadable type");
153 }
154 ▶ elsif (!ref $_ [1] || "$_[1]" !~ /(^|=)CODE\(0x[0-9a-f]+\)$/) {
Condition0%0/3
ref $_[1] && "$_[1]" =~ /(^|=)CODE\(0x[0-9a-f]+\)$/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[1] && "$_[1]" =~ /(^|=)CODE\(0x[0-9a-f]+\)$/
ref $_[1] "$_[1]" =~ /(^|=)CODE\(0x[0-9a-f]+\)$/
Truth table0%0/3
A && B
A= ref $_[1]B= "$_[1]" =~ /(^|=)CODE\(0x[0-9a-f]+\)$/
ABresult
0X0
100
111
155 # Can't use C<ref $_[1] eq "CODE"> above as code references can be
156 # blessed, and C<ref> would return the package the ref is blessed into.
157 0 ▶ if (warnings::enabled) {
Branch: 1 branch
BranchTrueFalseTotal
if (warnings::enabled()) 0 0 0
158 0 ▶ $_ [1] = "undef" unless defined $_ [1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 0 0 0
159 0 warnings::warn ("'$_[1]' is not a code reference");
160 }
161 }
162 else {
163 0 $^H{$_[0]} = $_[1];
164 0 $^H |= $constants{$_[0]};
165 }
166 0 shift, shift;
167 }
168 }
169  
170 0 ▶sub remove_constant {
Subroutine remove_constant: not called CC=2 SCAR=17.9
Pod undocumented
171 # Arguments: what, sub
172 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
173 0 delete $^H{$_[0]};
174 0 $^H &= ~ $constants{$_[0]};
175 0 shift, shift;
176 }
177 }
178  
179 7 1;
180  
181 __END__
« /usr/local/lib/perl5/5.44.0/parent.pm ↑ Summary /usr/local/lib/perl5/5.44.0/strict.pm »