line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Untaint::Twitter; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
169376
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
66
|
|
4
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
5
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
108
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
9
|
use base 'CGI::Untaint::object'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1589
|
|
8
|
2
|
|
|
2
|
|
2379
|
use Net::Twitter::Lite::WithAPIv1_1; |
|
2
|
|
|
|
|
136741
|
|
|
2
|
|
|
|
|
1012
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
CGI::Untaint::Twitter - Validate a Twitter ID in a CGI script |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.03 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
21
|
|
|
|
|
|
|
our $consumer_key; |
22
|
|
|
|
|
|
|
our $consumer_secret; |
23
|
|
|
|
|
|
|
our $access_token; |
24
|
|
|
|
|
|
|
our $access_token_secret; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
CGI::Untaint::Twitter is a subclass of CGI::Untaint used to |
29
|
|
|
|
|
|
|
validate if the given Twitter ID is valid. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use CGI::Info; |
32
|
|
|
|
|
|
|
use CGI::Untaint; |
33
|
|
|
|
|
|
|
use CGI::Untaint::Twitter; |
34
|
|
|
|
|
|
|
# ... |
35
|
|
|
|
|
|
|
my $info = CGI::Info->new(); |
36
|
|
|
|
|
|
|
my $params = $info->params(); |
37
|
|
|
|
|
|
|
# ... |
38
|
|
|
|
|
|
|
my $u = CGI::Untaint->new($params); |
39
|
|
|
|
|
|
|
my $tid = $u->extract(-as_Twitter => 'twitter'); |
40
|
|
|
|
|
|
|
# $tid will be lower case |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 is_valid |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Validates the data. |
47
|
|
|
|
|
|
|
Returns a boolean if $self->value is a valid twitter ID. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _untaint_re { |
52
|
|
|
|
|
|
|
# Only allow letters and digits |
53
|
|
|
|
|
|
|
# Remove the leading @ if any - leading spaces and so on will be |
54
|
|
|
|
|
|
|
# ignored |
55
|
1
|
|
|
1
|
|
12
|
return qr/\@?([a-zA-z0-9]+)/; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub is_valid { |
59
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
my $value = $self->value; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
0
|
if(!defined($value)) { |
64
|
0
|
|
|
|
|
0
|
return 0; |
65
|
|
|
|
|
|
|
} |
66
|
0
|
0
|
0
|
|
|
0
|
unless($consumer_key && $consumer_secret && $access_token && $access_token_secret) { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
carp 'Access tokens are required'; |
68
|
0
|
|
|
|
|
0
|
return 0; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Ignore leading and trailing spaces |
72
|
0
|
|
|
|
|
0
|
$value =~ s/\s+$//; |
73
|
0
|
|
|
|
|
0
|
$value =~ s/^\s+//; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
my $known_user = 0; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
eval { |
78
|
0
|
|
|
|
|
0
|
my $nt = Net::Twitter::Lite::WithAPIv1_1->new( |
79
|
|
|
|
|
|
|
consumer_key => $consumer_key, |
80
|
|
|
|
|
|
|
consumer_secret => $consumer_secret, |
81
|
|
|
|
|
|
|
legacy_lists_api => 0, |
82
|
|
|
|
|
|
|
access_token => $access_token, |
83
|
|
|
|
|
|
|
access_token_secret => $access_token_secret |
84
|
|
|
|
|
|
|
); |
85
|
0
|
0
|
|
|
|
0
|
if($nt->show_user({ screen_name => $value })) { |
86
|
0
|
|
|
|
|
0
|
$known_user = 1; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
}; |
89
|
0
|
0
|
|
|
|
0
|
if($@ =~ /exceeded/) { |
90
|
|
|
|
|
|
|
# Rate limit exceeded. Clients may not make more than 150 requests per hour. |
91
|
|
|
|
|
|
|
# Fall back assume it would have worked so as not to |
92
|
|
|
|
|
|
|
# incovenience the user |
93
|
0
|
|
|
|
|
0
|
return 1; |
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
0
|
return $known_user; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 init |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Set various options and override default values. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
use CGI::Info; |
103
|
|
|
|
|
|
|
use CGI::Untaint; |
104
|
|
|
|
|
|
|
use CGI::Untaint::Twitter { |
105
|
|
|
|
|
|
|
access_token => 'xxxxxx', access_token_secret => 'yyyyy', |
106
|
|
|
|
|
|
|
consumer_key => 'xyzzy', consumer_secret => 'plugh', |
107
|
|
|
|
|
|
|
}; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _init { |
112
|
0
|
0
|
|
0
|
|
0
|
my %params = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Safe options - can be called at any time |
115
|
0
|
0
|
|
|
|
0
|
if(defined($params{access_token})) { |
116
|
0
|
|
|
|
|
0
|
$access_token = $params{access_token}; |
117
|
|
|
|
|
|
|
} |
118
|
0
|
0
|
|
|
|
0
|
if(defined($params{access_token_secret})) { |
119
|
0
|
|
|
|
|
0
|
$access_token_secret = $params{access_token_secret}; |
120
|
|
|
|
|
|
|
} |
121
|
0
|
0
|
|
|
|
0
|
if(defined($params{consumer_key})) { |
122
|
0
|
|
|
|
|
0
|
$consumer_key = $params{consumer_key}; |
123
|
|
|
|
|
|
|
} |
124
|
0
|
0
|
|
|
|
0
|
if(defined($params{consumer_secret})) { |
125
|
0
|
|
|
|
|
0
|
$consumer_secret = $params{consumer_secret}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub import { |
130
|
|
|
|
|
|
|
# my $class = shift; |
131
|
1
|
|
|
1
|
|
10
|
shift; |
132
|
|
|
|
|
|
|
|
133
|
1
|
50
|
|
|
|
14
|
return unless @_; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
_init(@_); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 AUTHOR |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Nigel Horne, C<< >> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 BUGS |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Twitter only allows 150 requests per hour. If you exceed that, |
145
|
|
|
|
|
|
|
C won't validate and will assume all ID's are valid. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
148
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
149
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 SEE ALSO |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
CGI::Untaint |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 SUPPORT |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
perldoc CGI::Untaint::Twitter |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
You can also look for information at: |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=over 4 |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * CPAN Ratings |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * Search CPAN |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Copyright 2012,2013 Nigel Horne. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This program is released under the following licence: GPL |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
1; # End of CGI::Untaint::Twitter |