line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::WebService::Twitter::Tweet; |
2
|
2
|
|
|
2
|
|
15
|
use Mojo::Base -base; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
14
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
1452
|
use Mojo::WebService::Twitter::Media; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
15
|
|
5
|
2
|
|
|
2
|
|
991
|
use Mojo::WebService::Twitter::User; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
16
|
|
6
|
2
|
|
|
2
|
|
78
|
use Mojo::WebService::Twitter::Util 'parse_twitter_timestamp'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
86
|
|
7
|
2
|
|
|
2
|
|
11
|
use Scalar::Util 'weaken'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1137
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.003'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has [qw(source coordinates created_at favorites id in_reply_to_screen_name |
12
|
|
|
|
|
|
|
in_reply_to_status_id in_reply_to_user_id retweets text user)]; |
13
|
|
|
|
|
|
|
has media => sub { [] }; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub from_source { |
16
|
41
|
|
|
41
|
1
|
299
|
my ($self, $source) = @_; |
17
|
41
|
50
|
|
|
|
185
|
$self->coordinates($source->{coordinates}{coordinates}) if defined $source->{coordinates}; |
18
|
41
|
50
|
|
|
|
156
|
$self->created_at(parse_twitter_timestamp($source->{created_at})) if defined $source->{created_at}; |
19
|
41
|
|
|
|
|
2658
|
$self->favorites($source->{favorite_count}); |
20
|
41
|
|
|
|
|
281
|
$self->id($source->{id_str}); |
21
|
41
|
100
|
|
|
|
294
|
$self->in_reply_to_screen_name($source->{in_reply_to_screen_name}) if defined $source->{in_reply_to_screen_name}; |
22
|
41
|
100
|
|
|
|
157
|
$self->in_reply_to_status_id($source->{in_reply_to_status_id_str}) if defined $source->{in_reply_to_status_id_str}; |
23
|
41
|
100
|
|
|
|
153
|
$self->in_reply_to_user_id($source->{in_reply_to_user_id_str}) if defined $source->{in_reply_to_user_id_str}; |
24
|
41
|
100
|
66
|
|
|
180
|
if (defined $source->{extended_entities} and defined $source->{extended_entities}{media}) { |
25
|
13
|
|
|
|
|
25
|
my @media; |
26
|
13
|
|
|
|
|
21
|
foreach my $media_source (@{$source->{extended_entities}{media}}) { |
|
13
|
|
|
|
|
38
|
|
27
|
13
|
|
|
|
|
48
|
my $media = Mojo::WebService::Twitter::Media->new->from_source($media_source); |
28
|
13
|
|
|
|
|
62
|
weaken($media->{tweet} = $self); |
29
|
13
|
|
|
|
|
31
|
push @media, $media; |
30
|
|
|
|
|
|
|
} |
31
|
13
|
|
|
|
|
42
|
$self->media(\@media); |
32
|
|
|
|
|
|
|
} |
33
|
41
|
|
|
|
|
227
|
$self->retweets($source->{retweet_count}); |
34
|
41
|
|
33
|
|
|
268
|
my $text = $source->{full_text} // $source->{text}; |
35
|
41
|
100
|
|
|
|
90
|
if (defined $source->{display_text_range}) { |
36
|
40
|
|
|
|
|
63
|
my ($start, $end) = @{$source->{display_text_range}}; |
|
40
|
|
|
|
|
102
|
|
37
|
40
|
|
|
|
|
213
|
$text = substr $text, $start, $end; |
38
|
|
|
|
|
|
|
} |
39
|
41
|
|
|
|
|
136
|
$self->text($text); |
40
|
41
|
100
|
|
|
|
315
|
$self->user(Mojo::WebService::Twitter::User->new->from_source($source->{user})) if defined $source->{user}; |
41
|
41
|
|
|
|
|
263
|
$self->source($source); |
42
|
41
|
|
|
|
|
319
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Mojo::WebService::Twitter::Tweet - A tweet |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
use Mojo::WebService::Twitter; |
54
|
|
|
|
|
|
|
my $twitter = Mojo::WebService::Twitter->new(api_key => $api_key, api_secret => $api_secret); |
55
|
|
|
|
|
|
|
my $tweet = $twitter->get_tweet($tweet_id); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $username = $tweet->user->screen_name; |
58
|
|
|
|
|
|
|
my $created_at = $tweet->created_at; |
59
|
|
|
|
|
|
|
my $text = $tweet->text; |
60
|
|
|
|
|
|
|
say "[$created_at] \@$username: $text"; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 DESCRIPTION |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
L is an object representing a |
65
|
|
|
|
|
|
|
L tweet. See L |
66
|
|
|
|
|
|
|
for more information. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 source |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $href = $tweet->source; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Source data hashref from Twitter API. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 coordinates |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $coords = $tweet->coordinates; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Array reference of geographic coordinates (longitude then latitude), or |
81
|
|
|
|
|
|
|
C if tweet does not have coordinates. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 created_at |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $ts = $tweet->created_at; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
L object representing the creation time of the tweet in UTC. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 favorites |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $count = $tweet->favorites; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Number of times the tweet has been favorited. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 id |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $tweet_id = $tweet->id; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Tweet identifier. Note that tweet IDs are usually too large to be represented |
100
|
|
|
|
|
|
|
as a number, so should always be treated as a string. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 in_reply_to_screen_name |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $screen_name = $tweet->in_reply_to_screen_name; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Screen name of user whom tweet was in reply to, or C if tweet was not a |
107
|
|
|
|
|
|
|
reply. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 in_reply_to_status_id |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $tweet_id = $tweet->in_reply_to_status_id; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Tweet ID which tweet was in reply to, or C if tweet was not a reply. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 in_reply_to_user_id |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $user_id = $tweet->in_reply_to_user_id; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
User ID of user whom tweet was in reply to, or C if tweet was not a |
120
|
|
|
|
|
|
|
reply. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 media |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $media = $tweet->media; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Array reference of media entities associated to this tweet as |
127
|
|
|
|
|
|
|
L objects. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 retweets |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my $count = $tweet->retweets; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Number of times the tweet has been retweeted. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 text |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
my $text = $tweet->text; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Text contents of tweet. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 user |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $user = $tweet->user; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
User who sent the tweet, as a L object. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 METHODS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
L inherits all methods from L, |
150
|
|
|
|
|
|
|
and implements the following new ones. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 from_source |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
$tweet = $tweet->from_source($hr); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Populate attributes from hashref of Twitter API source data. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 BUGS |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Report any issues on the public bugtracker. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 AUTHOR |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Dan Book |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This software is Copyright (c) 2015 by Dan Book. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This is free software, licensed under: |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 SEE ALSO |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L |