Values/Instance.pm

filter: Statementstmt 84.6% 33 / 39 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 76.4% 13 / 17 Podpod 0.0% 0 / 11 totaltotal 68.8% 53 / 77 CC 7 SCAR 7.8
CC
7
Cov
82%
nomethod
6.0
BEGIN
3.0
sort
3.0
CRAP 2.2
« Values.pm ↑ Summary Values/Instance/Fatal.pm »
1 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 # ABSTRACT: Internal value object for the "Unknown::Values" distribution
5  
6 package Unknown::Values::Instance;
7 6 $Unknown::Values::Instance::VERSION = '0.102';
8 6 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 ▶use 5.01000;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 my @to_overload;
12  
13 6 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.0
14 6 my %to_overload = (
15 sort => [qw{ <=> cmp }],
16 compare => [qw{ <= >= < > lt le gt ge == eq != ne}],
17 math => [qw{ + - * / ** atan2 cos sin exp log sqrt int abs }],
18 string => [qw{ qr x }],
19 files => [qw{ <> -X }],
20 bits => [qw{ << >> & | ^ ~ }],
21 bool => [ 'bool', '!' ],
22 dereference => [qw< ${} @{} %{} &{} *{} >],
23 nomethod => ['nomethod'],
24 );
25 6 ▶ while ( my ( $method, $ops ) = each %to_overload ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %to_overload) 54 6 60
26 54 push @to_overload => $_ => $method foreach @$ops;
27 }
28 }
29  
30 6 ▶use overload @to_overload, '""' => 'to_string';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 6 my $CORE_UNKNOWN = __PACKAGE__->new;
32  
33 6 ▶sub to_string {
Subroutine to_string: called CC=1 SCAR=0.0
Pod undocumented
34 6 confess("Attempt to coerce unknown value to a string");
35 }
36  
37 15 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
38 15 my $class = shift;
39 15 my $unknown = bless {} => $class;
40 15 return $unknown;
41 }
42  
43 # this helps to prevent some infinite loops
44 20 ▶sub bool {$CORE_UNKNOWN}
Subroutine bool: called CC=1 SCAR=0.0
Pod undocumented
45  
46 26 ▶sub compare {
Subroutine compare: called CC=2 SCAR=7.6
Pod undocumented
47  
48 # this suppresses the "use of unitialized value in sort" warnings
49 26 ▶ wantarray ? () : 0;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 26 26
50 }
51  
52 26 ▶sub sort {
Subroutine sort: called CC=3 SCAR=11.0
Pod undocumented
53 26 ▶ if ( $_[2] ) { return -1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($_[2]) { } 8 18 26
elsif (&Unknown::Values::is_unknown($_[1])) { } 8 10 18
54 8 elsif ( Unknown::Values::is_unknown( $_[1] ) ) { return 0 } # unnecessary?
55 10 else { return 1 }
56 }
57  
58 13 ▶sub math { confess("Math cannot be performed on unknown values") }
Subroutine math: called CC=1 SCAR=0.0
Pod undocumented
59  
60 0 ▶sub dereference {
Subroutine dereference: not called CC=1 SCAR=6.9
Pod undocumented
61 0 confess("Dereferencing cannot be performed on unknown values");
62 }
63  
64 0 ▶sub files {
Subroutine files: not called CC=1 SCAR=6.9
Pod undocumented
65 0 confess("File operations cannot be performed on unknown values");
66 }
67  
68 0 ▶sub string {
Subroutine string: not called CC=1 SCAR=6.9
Pod undocumented
69 0 confess("String operations cannot be performed on unknown values");
70 }
71  
72 4 ▶sub bits {
Subroutine bits: called CC=1 SCAR=0.0
Pod undocumented
73 4 confess("Bit manipulation cannot be performed on unknown values");
74 }
75  
76 0 ▶sub nomethod {
Subroutine nomethod: not called CC=2 SCAR=17.9
Pod undocumented
77 0 ▶ if ( defined( my $operator = $_[3] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $operator = $_[3])) { } 0 0 0
78 0 confess("'$operator' operations are not allowed with unknown values");
79 }
80 else {
81  
82 # XXX seems bit manipulation can trigger this
83 0 confess("Illegal operation performed on unknown value");
84 }
85 }
86  
87 6 1;
88  
89 __END__
« Values.pm ↑ Summary Values/Instance/Fatal.pm »