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