blib/lib/Lexical/Failure/Objects.pm

filter: Statementstmt 31.2% 56 / 179 Branchbran 100% 2 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 20.7% 16 / 77 Podpod 100% 5 / 5 totaltotal 30.0% 80 / 266 CC 3 SCAR 6.0
CC
3
Cov
32%
_cant_use
2.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.8
« blib/lib/Lexical/Failure.pm ↑ Summary tlib/SetterErrorModule.pm »
1 package Lexical::Failure::Objects;
2  
3 9 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use Hash::Util::FieldHash 'fieldhash';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 our $VERSION = '0.000001';
8  
9 # Be invisible to Carp...
10 9 our @CARP_NOT = __PACKAGE__;
11  
12 # Attribute storage...
13 9 fieldhash my %msg_for;
14 9 fieldhash my %context_for;
15 9 fieldhash my %checked_for;
16  
17 # Constructor...
18 sub new {
19 4 ▶ my ($class, %option) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
20 4 my $newobj = bless do{ \my $impl }, $class;
21  
22 4 $msg_for{$newobj} = $option{msg};
23 4 $context_for{$newobj} = $option{context};
24  
25 4 return $newobj;
26 }
27  
28 # Utilities for error generation...
29 sub _croak {
30 9 ▶ require Carp;
Subroutine _croak: called CC=1 SCAR=0.0
31 9 Carp::croak(@_);
32 }
33  
34 sub _cant_use {
35 9 ▶ my ($obj, $as) = @_;
Subroutine _cant_use: called CC=2 SCAR=7.0
36 9 ▶ $as //= q{};
Condition50%1/2
$as //= ""
l!l
90
MC/DC0%0/1
$as //= ""
$as
Truth table50%1/2
A
A= $as
Aresult
11
00
37  
38 9 my (undef, $file, $line, $subname) = @{$context_for{$obj}};
39 9 $checked_for{$obj} = 1;
40 9 _croak("$msg_for{$obj} at $file line $line\nAttempt to use failure returned by $subname" . $as);
41 }
42  
43 # How failure objects behave...
44 use overload (
45 # Fail when used as a boolean...
46 0 ▶ bool => sub { my ($self) = @_; $checked_for{$self} = 1; return; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 3 ▶ q[!] => sub { my ($self) = @_; $checked_for{$self} = 1; return 1; },
Subroutine __ANON__: called CC=1 SCAR=0.0
48  
49 # Croak when used any other way...
50 0 ▶ q[neg] => sub { my ($self) = @_; _cant_use($self, " as negative value"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 ▶ q[~] => sub { my ($self) = @_; _cant_use($self, " in bitwise complement"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 3 ▶ q[""] => sub { my ($self) = @_; _cant_use($self, " as string"); },
Subroutine __ANON__: called CC=1 SCAR=0.0
53 0 ▶ q[0+] => sub { my ($self) = @_; _cant_use($self, " as number"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 0 ▶ q[qr] => sub { my ($self) = @_; _cant_use($self, " as regex"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 ▶ q[++] => sub { my ($self) = @_; _cant_use($self, " in increment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 0 ▶ q[--] => sub { my ($self) = @_; _cant_use($self, " in decrement"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 ▶ q[atan2] => sub { my ($self) = @_; _cant_use($self, " as argument to atan2"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 0 ▶ q[cos] => sub { my ($self) = @_; _cant_use($self, " as argument to cos"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 0 ▶ q[sin] => sub { my ($self) = @_; _cant_use($self, " as argument to sin"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 0 ▶ q[exp] => sub { my ($self) = @_; _cant_use($self, " as argument to exp"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
61 0 ▶ q[abs] => sub { my ($self) = @_; _cant_use($self, " as argument to abs"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 0 ▶ q[log] => sub { my ($self) = @_; _cant_use($self, " as argument to log"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 0 ▶ q[sqrt] => sub { my ($self) = @_; _cant_use($self, " as argument to sqrt"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 ▶ q[int] => sub { my ($self) = @_; _cant_use($self, " as argument to int"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 3 ▶ q[+] => sub { my ($self) = @_; _cant_use($self, " in addition"); },
Subroutine __ANON__: called CC=1 SCAR=0.0
66 0 ▶ q[-] => sub { my ($self) = @_; _cant_use($self, " in subtraction"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 0 ▶ q[*] => sub { my ($self) = @_; _cant_use($self, " in multiplication"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 0 ▶ q[/] => sub { my ($self) = @_; _cant_use($self, " in division"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 0 ▶ q[%] => sub { my ($self) = @_; _cant_use($self, " in modulo"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 0 ▶ q[**] => sub { my ($self) = @_; _cant_use($self, " in exponentiation"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 0 ▶ q[<<] => sub { my ($self) = @_; _cant_use($self, " in left shift"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 0 ▶ q[>>] => sub { my ($self) = @_; _cant_use($self, " in right shift"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 0 ▶ q[x] => sub { my ($self) = @_; _cant_use($self, " in repetition"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 0 ▶ q[.] => sub { my ($self) = @_; _cant_use($self, " in string concatenation"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 ▶ q[<>] => sub { my ($self) = @_; _cant_use($self, " in <> iterator"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 0 ▶ q[-X] => sub { my ($self) = @_; _cant_use($self, " in filetest"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 0 ▶ q[${}] => sub { my ($self) = @_; _cant_use($self, " as scalar reference"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 0 ▶ q[@{}] => sub { my ($self) = @_; _cant_use($self, " as array reference"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
79 3 ▶ q[%{}] => sub { my ($self) = @_; _cant_use($self, " as hash reference"); },
Subroutine __ANON__: called CC=1 SCAR=0.0
80 0 ▶ q[&{}] => sub { my ($self) = @_; _cant_use($self, " as subroutine reference"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 0 ▶ q[*{}] => sub { my ($self) = @_; _cant_use($self, " as typeglob reference"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
82 0 ▶ q[+=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 0 ▶ q[-=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 0 ▶ q[*=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
85 0 ▶ q[/=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 0 ▶ q[%=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
87 0 ▶ q[**=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 0 ▶ q[<<=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 0 ▶ q[>>=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 0 ▶ q[x=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 0 ▶ q[.=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 0 ▶ q[&=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
93 0 ▶ q[|=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 0 ▶ q[^=] => sub { my ($self) = @_; _cant_use($self, " in assignment"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 0 ▶ q[<] => sub { my ($self) = @_; _cant_use($self, " in numeric comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 0 ▶ q[<=] => sub { my ($self) = @_; _cant_use($self, " in numeric comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 0 ▶ q[>] => sub { my ($self) = @_; _cant_use($self, " in numeric comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
98 0 ▶ q[>=] => sub { my ($self) = @_; _cant_use($self, " in numeric comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 0 ▶ q[==] => sub { my ($self) = @_; _cant_use($self, " in numeric comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
100 0 ▶ q[!=] => sub { my ($self) = @_; _cant_use($self, " in numeric comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
101 0 ▶ q[<=>] => sub { my ($self) = @_; _cant_use($self, " in numeric comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 0 ▶ q[cmp] => sub { my ($self) = @_; _cant_use($self, " in string comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
103 0 ▶ q[lt] => sub { my ($self) = @_; _cant_use($self, " in string comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 0 ▶ q[le] => sub { my ($self) = @_; _cant_use($self, " in string comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
105 0 ▶ q[gt] => sub { my ($self) = @_; _cant_use($self, " in string comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
106 0 ▶ q[ge] => sub { my ($self) = @_; _cant_use($self, " in string comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
107 0 ▶ q[eq] => sub { my ($self) = @_; _cant_use($self, " in string comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
108 0 ▶ q[ne] => sub { my ($self) = @_; _cant_use($self, " in string comparison"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
109 0 ▶ q[&] => sub { my ($self) = @_; _cant_use($self, " in bitwise and"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 0 ▶ q[|] => sub { my ($self) = @_; _cant_use($self, " in bitwise or"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 0 ▶ q[^] => sub { my ($self) = @_; _cant_use($self, " in bitwise xor"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
112 0 ▶ q[~~] => sub { my ($self) = @_; _cant_use($self, " in smartmatch"); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
113 9 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 # Throw an exception if still unchecked upon destruction...
116 sub DESTROY {
117 4 ▶ my ($self) = @_;
Subroutine DESTROY: called CC=2 SCAR=6.9
118  
119 4 ▶ if (!$checked_for{$self}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $checked_for{$self}) 1 3 4
120 1 $checked_for{$self} = 1;
121 1 say {*STDERR} "$msg_for{$self} at $context_for{$self}[1] line $context_for{$self}[2]\n";
122 1 exit();
123 }
124 }
125  
126 # Context-enquiry interface...
127 3 ▶sub subname { my ($self) = @_; return $context_for{$self}[3]; }
Subroutine subname: called CC=1 SCAR=0.0
Pod documented
128 3 ▶sub line { my ($self) = @_; return $context_for{$self}[2]; }
Subroutine line: called CC=1 SCAR=0.0
Pod documented
129 3 ▶sub file { my ($self) = @_; return $context_for{$self}[1]; }
Subroutine file: called CC=1 SCAR=0.0
Pod documented
130  
131 sub context {
132 3 ▶ my ($self) = @_;
Subroutine context: called CC=1 SCAR=0.0
Pod documented
133 3 my ($subname, $file, $line) = @{$context_for{$self}}[3,1,2];
134 3 return "call to $subname at $file line $line";
135 }
136  
137  
138 9 1; # Magic true value required at end of module
139 __END__
« blib/lib/Lexical/Failure.pm ↑ Summary tlib/SetterErrorModule.pm »