File Coverage

blib/lib/Net/Stripe/Simple/Error.pm
Criterion Covered Total %
statement 15 15 100.0
branch 8 8 100.0
condition 4 4 100.0
subroutine 4 4 100.0
pod 1 1 100.0
total 32 32 100.0


line stmt bran cond sub pod time code
1             package Net::Stripe::Simple::Error;
2             $Net::Stripe::Simple::Error::VERSION = '0.005';
3             # ABSTRACT: general error class for Net::Stripe::Simple
4              
5              
6 3     3   22 use parent 'Net::Stripe::Simple::Data';
  3         21  
  3         25  
7              
8              
9 1     1 1 490 sub trace { shift->{_trace}->as_string }
10              
11             use overload '""' => sub {
12 75     75   2793 my $e = shift;
13 75         303 my ( $type, $message ) = @$e{qw(type message)};
14 75 100 100     310 $message = '[no message]' unless length( $message // '' );
15 75 100 100     263 $type = 'unknown' unless length( $type // '' );
16 75         360 my $msg = sprintf 'Error: %s - %s', $type, $message;
17 75 100       255 $msg .= " On parameter: " . $e->{param} if exists $e->{param};
18 75 100       233 $msg .= "\n\tCode: " . $e->{code} if exists $e->{code};
19 75         812 return $msg;
20 3     3   590 };
  3         56  
  3         49  
21              
22             1;
23              
24             __END__
25              
26             =pod
27              
28             =encoding UTF-8
29              
30             =head1 NAME
31              
32             Net::Stripe::Simple::Error - general error class for Net::Stripe::Simple
33              
34             =head1 DESCRIPTION
35              
36             This is a subclass of L<Net::Stripe::Simple::Data>. It has no constructor but
37             rather is constructed by L<Net::Stripe::Simple>. It is guaranteed to have a
38             C<_trace> parameter.
39              
40             It's stringification method differs from its parent's in that it stringifies to
41             a concatenation of its message and type and will report its param and code
42             attributes if these are available. The default stringification, for an error
43             with no specified message or type, is
44              
45             Error: unknown - [no message]
46              
47             The general stringification pattern is
48              
49             sprintf 'Error: %s - %s', $type, $message;
50              
51             with 'unknown' reported as the type when the type is unspecified and
52             '[no message]' as the message.
53              
54             =head1 NAME
55              
56             Net::Stripe::Simple::Error - general error class for Net::Stripe::Simple
57              
58             =head1 METHODS
59              
60             =head2 trace
61              
62             Returns the stringification of the C<_trace> parameter, which is a
63             L<Devel::StackTrace> trace which omits frames in L<Net::Stripe::Simple>.
64              
65             =head1 AUTHORS
66              
67             =over 4
68              
69             =item *
70              
71             Grant Street Group <developers@grantstreet.com>
72              
73             =item *
74              
75             David F. Houghton <dfhoughton@gmail.com>
76              
77             =back
78              
79             =head1 COPYRIGHT AND LICENSE
80              
81             This software is copyright (c) 2014 by Grant Street Group.
82              
83             This is free software; you can redistribute it and/or modify it under
84             the same terms as the Perl 5 programming language system itself.
85              
86             =head1 AUTHORS
87              
88             =over 4
89              
90             =item *
91              
92             Grant Street Group <developers@grantstreet.com>
93              
94             =item *
95              
96             David F. Houghton <dfhoughton@gmail.com>
97              
98             =back
99              
100             =head1 COPYRIGHT AND LICENSE
101              
102             This software is copyright (c) 2014 by Grant Street Group.
103              
104             This is free software; you can redistribute it and/or modify it under
105             the same terms as the Perl 5 programming language system itself.
106              
107             =cut