| 1 | 2 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package failures; | ||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Minimalist exception hierarchy generator | ||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '0.004'; # VERSION | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | my ( $class, @failures ) = @_; | |||||||||||||||||||||||||||
| 12 | 3 | my $caller = caller; | |||||||||||||||||||||||||||
| 13 | 3 | my $is_custom = $class eq 'custom::failures'; | |||||||||||||||||||||||||||
| 14 | 3 | ▶ | if ( $is_custom && ref $failures[1] eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$is_custom and ref $failures[1] eq "ARRAY"
MC/DC100%2/2
$is_custom and ref $failures[1] eq "ARRAY"
$is_custom
ref $failures[1] eq "ARRAY"
Truth table100%3/3
A and B
A= $is_customB= ref $failures[1] eq "ARRAY"
| |||||||||||||||||||||||||||||
| 15 | 1 | $caller = shift @failures; | |||||||||||||||||||||||||||
| 16 | 1 | @failures = @{ $failures[0] }; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | 3 | for my $f (@failures) { | |||||||||||||||||||||||||||
| 19 | # XXX should check $f for valid package name | ||||||||||||||||||||||||||||
| 20 | 5 | my $custom = $caller; | |||||||||||||||||||||||||||
| 21 | 5 | my $default = 'failure'; | |||||||||||||||||||||||||||
| 22 | 5 | ▶ | push @{"$custom\::ISA"}, $default if $is_custom; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 5 | for my $p ( split /::/, $f ) { | |||||||||||||||||||||||||||
| 24 | 9 | push @{"$default\::$p\::ISA"}, $default; | |||||||||||||||||||||||||||
| 25 | 9 | $default .= "::$p"; | |||||||||||||||||||||||||||
| 26 | 9 | ▶ | if ($is_custom) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 4 | push @{"$custom\::$p\::ISA"}, $custom, $default; | |||||||||||||||||||||||||||
| 28 | 4 | $custom .= "::$p"; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | package failure; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | use Class::Tiny { msg => '', trace => '', payload => undef }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | ▶ | use overload ( q{""} => \&as_string, fallback => 1 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 12 | ▶ | sub throw { | ||||||||||||||||||||||||||
|
Subroutine
throw: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 41 | 12 | my ( $class, $msg ) = @_; | |||||||||||||||||||||||||||
| 42 | 12 | ▶ | my $m = ref $msg eq 'HASH' ? $msg : { msg => $msg }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 12 | ▶ | die $class->new( map { defined $m->{$_} ? ( $_ => $m->{$_} ) : () } keys %$m ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 21 | ▶ | sub message { | ||||||||||||||||||||||||||
|
Subroutine
message: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 47 | 21 | my ( $self, $msg ) = @_; | |||||||||||||||||||||||||||
| 48 | 21 | my $intro = "Caught @{[ref $self]}"; | |||||||||||||||||||||||||||
| 49 | 21 | ▶ | return defined($msg) && length($msg) ? "$intro: $msg" : $intro; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $msg and length $msg
MC/DC100%2/2
defined $msg and length $msg
defined $msg
length $msg
Truth table100%3/3
A and B
A= defined $msgB= length $msg
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 19 | ▶ | sub as_string { | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 53 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||
| 54 | 19 | my ( $message, $trace ) = ( $self->message( $self->msg ), $self->trace ); | |||||||||||||||||||||||||||
| 55 | 19 | ▶ | return length($trace) ? "$message\n\n$trace\n" : "$message\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | sub line_trace { | ||||||||||||||||||||||||||
|
Subroutine
line_trace: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 1 | my ( undef, $filename, $line ) = caller(0); | |||||||||||||||||||||||||||
| 60 | 1 | return "Failure caught at $filename line $line."; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | for my $fn (qw/croak_trace confess_trace/) { | |||||||||||||||||||||||||||
| 64 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 4 | ▶ | *{$fn} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 67 | 2 | require Carp; | |||||||||||||||||||||||||||
| 68 | 2 | local @failure::CARP_NOT = ( scalar caller ); | |||||||||||||||||||||||||||
| 69 | 2 | ▶ | chomp( my $trace = $fn eq 'croak_trace' ? Carp::shortmess('') : Carp::longmess('') ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 2 | return "Failure caught$trace"; | |||||||||||||||||||||||||||
| 71 | 4 | }; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | 1; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # vim: ts=4 sts=4 sw=4 et: | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||