lib/Attribute/Overload.pm

filter: Statementstmt 100% 20 / 20 Branchbran 61.1% 11 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 2 / 2 Podpod 0.0% 0 / 1 totaltotal 73.9% 34 / 46 CC 12 SCAR 21.0
CC
12
Cov
78%
INIT
10.0
Overload
4.1
CRAP 8.2
↑ Summary
1 use 5.008;
2 use warnings;
3 use strict;
4  
5 package Attribute::Overload;
6 our $VERSION = '1.100710';
7 # ABSTRACT: Attribute that makes overloading easier
8  
9 use Attribute::Handlers;
10  
11 # RAWDATA to get '""' as such;
12 # CODE would interpret it as empty string and return nothing
13 sub UNIVERSAL::Overload : ATTR(CODE,RAWDATA) {
14 1 ▶ my ($pkg, $symbol, $data) = @_[ 0, 1, 4 ];
Subroutine Overload: called CC=4 SCAR=14.1
Pod undocumented
15 1 our %overload;
16 1 ▶ for (ref $data eq 'ARRAY' ? @$data : $data) {
Branch: 1 branch
BranchTrueFalseTotal
ref $data eq 'ARRAY' ? : 0 3 3
17 1 ▶ die "Too late to overload constant $_ in CHECK for $symbol\n"
Branch: 1 branch
BranchTrueFalseTotal
if /^(integer|float|binary|qr?)$/ 0 3 3
18 if /^(integer|float|binary|qr?)$/;
19 1 s!\"\"!""!g;
20 1 $overload{$pkg}{$_} = *{$symbol}{NAME};
21 }
22 }
23  
24 sub INIT {
25  
26 # only eval here, because multiple overloaded subs must only
27 # trigger one 'use overload' statement
28 1 ▶ our %overload;
Subroutine INIT: called CC=9 SCAR=23.1
29 1 my $code;
30 1 ▶ while (my ($pkg, $pkgdef) = each %overload) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %Attribute::Overload::overload) 1 1 2
31 1 my (@code, @constcode);
32 1 ▶ while (my ($op, $sub) = each %$pkgdef) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$pkgdef) 3 1 4
33 1 ▶ if ($op =~ /^(integer|float|binary|qr?)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /^(integer|float|binary|qr?)$/) { } 0 3 3
34 1 push @constcode => "$op => \\&$sub";
35 } else {
36 1 push @code => "'$op' => \\&$sub";
37 }
38 }
39 1 ▶ next unless @code || @constcode; # huh? no defs?
Branch: 1 branch
BranchTrueFalseTotal
unless @code or @constcode 0 1 1
Condition33%1/3
@code or @constcode
l!l&&r!l&&!r
100
MC/DC0%0/2
@code or @constcode
@code @constcode
Truth table33%1/3
A or B
A= @codeB= @constcode
ABresult
1X1
011
000
40 1 $code .= "package $pkg;\n";
41 1 ▶ $code .= "use overload\n" . join(",\n" => @code) . ";\n"
Branch: 1 branch
BranchTrueFalseTotal
if @code 1 0 1
42 if @code;
43  
44 # Note: the following doesn't do anything, since import()
45 # is called at BEGIN via use(), but attributes are only
46 # evaluated during CHECK. So it's commented out for now.
47 # $code .= "BEGIN { sub import { overload::constant (\n" .
48 # join(",\n" => @constcode) . ")}};\n" if @constcode;
49 }
50  
51 1 ▶ eval $code if $code;
Branch: 1 branch
BranchTrueFalseTotal
if $code 1 0 1
52 1 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
53 }
54 1;
55  
56  
57 __END__
↑ Summary