LiveJournal.pm

filter: Statementstmt 35.1% 26 / 74 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 50.0% 8 / 16 Podpod 0.0% 0 / 5 totaltotal 25.7% 34 / 132 CC 14 SCAR 24.6
CC
14
Cov
25%
new
30.0
_encode
20.0
post
12.0
CRAP 11.7
« LiveJournal/Entry.pm ↑ Summary
1 package Net::LiveJournal;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Net::LiveJournal::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use LWP;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 $VERSION = '0.27';
11  
12 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
13 0 my ($class, %opts) = @_;
14 0 my $self = bless {}, $class;
15  
16 0 ▶ $self->{server} = delete $opts{server} || "www.livejournal.com";
Condition0%0/2
delete $opts{'server'} || 'www.livejournal.com'
l!l
00
MC/DC0%0/1
delete $opts{'server'} || 'www.livejournal.com'
delete $opts{'server'}
Truth table0%0/2
A
A= delete $opts{'server'}
Aresult
11
00
17 0 ▶ $self->{user} = delete $opts{user} || delete $opts{username};
Condition0%0/3
delete $opts{'user'} || delete $opts{'username'}
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opts{'user'} || delete $opts{'username'}
delete $opts{'user'} delete $opts{'username'}
Truth table0%0/3
A || B
A= delete $opts{'user'}B= delete $opts{'username'}
ABresult
1X1
011
000
18 0 ▶ $self->{password} = delete $opts{pass} || delete $opts{password};
Condition0%0/3
delete $opts{'pass'} || delete $opts{'password'}
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opts{'pass'} || delete $opts{'password'}
delete $opts{'pass'} delete $opts{'password'}
Truth table0%0/3
A || B
A= delete $opts{'pass'}B= delete $opts{'password'}
ABresult
1X1
011
000
19 0 ▶ croak("Unknown options: " . join(", ", %opts)) if %opts;
Branch: 1 branch
BranchTrueFalseTotal
if %opts 0 0 0
20  
21 0 return $self;
22 }
23  
24 0 ▶sub ua {
Subroutine ua: not called CC=2 SCAR=17.9
Pod undocumented
25 0 my $self = shift;
26 0 ▶ return $self->{ua} ||= do {
Condition0%0/3
$self->{"ua"} ||= do { "LWP::UserAgent"->new("agent", "Net::LiveJournal") }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ua"} ||= do { "LWP::UserAgent"->new("agent", "Net::LiveJournal") }
$self->{"ua"} do { "LWP::UserAgent"->new("agent", "Net::LiveJournal") }
Truth table0%0/3
A ||= B
A= $self->{"ua"}B= do { "LWP::UserAgent"->new("agent", "Net::LiveJournal") }
ABresult
1X1
011
000
27 0 LWP::UserAgent->new(agent => "Net::LiveJournal");
28 };
29 }
30  
31 0 ▶sub post {
Subroutine post: not called CC=3 SCAR=24.8
Pod undocumented
32 0 my ($self, $entry) = @_;
33  
34 my $params = {
35 mode => "postevent",
36 user => $self->{user} || croak("No username provided in the Net::LiveJournal ($self) object"),
37 password => $self->{password},
38 0 ▶ version => 1,
Condition0%0/2
$self->{'user'} || croak("No username provided in the Net::LiveJournal ($self) object")
l!l
00
MC/DC0%0/1
$self->{'user'} || croak("No username provided in the Net::LiveJournal ($self) object")
$self->{'user'}
Truth table0%0/2
A
A= $self->{'user'}
Aresult
11
00
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_<name>")
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 ▶ return 0 unless $self->is_success($res);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_success($res) 0 0 0
57 0 return $res->{url};
58 }
59  
60 0 ▶sub errstr {
Subroutine errstr: not called CC=1 SCAR=6.9
Pod undocumented
61 0 my $self = shift;
62 0 return $self->{lasterrstr};
63 }
64  
65 0 ▶sub is_success {
Subroutine is_success: not called CC=2 SCAR=17.9
Pod undocumented
66 0 my ($self, $res) = @_;
67 0 $self->{lasterrstr} = undef;
68 0 ▶ return 1 if $res->{success} eq "OK";
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"success"} eq "OK" 0 0 0
69  
70 0 $self->{lasterrstr} = $res->{errmsg};
71 0 return 0;
72 }
73  
74 0 ▶sub _parse {
Subroutine _parse: not called CC=3 SCAR=24.8
75 0 my $res = shift;
76 0 ▶ return { success => "FAIL", errmsg => "Undefined response" } unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
77 0 my $ret = {};
78 0 ▶ unless ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->is_success) 0 0 0
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 0 ▶sub _encode {
Subroutine _encode: not called CC=4 SCAR=30.0
88 0 my $val = shift;
89 0 ▶ $val = "" unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
90 0 ▶ if (ref $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val) { } 0 0 0
91 0 my $ret = "";
92 0 ▶ while (my ($k, $v) = each %$val) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$val) 0 0 0
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;
99 0 $val =~ tr/ /+/;
100 0 return $val;
101 }
102 }
103  
104 0 ▶sub _flat {
Subroutine _flat: not called CC=1 SCAR=6.9
105 0 my $self = shift;
106 0 return "http://$self->{server}/interface/flat";
107 }
108  
109 1 1;
110  
111 __END__
« LiveJournal/Entry.pm ↑ Summary