| 1 | package Valiant::Util::Exception; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Devel::StackTrace 2.03; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | has 'trace' => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 7 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | builder => '_build_trace', | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | sub _build_trace { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_trace: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | my $skip = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | while (my @c = caller(++$skip)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | last if ($c[3] =~ /^(.*)::new$/ || $c[3] =~ /^\S+ (.*)::new \(defined at /) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$c[3] =~ /^(.*)::new$/ || $c[3] =~ /^\S+ (.*)::new \(defined at / and $self->isa($1)
$c[3] =~ /^(.*)::new$/ or $c[3] =~ /^\S+ (.*)::new \(defined at /
MC/DC33%1/3
$c[3] =~ /^(.*)::new$/ || $c[3] =~ /^\S+ (.*)::new \(defined at / and $self->isa($1)
$c[3] =~ /^(.*)::new$/
$c[3] =~ /^\S+ (.*)::new \(defined at /
$self->isa($1)
Truth table40%2/5
A or B and C
A= $c[3] =~ /^(.*)::new$/B= $c[3] =~ /^\S+ (.*)::new \(defined at /C= $self->isa($1)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | && $self->isa($1); | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | $skip++; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | Devel::StackTrace->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | message => $self->message, | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | indent => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | skip_frames => $skip, | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | no_refs => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | has 'message' => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | builder => '_build_message', | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub _build_message { "Error" } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_message: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | use overload( | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | q{""} => 'as_string', | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | bool => sub () { 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | fallback => 1, | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | sub BUILD { shift->trace } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | if ( $ENV{VALIANT_FULL_EXCEPTION} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return $self->trace->as_string; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | my @frames; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | my $last_frame; | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | my $in_moose = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | for my $frame ( $self->trace->frames ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 19 | ▶ | if ( $in_moose && $frame->package =~ /^(?:Valiant)(?::|$)/ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$in_moose and $frame->package =~ /^(?:Valiant)(?::|$)/
MC/DC100%2/2
$in_moose and $frame->package =~ /^(?:Valiant)(?::|$)/
$in_moose
$frame->package =~ /^(?:Valiant)(?::|$)/
Truth table100%3/3
A and B
A= $in_mooseB= $frame->package =~ /^(?:Valiant)(?::|$)/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 11 | $last_frame = $frame; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 11 | next; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | elsif ($last_frame) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | push @frames, $last_frame; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | undef $last_frame; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 8 | $in_moose = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 8 | push @frames, $frame; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # This would be a somewhat pathological case, but who knows | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | ▶ | return $self->trace->as_string unless @frames; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | my $message = ( shift @frames )->as_string( 1, {} ) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | $message .= join q{}, map { $_->as_string( 0, {} ) . "\n" } @frames; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | return $message; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub throw { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | die $class->new(@args); | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub rethrow { die shift } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rethrow: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | Valiant::Exception - Base exceptions class; | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # Nothing for end users here | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | I just copied this from L<Moose::Exception> since I trust the authors. You shouldn't | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | really use this unless you add doing L<Valiant> extensions and need to create a new | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | exception type. | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | You won't use any of this unless you are doing L<Valiant> extensions or validators. | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | =head2 trace | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | Full stack trace if you need it | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | =head2 message | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | The actual exception message | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | This class does the following methods | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | =head2 as_string | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | Exception stringy-fied. Used as an overloading target. | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | L<Valiant> | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | See L<Valiant> | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | See L<Valiant> | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||