line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Twitter::Lite::Error; |
2
|
|
|
|
|
|
|
$Net::Twitter::Lite::Error::VERSION = '0.12006'; |
3
|
9
|
|
|
9
|
|
63
|
use warnings; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
376
|
|
4
|
9
|
|
|
9
|
|
1368
|
use strict; |
|
9
|
|
|
|
|
31
|
|
|
9
|
|
|
|
|
589
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
|
|
192
|
use overload '""' => \&error, |
7
|
9
|
|
|
9
|
|
53
|
'fallback' => 1; |
|
9
|
|
|
|
|
19
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# This is basically a duplicate of Net::Twitter::Lite::Error, only without Moose. I |
10
|
|
|
|
|
|
|
# considered creating a new Net-Twitter-Error distribution so that it could be |
11
|
|
|
|
|
|
|
# shared by both Net::Twitter and Net::Twitter::Lite. But there's a strong |
12
|
|
|
|
|
|
|
# argument for making Net::Twitter::Lite depend upon as few modules as |
13
|
|
|
|
|
|
|
# possible. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Net::Twitter::Lite::Error - Encapsulates errors thrown by Net::Twitter::Lite |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 VERSION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
version 0.12006 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Net::Twitter::Lite; |
26
|
|
|
|
|
|
|
my $nt = Net::Twitter::Lite->new; |
27
|
|
|
|
|
|
|
my $r = eval { $nt->friends_timeline }; |
28
|
|
|
|
|
|
|
warn "$@\n" if $@; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
B encapsulates errors thrown by C. A |
33
|
|
|
|
|
|
|
C object will contain an C, and a HASHREF |
34
|
|
|
|
|
|
|
containing Twitter API error information if one was returned by Twitter. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 METHODS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=over 4 |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item new |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Constructs an C object with an HTTP::Response and optionally |
45
|
|
|
|
|
|
|
a Twitter error HASH ref. It takes HASH of arguments. Examples: |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $e = Net::Twitter::Lite::Error->new(http_response => $res, twitter_error => $te); |
48
|
|
|
|
|
|
|
my $e = Net::Twitter::Lite::Error->new(http_response => $res); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub new { |
53
|
4
|
|
|
4
|
1
|
15
|
my ($class, %args) = @_; |
54
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
24
|
return bless \%args, $class; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item twitter_error |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Get or set the encapsulated Twitter API error HASH ref. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub twitter_error { |
65
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
$self->{twitter_error} = shift if @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $self->{twitter_error}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item http_response |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Get or set the encapsulated HTTP::Response instance. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub http_response { |
79
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
$self->{http_response} = shift if @_; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $self->{http_response}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item code |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Returns the HTTP Status Code from the encapsulated HTTP::Response |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub code { |
93
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
0
|
|
|
|
return exists $self->{http_response} && $self->{http_response}->code; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item message |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Returns the HTTP Status Message from the encapsulated HTTP::Response |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub message { |
105
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
0
|
|
|
|
return exists $self->{http_response} && $self->{http_response}->message; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item error |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Returns an error message as a string. The message be the C element of |
113
|
|
|
|
|
|
|
the encapsulated Twitter API HASH ref, if there is one. Otherwise it will |
114
|
|
|
|
|
|
|
return a string containing the HTTP Status Code and Message. If the |
115
|
|
|
|
|
|
|
C instance does not contain either an HTTP::Response or a |
116
|
|
|
|
|
|
|
Twitter Error HASH ref, or the HTTP::Response has no status code or message, |
117
|
|
|
|
|
|
|
C returns the string '[unknown]'. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
A Net::Twitter::Lite::Error stringifies to the C message. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub error { |
124
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# We MUST stringyfy to something that evaluates to true, or testing $@ will fail! |
127
|
0
|
0
|
0
|
|
|
|
exists $self->{twitter_error} && $self->{twitter_error}{error} |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
128
|
|
|
|
|
|
|
|| ( exists $self->{http_response} |
129
|
|
|
|
|
|
|
&& ($self->code . ": " . $self->message ) |
130
|
|
|
|
|
|
|
) |
131
|
|
|
|
|
|
|
|| '[unknown]'; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |