File Coverage

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


line stmt bran cond sub pod time code
1             package Net::Stripe::Simple::Error;
2             $Net::Stripe::Simple::Error::VERSION = '0.004';
3             # ABSTRACT: general error class for Net::Stripe::Simple
4              
5              
6 3     3   833 use parent 'Net::Stripe::Simple::Data';
  3         572  
  3         18  
7              
8              
9 1     1 1 651 sub trace { shift->{_trace}->as_string }
10              
11             use overload '""' => sub {
12 75     75   3139 my $e = shift;
13 75         315 my ( $type, $message ) = @$e{qw(type message)};
14 75 100 100     413 $message = '[no message]' unless length( $message // '' );
15 75 100 100     343 $type = 'unknown' unless length( $type // '' );
16 75         379 my $msg = sprintf 'Error: %s - %s', $type, $message;
17 75 100       296 $msg .= " On parameter: " . $e->{param} if exists $e->{param};
18 75 50       220 $msg .= "\n\tCode: " . $e->{code} if exists $e->{code};
19 75         1885 return $msg;
20 3     3   497 };
  3         4  
  3         21  
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.004
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 METHODS
63              
64             =head2 trace
65              
66             Returns the stringification of the C<_trace> parameter, which is a
67             L<Devel::StackTrace> trace which omits frames in L<Net::Stripe::Simple>.
68              
69             =head1 AUTHORS
70              
71             =over 4
72              
73             =item *
74              
75             Grant Street Group <developers@grantstreet.com>
76              
77             =item *
78              
79             David F. Houghton <dfhoughton@gmail.com>
80              
81             =back
82              
83             =head1 COPYRIGHT AND LICENSE
84              
85             This software is copyright (c) 2014 by Grant Street Group.
86              
87             This is free software; you can redistribute it and/or modify it under
88             the same terms as the Perl 5 programming language system itself.
89              
90             =head1 AUTHORS
91              
92             =over 4
93              
94             =item *
95              
96             Grant Street Group <developers@grantstreet.com>
97              
98             =item *
99              
100             David F. Houghton <dfhoughton@gmail.com>
101              
102             =back
103              
104             =head1 COPYRIGHT AND LICENSE
105              
106             This software is copyright (c) 2014 by Grant Street Group.
107              
108             This is free software; you can redistribute it and/or modify it under
109             the same terms as the Perl 5 programming language system itself.
110              
111             =cut