File Coverage

blib/lib/WWW/Postini/Exception.pm
Criterion Covered Total %
statement 37 38 97.3
branch 9 12 75.0
condition 3 3 100.0
subroutine 6 6 100.0
pod 1 1 100.0
total 56 60 93.3


line stmt bran cond sub pod time code
1             package WWW::Postini::Exception;
2            
3 1     1   5 use strict;
  1         1  
  1         29  
4 1     1   4 use warnings;
  1         2  
  1         22  
5            
6 1     1   1019 use Exception::Class;
  1         13512  
  1         7  
7            
8 1     1   40 use vars qw( @ISA $VERSION );
  1         3  
  1         465  
9            
10             @ISA = qw( Exception::Class::Base );
11             $VERSION = '0.01';
12            
13             #################
14             ## initializer ##
15             #################
16            
17             sub _initialize {
18            
19 3     3   56 my $self = shift;
20 3         5 my %params;
21            
22 3 50       10 if (@_ == 1) {
23            
24             # passing an exception object as a cause
25            
26 3 100       14 if (UNIVERSAL::isa($_[0], 'WWW::Postini::Exception')) {
27            
28 1         2 $params{'cause'} = shift;
29            
30             # passing error text
31            
32             } else {
33            
34 2         5 $params{'error'} = shift;
35            
36             }
37            
38             } else {
39            
40 0         0 %params = @_;
41            
42             }
43            
44             # cause object is defined
45            
46 3 100       12 if (defined $params{'cause'}) {
47            
48             # set cause and remove parameter unsupported by base class
49 1         9 my $cause = $self->cause(delete $params{'cause'});
50            
51             # call superclass initializer
52 1         5 $self->SUPER::_initialize(@_);
53            
54             # prohibit superclass from using $! as the default message
55 1 50       292 $self->{'message'} = ref $cause unless defined $params{'message'};
56            
57 1         8 my $trace = $self->trace();
58 1         10 my $cause_trace = $cause->trace();
59 1         8 my $frame_count = $trace->frame_count();
60            
61             # strip any frames already present in cause stack trace
62            
63 1         252 for my $idx (0..$frame_count - 1) {
64            
65 2         46 my $frame = $trace->frame($idx);
66            
67 2 100 100     18 if (grep $_->filename() eq $frame->filename()
  2         8  
68             && $_->line() == $frame->line(),
69             @{$cause_trace->{'frames'}}
70             ) {
71            
72 1         35 splice @{$trace->{'frames'}}, $idx;
  1         2  
73 1         7 last;
74            
75             }
76            
77             }
78            
79             } else {
80            
81 2         15 $self->SUPER::_initialize(%params);
82            
83             }
84            
85             }
86            
87             ######################
88             ## accessor methods ##
89             ######################
90            
91             # cause
92            
93             sub cause {
94            
95 1     1 1 1 my $self = shift;
96            
97 1 50       4 if (@_) {
98            
99 1         128 $self->{'cause'} = shift
100            
101             }
102            
103 1         3 $self->{'cause'};
104            
105             }
106            
107             1;
108            
109             __END__