line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Twitter::Badge; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21938
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
87
|
|
6
|
1
|
|
|
1
|
|
1190
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
110080
|
|
|
1
|
|
|
|
|
1091
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
12
|
0
|
|
|
|
|
|
my %args = @_; |
13
|
0
|
0
|
|
|
|
|
$args{screen_name} = undef unless defined $args{screen_name}; |
14
|
0
|
0
|
|
|
|
|
$args{id} = undef unless defined $args{id}; |
15
|
0
|
0
|
|
|
|
|
$args{ua} = 'Mozilla/4.0;Twitter::Badge' unless defined $args{ua}; |
16
|
0
|
|
|
|
|
|
$args{name} = undef; |
17
|
0
|
|
|
|
|
|
$args{text} = undef; |
18
|
0
|
|
|
|
|
|
$args{profile_image_url} = undef; |
19
|
0
|
|
|
|
|
|
$args{followers_count} = undef; |
20
|
0
|
|
|
|
|
|
$args{created_at} = undef; |
21
|
0
|
|
|
|
|
|
return bless {%args}, $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub get_id_from_screen_name { |
25
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
26
|
0
|
|
|
|
|
|
my $screen_name = shift; |
27
|
0
|
|
|
|
|
|
$self->{screen_name} = $screen_name; |
28
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(agent => $self->{ua}); |
29
|
0
|
|
|
|
|
|
my $response = $ua->get('http://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name='.$self->{screen_name}); |
30
|
0
|
0
|
|
|
|
|
if ($response->is_success) { |
31
|
0
|
|
|
|
|
|
my $xml = $response->content; |
32
|
0
|
|
|
|
|
|
$xml =~ s!\n!!g; |
33
|
0
|
0
|
|
|
|
|
if ($xml =~ m!.*?.*?(\d+).*?.*?!) { |
34
|
0
|
|
|
|
|
|
$self->{id} = $1; |
35
|
|
|
|
|
|
|
} else { |
36
|
0
|
|
|
|
|
|
undef $self->{id}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} else { |
39
|
0
|
|
|
|
|
|
undef $self->{id}; |
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
|
return $self->{id}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub fetch { |
45
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
46
|
0
|
0
|
0
|
|
|
|
if (!defined($self->{id}) && !defined $self->{screen_name}) { |
47
|
0
|
|
|
|
|
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
# Check for ID or screen_name |
50
|
0
|
|
|
|
|
|
my $id_or_screen_name; |
51
|
0
|
0
|
|
|
|
|
if (defined($self->{screen_name})) { |
52
|
0
|
|
|
|
|
|
$id_or_screen_name = 'screen_name='.$self->{screen_name}; |
53
|
|
|
|
|
|
|
} else { |
54
|
0
|
|
|
|
|
|
$id_or_screen_name = 'id='.$self->{id}; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(agent => $self->{ua}); |
57
|
0
|
|
|
|
|
|
my $response = $ua->get('http://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&'.$id_or_screen_name); |
58
|
0
|
0
|
|
|
|
|
if ($response->is_success) { |
59
|
0
|
|
|
|
|
|
my $xml = $response->content; |
60
|
0
|
|
|
|
|
|
$xml =~ s!\n!!g; |
61
|
0
|
0
|
|
|
|
|
if ($xml =~ m!(.+?)!) { |
62
|
0
|
|
|
|
|
|
$xml = $1; |
63
|
|
|
|
|
|
|
# Get data |
64
|
0
|
|
|
|
|
|
($self->{text}) = ($xml =~ m!(.*)!); |
65
|
0
|
0
|
|
|
|
|
if (!defined($self->{id})) { |
66
|
0
|
|
|
|
|
|
$self->{id} = ($xml =~ m!.*?(\d+).*?!); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
($self->{name}) = ($xml =~ m!.*?(.*).*?!); |
69
|
0
|
|
|
|
|
|
($self->{screen_name}) = ($xml =~ m!.*?(.*).*?!); |
70
|
0
|
|
|
|
|
|
($self->{profile_image_url}) = ($xml =~ m!.*?(.*).*?!); |
71
|
0
|
|
|
|
|
|
($self->{followers_count}) = ($xml =~ m!.*?(.*).*?!); |
72
|
0
|
|
|
|
|
|
($self->{created_at}) = ($xml =~ m!.*?(.*).*?!); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} else { |
75
|
0
|
|
|
|
|
|
croak $response->status_line; |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
return $self; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub screen_name { |
81
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
82
|
0
|
0
|
|
|
|
|
if (@_) { |
83
|
0
|
|
|
|
|
|
$self->{screen_name} = shift; |
84
|
0
|
|
|
|
|
|
$self->{id} = $self->get_id_from_screen_name($self->{screen_name}); |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
|
return $self->{screen_name}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub id { |
90
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
91
|
0
|
0
|
|
|
|
|
if (@_) { $self->{id} = shift; } |
|
0
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return $self->{id}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub ua { |
96
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
97
|
0
|
0
|
|
|
|
|
if (@_) { $self->{ua} = shift; } |
|
0
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return $self->{ua}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub name { |
102
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
103
|
0
|
|
|
|
|
|
return $self->{name}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub text { |
107
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
108
|
0
|
|
|
|
|
|
return $self->{text}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub profile_image_url { |
112
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
113
|
0
|
|
|
|
|
|
return $self->{profile_image_url}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub followers_count { |
117
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
118
|
0
|
|
|
|
|
|
return $self->{followers_count}; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub created_at { |
122
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
123
|
0
|
|
|
|
|
|
return $self->{created_at}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
__END__ |