File Coverage

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


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