line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::LiveJournal; |
2
|
1
|
|
|
1
|
|
36797
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
578
|
use Net::LiveJournal::Entry; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
6
|
use Carp qw(croak); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
6
|
1
|
|
|
1
|
|
2732
|
use LWP; |
|
1
|
|
|
|
|
115198
|
|
|
1
|
|
|
|
|
45
|
|
7
|
1
|
|
|
1
|
|
12
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
8
|
1
|
|
|
1
|
|
7
|
use HTTP::Request; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
9
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
985
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.27'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
|
my ($class, %opts) = @_; |
14
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
0
|
|
|
|
$self->{server} = delete $opts{server} || "www.livejournal.com"; |
17
|
0
|
|
0
|
|
|
|
$self->{user} = delete $opts{user} || delete $opts{username}; |
18
|
0
|
|
0
|
|
|
|
$self->{password} = delete $opts{pass} || delete $opts{password}; |
19
|
0
|
0
|
|
|
|
|
croak("Unknown options: " . join(", ", %opts)) if %opts; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub ua { |
25
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
26
|
0
|
|
0
|
|
|
|
return $self->{ua} ||= do { |
27
|
0
|
|
|
|
|
|
LWP::UserAgent->new(agent => "Net::LiveJournal"); |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub post { |
32
|
0
|
|
|
0
|
0
|
|
my ($self, $entry) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
0
|
|
|
|
my $params = { |
35
|
|
|
|
|
|
|
mode => "postevent", |
36
|
|
|
|
|
|
|
user => $self->{user} || croak("No username provided in the Net::LiveJournal ($self) object"), |
37
|
|
|
|
|
|
|
password => $self->{password}, |
38
|
|
|
|
|
|
|
version => 1, |
39
|
|
|
|
|
|
|
event => $entry->body, |
40
|
|
|
|
|
|
|
subject => $entry->subject, |
41
|
|
|
|
|
|
|
security => $entry->security, |
42
|
|
|
|
|
|
|
allowmask => $entry->allowmask, |
43
|
|
|
|
|
|
|
year => $entry->year, |
44
|
|
|
|
|
|
|
mon => $entry->month, |
45
|
|
|
|
|
|
|
day => $entry->day, |
46
|
|
|
|
|
|
|
hour => $entry->hour, |
47
|
|
|
|
|
|
|
min => $entry->minute, |
48
|
|
|
|
|
|
|
usejournal => $entry->journal, |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
# TODO: props ("prop_") |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $ua = $self->ua; |
53
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new(POST => $self->_flat); |
54
|
0
|
|
|
|
|
|
$req->content(_encode($params)); |
55
|
0
|
|
|
|
|
|
my $res = _parse($ua->request($req)); |
56
|
0
|
0
|
|
|
|
|
return 0 unless $self->is_success($res); |
57
|
0
|
|
|
|
|
|
return $res->{url}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub errstr { |
61
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
62
|
0
|
|
|
|
|
|
return $self->{lasterrstr}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub is_success { |
66
|
0
|
|
|
0
|
0
|
|
my ($self, $res) = @_; |
67
|
0
|
|
|
|
|
|
$self->{lasterrstr} = undef; |
68
|
0
|
0
|
|
|
|
|
return 1 if $res->{success} eq "OK"; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$self->{lasterrstr} = $res->{errmsg}; |
71
|
0
|
|
|
|
|
|
return 0; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _parse { |
75
|
0
|
|
|
0
|
|
|
my $res = shift; |
76
|
0
|
0
|
|
|
|
|
return { success => "FAIL", errmsg => "Undefined response" } unless $res; |
77
|
0
|
|
|
|
|
|
my $ret = {}; |
78
|
0
|
0
|
|
|
|
|
unless ($res->is_success) { |
79
|
0
|
|
|
|
|
|
$ret->{success} = "FAIL"; |
80
|
0
|
|
|
|
|
|
$ret->{errmsg} = $res->status_line; |
81
|
0
|
|
|
|
|
|
return $ret; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
|
$ret = { split(/\n/, $res->content) }; |
84
|
0
|
|
|
|
|
|
return $ret; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _encode { |
88
|
0
|
|
|
0
|
|
|
my $val = shift; |
89
|
0
|
0
|
|
|
|
|
$val = "" unless defined $val; |
90
|
0
|
0
|
|
|
|
|
if (ref $val) { |
91
|
0
|
|
|
|
|
|
my $ret = ""; |
92
|
0
|
|
|
|
|
|
while (my ($k, $v) = each %$val) { |
93
|
0
|
|
|
|
|
|
$ret .= _encode($k) . "=" . _encode($v) . "&"; |
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
|
chop $ret; |
96
|
0
|
|
|
|
|
|
return $ret; |
97
|
|
|
|
|
|
|
} else { |
98
|
0
|
|
|
|
|
|
$val =~ s/([^a-zA-Z0-9_\,\-.\/\\\: ])/uc sprintf("%%%02x",ord($1))/eg; |
|
0
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$val =~ tr/ /+/; |
100
|
0
|
|
|
|
|
|
return $val; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _flat { |
105
|
0
|
|
|
0
|
|
|
my $self = shift; |
106
|
0
|
|
|
|
|
|
return "http://$self->{server}/interface/flat"; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |