| 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'
$args{'type'} || 'Generic'
$args{'attribute'} || undef
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'}
Truth table50%1/2
A
A= $args{'type'}
Truth table100%2/2
A
A= $args{'attribute'}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||