Valiant/Util/Exception.pm

filter: Statementstmt 87.8% 36 / 41 Branchbran 75.0% 9 / 12 Conditioncond 77.7% 7 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 66.6% 6 / 9 Podpod 25.0% 1 / 4 totaltotal 77.5% 62 / 80 CC 11 SCAR 15.0
CC
11
Cov
84%
as_string
7.1
_build_trace
5.2
_build_message
2.0
CRAP 4.5
« Valiant/Validator/Confirmation.pm ↑ Summary Valiant/Filter/Collection.pm »
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
BranchTrueFalseTotal
if (my(@c) = &CORE::GLOBAL::caller(++$skip)) 6 0 6
16 6 ▶ last if ($c[3] =~ /^(.*)::new$/ || $c[3] =~ /^\S+ (.*)::new \(defined at /)
Branch: 1 branch
BranchTrueFalseTotal
if $c[3] =~ /^(.*)::new$/ || $c[3] =~ /^\S+ (.*)::new \(defined at / and $self->isa($1) 2 4 6
Condition66%4/6
$c[3] =~ /^(.*)::new$/ || $c[3] =~ /^\S+ (.*)::new \(defined at / and $self->isa($1)
!ll&&!rl&&r
402
$c[3] =~ /^(.*)::new$/ or $c[3] =~ /^\S+ (.*)::new \(defined at /
l!l&&r!l&&!r
204
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)
ABCresult
00X0
1X00
0100
1X11
0111
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
BranchTrueFalseTotal
if ($ENV{"VALIANT_FULL_EXCEPTION"}) 0 2 2
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
BranchTrueFalseTotal
if ($in_moose and $frame->package =~ /^(?:Valiant)(?::|$)/) { } 11 8 19
elsif ($last_frame) { } 2 6 8
Condition100%3/3
$in_moose and $frame->package =~ /^(?:Valiant)(?::|$)/
!ll&&!rl&&r
6211
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)(?::|$)/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless @frames 0 2 2
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
« Valiant/Validator/Confirmation.pm ↑ Summary Valiant/Filter/Collection.pm »