PPI/Exception.pm

filter: Statementstmt 79.1% 19 / 24 Branchbran 40.0% 4 / 10 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 100% 4 / 4 totaltotal 66.0% 33 / 50 CC 8 SCAR 15.1
CC
8
Cov
63%
callers
6.0
throw
5.6
new
5.2
CRAP 4.5
« PPI/Token/Number/Float.pm ↑ Summary PPI/Cache.pm »
1 package PPI::Exception;
2  
3 =head1 NAME
4  
5 PPI::Exception - The PPI exception base class
6  
7 =head1 SYNOPSIS
8  
9 use PPI::Exception;
10
11 my $e = PPI::Exception->new( 'something happened' );
12 $e->throw;
13  
14 PPI::Exception->new( message => 'something happened' )->throw;
15 PPI::Exception->throw( message => 'something happened' );
16  
17 =head1 DESCRIPTION
18  
19 All exceptions thrown from within PPI will be instances or derivations
20 of this class.
21  
22 =cut
23  
24 63 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 63 ▶use Params::Util qw{_INSTANCE};
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 63 our $VERSION = '1.260'; # VERSION
28  
29  
30 =head1 METHODS
31  
32 =head2 new $message | message => $message, ...
33  
34 Constructs and returns a new C<PPI::Exception> object.
35  
36 A message for the exception can be passed, either as a string
37 or as C<< message => $message >>. The message is available via the
38 C<message> method.
39  
40 =cut
41  
42 sub new {
43 3 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=16.5
Pod documented
44 3 ▶ return bless { @_ }, $class if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 3 0 3
45 0 ▶ return bless { message => $_[0] }, $class if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
46 0 return bless { message => 'Unknown Exception' }, $class;
47 }
48  
49  
50 =head2 throw
51  
52 If called on a C<PPI::Exception> object, throws the object.
53 If called on the class name, uses the arguments to construct a
54 C<PPI::Exception> and then throw it.
55  
56 Each time the object is thrown, information from the Perl <caller(0)>
57 call is saved and made available via the C<callers> method.
58  
59 This method never returns.
60  
61 =cut
62  
63 sub throw {
64 4 ▶ my $it = shift;
Subroutine throw: called CC=5 SCAR=17.3
Pod documented
65 4 ▶ if ( _INSTANCE($it, 'PPI::Exception') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_INSTANCE($it, 'PPI::Exception')) { } 1 3 4
66 1 ▶ if ( $it->{callers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($it->{'callers'}) { } 1 0 1
67 1 push @{ $it->{callers} }, [ caller(0) ];
68 } else {
69 0 ▶ $it->{callers} ||= [];
Condition0%0/2
$it->{"callers"} ||= []
l!l
00
MC/DC0%0/1
$it->{"callers"} ||= []
$it->{"callers"}
Truth table0%0/2
A
A= $it->{"callers"}
Aresult
11
00
70 }
71 } else {
72 3 ▶ my $message = $_[0] || 'Unknown Exception';
Condition50%1/2
$_[0] || 'Unknown Exception'
l!l
30
MC/DC0%0/1
$_[0] || 'Unknown Exception'
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
73 3 $it = $it->new(
74 message => $message,
75 callers => [
76 [ caller(0) ],
77 ],
78 );
79 }
80 4 die $it;
81 }
82  
83  
84 =head2 message
85  
86 Returns the exception message passed to the object's constructor,
87 or a default message.
88  
89 =cut
90  
91 sub message {
92 4 ▶ $_[0]->{message};
Subroutine message: called CC=1 SCAR=0.0
Pod documented
93 }
94  
95  
96 =head2 callers
97  
98 Returns a listref, each element of which is a listref of C<caller(0)>
99 information. The returned listref can be empty.
100  
101 =cut
102  
103 sub callers {
104 0 ▶ @{ $_[0]->{callers} || [] };
Subroutine callers: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"callers"} or [] 0 0 0
105 }
106  
107  
108 63 1;
« PPI/Token/Number/Float.pm ↑ Summary PPI/Cache.pm »