lib/Unknown/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 SCAR 19.9
CC
7
Cov
82%
nomethod
6.0
BEGIN
3.0
sort
3.0
CRAP 7.3
« blib/lib/Unknown/Values.pm ↑ Summary lib/Unknown/Values.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.100';
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 BEGIN {
14 6 ▶ my %to_overload = (
Subroutine BEGIN: called CC=3 SCAR=11.0
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 sub to_string {
34 6 ▶ confess("Attempt to coerce unknown value to a string");
Subroutine to_string: called CC=1 SCAR=0.0
Pod undocumented
35 }
36  
37 sub new {
38 15 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
39 15 my $unknown = bless {} => $class;
40 15 return $unknown;
41 }
42  
43 # this helps to prevent some infinite loops
44 32 ▶sub bool {$CORE_UNKNOWN}
Subroutine bool: called CC=1 SCAR=0.0
Pod undocumented
45  
46 sub compare {
47  
48 # this suppresses the "use of unitialized value in sort" warnings
49 26 ▶ wantarray ? () : 0;
Subroutine compare: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 26 26
50 }
51  
52 sub sort {
53 26 ▶ if ( $_[2] ) { return -1 }
Subroutine sort: called CC=3 SCAR=11.0
Pod undocumented
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 sub dereference {
61 0 ▶ confess("Dereferencing cannot be performed on unknown values");
Subroutine dereference: not called CC=1 SCAR=6.9
Pod undocumented
62 }
63  
64 sub files {
65 0 ▶ confess("File operations cannot be performed on unknown values");
Subroutine files: not called CC=1 SCAR=6.9
Pod undocumented
66 }
67  
68 sub string {
69 0 ▶ confess("String operations cannot be performed on unknown values");
Subroutine string: not called CC=1 SCAR=6.9
Pod undocumented
70 }
71  
72 sub bits {
73 4 ▶ confess("Bit manipulation cannot be performed on unknown values");
Subroutine bits: called CC=1 SCAR=0.0
Pod undocumented
74 }
75  
76 sub nomethod {
77 0 ▶ if ( defined( my $operator = $_[3] ) ) {
Subroutine nomethod: not called CC=2 SCAR=17.9
Pod undocumented
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__
« blib/lib/Unknown/Values.pm ↑ Summary lib/Unknown/Values.pm »