Uniform/Exceptions.pm

filter: Statementstmt 100% 26 / 26 Branchbran 50.0% 1 / 2 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 7 totaltotal 77.7% 42 / 54 CC 5 SCAR 7.1
CC
5
Cov
91%
throw
4.1
to_string
2.0
BEGIN
1.0
CRAP 2.0
« Uniform/Utils.pm ↑ Summary Uniform.pm »
1 package Uniform::Exceptions;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use overload '""' => \&to_string; # Automatically stringifies when printed or used in regex
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '1.02';
8  
9 # Class Factory Constructor
10 5 ▶sub throw {
Subroutine throw: called CC=4 SCAR=14.2
Pod undocumented
11 5 my ($class, %args) = @_;
12  
13 my $self = {
14 message => $args{message} || 'An unhandled framework exception occurred',
15 type => $args{type} || 'Generic',
16 attribute => $args{attribute} || undef,
17 5 ▶ trace => [ caller(1) ], # Captures the exact line of code that triggered the failure
Condition66%4/6
$args{'message'} || 'An unhandled framework exception occurred'
l!l
50
$args{'type'} || 'Generic'
l!l
50
$args{'attribute'} || undef
l!l
41
MC/DC0%0/1
$args{'message'} || 'An unhandled framework exception occurred'
$args{'message'}
MC/DC0%0/1
$args{'type'} || 'Generic'
$args{'type'}
MC/DC100%1/1
$args{'attribute'} || undef
$args{'attribute'}
Truth table50%1/2
A
A= $args{'message'}
Aresult
11
00
Truth table50%1/2
A
A= $args{'type'}
Aresult
11
00
Truth table100%2/2
A
A= $args{'attribute'}
Aresult
11
00
18 };
19  
20 5 bless $self, $class;
21 5 die $self; # Throws the object reference immediately
22 }
23  
24 # Accessor methods
25 1 ▶sub message { $_[0]->{message} }
Subroutine message: called CC=1 SCAR=0.0
Pod undocumented
26 2 ▶sub type { $_[0]->{type} }
Subroutine type: called CC=1 SCAR=0.0
Pod undocumented
27 2 ▶sub attribute { $_[0]->{attribute} }
Subroutine attribute: called CC=1 SCAR=0.0
Pod undocumented
28 1 ▶sub line { $_[0]->{trace}->[2] }
Subroutine line: called CC=1 SCAR=0.0
Pod undocumented
29 1 ▶sub file { $_[0]->{trace}->[1] }
Subroutine file: called CC=1 SCAR=0.0
Pod undocumented
30  
31 # Stringification string conversion layout
32 1 ▶sub to_string {
Subroutine to_string: called CC=2 SCAR=7.0
Pod undocumented
33 1 my ($self) = @_;
34 1 my $str = sprintf "[Uniform::Exception::%s] %s", $self->type, $self->message;
35 1 ▶ if (defined $self->attribute) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->attribute) 1 0 1
36 1 $str .= sprintf " (failed on attribute: '%s')", $self->attribute;
37 }
38 1 $str .= sprintf " at %s line %d.\n", $self->file, $self->line;
39 1 return $str;
40 }
41  
42 3 1;
43  
44 __END__
« Uniform/Utils.pm ↑ Summary Uniform.pm »