line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Twitter::TagGrep; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22345
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
583
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.0000'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub prefix { |
9
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
10
|
|
|
|
|
|
|
|
11
|
0
|
0
|
|
|
|
|
if (defined $_[0]) { |
12
|
0
|
|
|
|
|
|
$self->{prefix} = $_[0]; |
13
|
0
|
|
|
|
|
|
undef $self->{tag_regex}; |
14
|
|
|
|
|
|
|
} |
15
|
0
|
|
|
|
|
|
return $self->{prefix}; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub add_prefix { |
19
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
$self->{prefix} = join '', $self->{prefix}, @_; |
22
|
0
|
|
|
|
|
|
undef $self->{tag_regex}; |
23
|
0
|
|
|
|
|
|
return $self->{prefix}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub tags { |
27
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
if (@_) { |
30
|
0
|
0
|
|
|
|
|
if (ref $_[0] eq 'ARRAY') { |
31
|
0
|
|
|
|
|
|
$self->{tags} = $_[0]; |
32
|
|
|
|
|
|
|
} else { |
33
|
0
|
|
|
|
|
|
$self->{tags} = [ @_ ]; |
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
|
undef $self->{tag_regex}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return @{$self->{tags}}; |
|
0
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub add_tag { |
42
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
for my $tag (@_) { |
45
|
0
|
0
|
|
|
|
|
if (ref $tag eq 'ARRAY') { |
46
|
0
|
|
|
|
|
|
push @{$self->{tags}}, @$tag; |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
|
push @{$self->{tags}}, $tag; |
|
0
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
undef $self->{tag_regex}; |
53
|
0
|
|
|
|
|
|
return @{$self->{tags}}; |
|
0
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub grep_tags { |
58
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
59
|
0
|
|
|
|
|
|
my $timeline = shift; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
$self->_gen_tag_regex unless $self->{tag_regex}; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return reverse grep { |
64
|
0
|
|
|
|
|
|
my @tags = $_->{text} =~ /$self->{tag_regex}/gi; |
65
|
0
|
0
|
|
|
|
|
$_->{tags} = \@tags if @tags; |
66
|
|
|
|
|
|
|
} @$timeline; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub new { |
71
|
0
|
|
|
0
|
1
|
|
my ($class, %params) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
my $self = { |
74
|
|
|
|
|
|
|
prefix => defined $params{prefix} ? $params{prefix} : '#', |
75
|
|
|
|
|
|
|
tags => [], |
76
|
|
|
|
|
|
|
tag_regex => undef, |
77
|
|
|
|
|
|
|
}; |
78
|
0
|
|
|
|
|
|
bless $self, $class; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
$self->tags($params{tags}) if $params{tags}; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return $self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _gen_tag_regex { |
86
|
0
|
|
|
0
|
|
|
my $self = shift; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$self->{tag_regex} = '(?:\A|\s)[' . $self->prefix . '](' |
89
|
|
|
|
|
|
|
. (join '|', $self->tags) . ')\b'; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# print $self->{tag_regex}, "\n"; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 NAME |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Twitter::TagGrep - Find messages with selected tags in Twitter timelines |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 VERSION |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Version 1.00 |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SYNOPSIS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
use Twitter::TagGrep; |
106
|
|
|
|
|
|
|
use Net::Twitter; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $twit = Net::Twitter->new( ... ); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $tg = Twitter::TagGrep->new( prefix => '#!', |
111
|
|
|
|
|
|
|
tags => [ 'foo', 'bar' ] ); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $timeline = $twit->friends_timeline; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Get tweets containing one or more of #foo, #bar, !foo, or !bar |
116
|
|
|
|
|
|
|
my @matches = $tg->grep_tags($timeline); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
for my $tweet (@matches) { |
119
|
|
|
|
|
|
|
print $tweet->{text}, "\n", join(', ', @{$tweet->{tags}}), "\n"; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 METHODS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=over |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item C |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Initializes and returns a new Twitter::TagGrep object. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Takes the following optional parameters: |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=over |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item C |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
A string defining the set of tag prefixes to recognize. Defaults to '#' |
137
|
|
|
|
|
|
|
(hashtags) if not specified. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item C |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Either a single tag to search for or a reference to an array containing |
142
|
|
|
|
|
|
|
any number of tags to search for. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=back |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item C |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
If passed a parameter, replaces the set of recognized prefixes. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Returns the set of recognized prefixes as a single string value. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item C |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Appends all parameters to the set of recognized prefixes and returns that |
155
|
|
|
|
|
|
|
set. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item C |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
If passed one or more parameters, sets the list of recognized tags. Any |
160
|
|
|
|
|
|
|
array references will add the contents of the referenced array, while other |
161
|
|
|
|
|
|
|
parameters will be used as-is. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Returns an array of recognized tags. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item C |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
As C, but appends to the list of tags rather than replacing it. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item C |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Takes a single scalar parameter referencing a Twitter timeline as returned |
172
|
|
|
|
|
|
|
by Net::Twitter's *_timeline functions. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Returns an array of tweets found within that timeline which contain at least |
175
|
|
|
|
|
|
|
one instance of (any character found in the C setting) followed by |
176
|
|
|
|
|
|
|
(any string listed in the C setting). This check is case-insensitive. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
A list of tags found in each returned tweet is added to it under the "tags" |
179
|
|
|
|
|
|
|
hash key. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
The tag must normally stand alone as a word by itself, but can be matched as a |
182
|
|
|
|
|
|
|
substring by using regular expression metacharacters in C values. |
183
|
|
|
|
|
|
|
Wildcard searches may also be done in this fashion, such as using the value |
184
|
|
|
|
|
|
|
"\w+" to locate all tweets containing one or more tags. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=back |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 AUTHOR |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Dave Sherohman, C<< >> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 BUGS |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
195
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
196
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 SUPPORT |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
perldoc Twitter::TagGrep |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
The latest version of this module may be obtained from |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
git://sherohman.org/tag_grep |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
You can also look for information at: |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=over 4 |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
L |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
L |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item * CPAN Ratings |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
L |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item * Search CPAN |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
L |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=back |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Copyright 2009 Dave Sherohman, all rights reserved. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
244
|
|
|
|
|
|
|
under the same terms as Perl itself. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
1; # End of Twitter::TagGrep |