line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Twittervision; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
34974
|
use 5.008000; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
45
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
112
|
|
7
|
1
|
|
|
1
|
|
2435
|
use LWP; |
|
1
|
|
|
|
|
86875
|
|
|
1
|
|
|
|
|
36
|
|
8
|
1
|
|
|
1
|
|
1283
|
use JSON; |
|
1
|
|
|
|
|
15182
|
|
|
1
|
|
|
|
|
7
|
|
9
|
1
|
|
|
1
|
|
225
|
use URI::Escape; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
86
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION $DEBUG $TVURL); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
889
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
14
|
|
|
|
|
|
|
$TVURL = 'http://api.twittervision.com'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
1
|
|
|
1
|
1
|
13
|
my $class = shift; |
18
|
1
|
|
|
|
|
2
|
my $self = shift; |
19
|
1
|
|
|
|
|
4
|
my %hash = @_; |
20
|
|
|
|
|
|
|
|
21
|
1
|
50
|
|
|
|
6
|
(exists($hash{url})) ? $self->{url} = $hash{url} : $self->{url} = $TVURL; |
22
|
1
|
50
|
|
|
|
5
|
(exists($hash{debug})) ? $DEBUG = $hash{debug} : 0; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
3
|
bless $self, $class; |
25
|
1
|
|
|
|
|
4
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub current_status { |
29
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
30
|
0
|
|
|
|
|
0
|
my %hash = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
my $screen_name = ""; |
33
|
0
|
0
|
|
|
|
0
|
(exists($hash{screen_name})) ? $screen_name = $hash{screen_name} : croak('Needs a screen name'); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
my $req_url = $self->{url} . '/user/current_status/' . $screen_name . '.json'; |
36
|
0
|
|
|
|
|
0
|
my $req = HTTP::Request->new(GET => $req_url); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
0
|
my $ua = LWP::UserAgent->new; |
39
|
0
|
|
|
|
|
0
|
my $res = $ua->request($req); |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
0
|
if (!$res->is_success) { |
42
|
0
|
|
|
|
|
0
|
carp('Unable to access ' . $req_url); |
43
|
0
|
|
|
|
|
0
|
return undef; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
my $json = new JSON; |
47
|
0
|
|
|
|
|
0
|
my $data = $json->decode($res->content); |
48
|
0
|
|
|
|
|
0
|
return $data; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub update_status { |
52
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
53
|
0
|
|
|
|
|
0
|
my %hash = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
my $screen_name; |
56
|
|
|
|
|
|
|
my $password; |
57
|
0
|
|
|
|
|
0
|
my $location; |
58
|
0
|
0
|
|
|
|
0
|
(exists($hash{screen_name})) ? $screen_name = $hash{screen_name} : croak('Needs a screen name'); |
59
|
0
|
0
|
|
|
|
0
|
(exists($hash{password})) ? $password = $hash{password} : croak('Needs a password'); |
60
|
0
|
0
|
|
|
|
0
|
(exists($hash{location})) ? $location = $hash{location} : croak('Needs a location'); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
$location = uri_escape($location); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
my $req_url = $self->{url} . '/user/update_location.json?location=' . $location; |
65
|
0
|
|
|
|
|
0
|
print "$req_url\n"; |
66
|
0
|
|
|
|
|
0
|
my $req = HTTP::Request->new(POST => $req_url);#, [location => $location]); |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
my $ua = LWP::UserAgent->new; |
69
|
0
|
|
|
|
|
0
|
push @{ $ua->requests_redirectable }, 'POST'; |
|
0
|
|
|
|
|
0
|
|
70
|
0
|
|
|
|
|
0
|
$ua->credentials( |
71
|
|
|
|
|
|
|
'twittervision.com:80', |
72
|
|
|
|
|
|
|
'Web Password', |
73
|
|
|
|
|
|
|
$screen_name, |
74
|
|
|
|
|
|
|
$password |
75
|
|
|
|
|
|
|
); |
76
|
0
|
|
|
|
|
0
|
my $res = $ua->request($req); |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
0
|
if (!$res->is_success) { |
79
|
0
|
|
|
|
|
0
|
carp('Unable to access ' . $req_url . ": " . $res->status_line . ": " . $res->header('WWW-Authenticate')); |
80
|
0
|
|
|
|
|
0
|
return undef; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
my $json = new JSON; |
84
|
0
|
|
|
|
|
0
|
my $data = $json->decode($res->content); |
85
|
0
|
|
|
|
|
0
|
return $data; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub parse_location { |
90
|
7
|
|
|
7
|
1
|
4693
|
my $self = shift; |
91
|
7
|
|
|
|
|
18
|
my %hash = @_; |
92
|
|
|
|
|
|
|
|
93
|
7
|
|
|
|
|
12
|
my $message = ""; |
94
|
7
|
50
|
|
|
|
22
|
(exists($hash{message})) ? $message = $hash{message} : croak('Needs a message string'); |
95
|
|
|
|
|
|
|
|
96
|
7
|
|
|
|
|
12
|
my @locations = (); |
97
|
7
|
|
|
|
|
53
|
while($message =~ s/[lL]:([a-zA-Z]+=)?\s*([^:]+)?:?//) { |
98
|
10
|
|
|
|
|
50
|
push(@locations, $2); |
99
|
|
|
|
|
|
|
} |
100
|
7
|
|
|
|
|
31
|
return @locations; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub strip_location { |
104
|
7
|
|
|
7
|
1
|
7326
|
my $self = shift; |
105
|
7
|
|
|
|
|
20
|
my %hash = @_; |
106
|
|
|
|
|
|
|
|
107
|
7
|
|
|
|
|
12
|
my $message = ""; |
108
|
7
|
50
|
|
|
|
21
|
(exists($hash{message})) ? $message = $hash{message} : croak('Needs a message string'); |
109
|
|
|
|
|
|
|
|
110
|
7
|
|
|
|
|
12
|
my @locations = (); |
111
|
7
|
|
|
|
|
51
|
$message =~ s/[lL]:([a-zA-Z]+=)?\s*([^:]+)?:?//g; |
112
|
7
|
|
|
|
|
22
|
$message =~ s/\s\s*/ /g; |
113
|
7
|
|
|
|
|
23
|
$message =~ s/^\s*//; |
114
|
7
|
|
|
|
|
31
|
$message =~ s/\s*$//; |
115
|
|
|
|
|
|
|
|
116
|
7
|
|
|
|
|
23
|
return $message; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
__END__ |