blib/lib/Net/Blogger/Engine/Slash.pm

filter: Statementstmt 22.7% 18 / 79 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 26.6% 4 / 15 Podpod 100% 9 / 9 totaltotal 22.4% 31 / 138 SCAR 52.4
CC
17
Cov
16%
getUserBlogs
20.0
getRecentPosts
20.0
newPost
12.0
CRAP 187.9
« blib/lib/Net/Blogger/Engine/Base.pm ↑ Summary blib/lib/Net/Blogger/Engine/Userland.pm »
1 {
2
3 1 =head1 NAME
4
5 Net::Blogger::Engine::Slash - Adds support for the Slashcode SOAP API.
6
7 =head1 SYNOPSIS
8
9 # Create object.
10 my $blogger = Net::Blogger->new(engine=>"slash",debug=>1);
11
12 # Same old, same old.
13 $blogger->Username(1234);
14 $blogger->Password("*****");
15 $blogger->Proxy("http://use.perl.org/journal.pl");
16
17 # Hey, this is different!
18 $blogger->Uri("http://use.perl.org/Slash/Journal/SOAP");
19
20 # This (the good old Blogger API) ...
21 $blogger->newPost(postbody=>\"hello\nworld");
22
23 # ...is the same as (slashcode API) ...
24 $blogger->slash()->add_entry(subject=>"hello",body=>"world");
25
26 =head1 DESCRIPTION
27
28 Net::Blogger::Engine::Slash allows a program to interact with the Slashcode
29 SOAP API using the Blogger API. Neat, huh?
30
31 =cut
32
33 package Net::Blogger::Engine::Slash;
34 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
35
36 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use Net::Blogger::Engine::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
38
39 1 ▶use CGI qw (unescape);
Subroutine BEGIN: called CC=1 SCAR=0.0
40
41 1 $Net::Blogger::Engine::Slash::VERSION = '1.0';
42
43 1 @Net::Blogger::Engine::Slash::ISA = qw ( Net::Blogger::Engine::Base );
44 1 @Net::Blogger::Engine::Slash::EXPORT = qw ();
45 1 @Net::Blogger::Engine::Slash::EXPORT_OK = qw ();
46
47 =head1 Blogger API OBJECT METHODS
48
49 =cut
50
51 =head2 $pkg->getUserBlogs()
52
53 =cut
54
55 sub getUserBlogs {
56 0 ▶ my $self = shift;
Subroutine getUserBlogs: not called CC=4 SCAR=30.0
Pod documented
57
58 0 ▶ if ((! $self->{'__blogs'}) || (! $self->{'__blogs'}->[0]->{'blogName'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"__blogs"} and $self->{"__blogs"}[0]{"blogName"}) 0 0 0
Condition0%0/3
$self->{"__blogs"} and $self->{"__blogs"}[0]{"blogName"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"__blogs"} and $self->{"__blogs"}[0]{"blogName"}
$self->{"__blogs"} $self->{"__blogs"}[0]{"blogName"}
Truth table0%0/3
A and B
A= $self->{"__blogs"}B= $self->{"__blogs"}[0]{"blogName"}
ABresult
0X0
100
111
59
60 0 my $post = $self->slash()->get_entries($self->Username(),1);
61
62 0 ▶ if (ref($post) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $post eq 'ARRAY') { } 0 0 0
63 0 $post = $post->[0];
64
65 0 $post->{'url'} =~ /^((.*)\/~(.*)\/journal)\/(\d+)$/;
66
67 0 my $url = $1;
68 0 my $name = &CGI::unescape($3);
69
70 # hack
71 0 $self->{'__blogs'} = [
72 {
73 blogid => $self->Username(),
74 url => $url,
75 blogName => $name."'s journal",
76 },
77 ];
78 }
79
80 # hack hack hack
81 0 else { $self->{'__blogs'} = [{ blogid => $self->Username() }]; }
82 }
83
84 0 return $self->{'__blogs'};
85 }
86
87 =head2 $pkg->newPost(\%args)
88
89 Releases prior to Net::Blogger 0.85 accepted a list of arguments
90 rather than a reference. Version 0.85+ are backwards compatible.
91
92 =cut
93
94 sub newPost {
95 0 ▶ my $self = shift;
Subroutine newPost: not called CC=3 SCAR=24.8
Pod documented
96 0 ▶ my $args = (ref($_[0]) eq "HASH") ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
97
98 0 ▶ if (! $self->check_newPost($args)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->check_newPost($args)) 0 0 0
99 0 return 0;
100 }
101
102 0 return $self->slash()->add_entry(&_bloggerpost2slash($args->{'postbody'}));
103 }
104
105 =head2 $pkg->getPost($postid)
106
107 =cut
108
109 sub getPost {
110 0 ▶ my $self = shift;
Subroutine getPost: not called CC=3 SCAR=24.8
Pod documented
111 0 my $postid = shift;
112
113 0 ▶ if (! $self->check_getPost($postid)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->check_getPost($postid)) 0 0 0
114 0 return 0;
115 }
116
117 0 my $post = $self->slash()->get_entry($postid);
118
119 0 ▶ return ($post) ? &_slashpost2blogger($post) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$post ? : 0 0 0
120 }
121
122 =head2 $pkg->getRecentPosts(\%args)
123
124 Releases prior to Net::Blogger 0.85 accepted a list of arguments
125 rather than a reference. Version 0.85+ are backwards compatible.
126
127 =cut
128
129 sub getRecentPosts {
130 0 ▶ my $self = shift;
Subroutine getRecentPosts: not called CC=4 SCAR=30.0
Pod documented
131 0 ▶ my $args = (ref($_[0]) eq "HASH") ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
132
133 0 ▶ if (! $self->check_getRecentPosts($args)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->check_getRecentPosts($args)) 0 0 0
134 0 return (0);
135 }
136
137 0 my $posts = $self->slash()->get_entries($self->Username(),$args->{'numposts'});
138
139 0 ▶ if (! $posts ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($posts) 0 0 0
140 0 return (0);
141 }
142
143 0 map { $_ = &_slashpost2blogger($_); } @$posts;
144
145 0 return (1,@$posts);
146 }
147
148 =head2 $pkg->editPost(\%args)
149
150 Releases prior to Net::Blogger 0.85 accepted a list of arguments
151 rather than a reference. Version 0.85+ are backwards compatible.
152
153 =cut
154
155 sub editPost {
156 0 ▶ my $self = shift;
Subroutine editPost: not called CC=3 SCAR=24.8
Pod documented
157 0 ▶ my $args = (ref($_[0]) eq "HASH") ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
158
159 0 ▶ if (! $self->check_editPost($args)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->check_editPost($args)) 0 0 0
160 0 return 0;
161 }
162
163 0 return $self->slash()->modify_entry($args->{'postid'},&_bloggerpost2slash($args->{'postbody'}));
164 }
165
166 =head2 $pkg->deletePost(\%args)
167
168 Releases prior to Net::Blogger 0.85 accepted a list of arguments
169 rather than a reference. Version 0.85+ are backwards compatible.
170
171 =cut
172
173 sub deletePost {
174 0 ▶ my $self = shift;
Subroutine deletePost: not called CC=3 SCAR=24.8
Pod documented
175 0 ▶ my $args = (ref($_[0]) eq "HASH") ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
176
177 0 ▶ if (! $self->check_deletePost($args)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->check_deletePost($args)) 0 0 0
178 0 return 0;
179 }
180
181 0 return $self->slash()->delete_entry($args->{'postid'});
182 }
183
184 =head2 $pkg->setTemplate()
185
186 This method is not supported by the I<Slash> engine.
187
188 =cut
189
190 sub setTemplate {
191 0 ▶ my $self = shift;
Subroutine setTemplate: not called CC=1 SCAR=6.9
Pod documented
192 0 $self->LastError("This method is not supported by the Slash engine.");
193 0 return undef;
194 }
195
196 =head2 $pkg->getTemplate()
197
198 This method is not supported by the I<Slash> engine.
199
200 =cut
201
202 sub getTemplate {
203 0 ▶ my $self = shift;
Subroutine getTemplate: not called CC=1 SCAR=6.9
Pod documented
204 0 $self->LastError("This method is not supported by the Slash engine.");
205 0 return undef;
206 }
207
208 =head1 Slashcode API METHODS
209
210 =cut
211
212 =head2 $pkg->slash()
213
214 Returns an object. Woot!
215
216 =cut
217
218 sub slash {
219 0 ▶ my $self = shift;
Subroutine slash: not called CC=2 SCAR=17.9
Pod documented
220
221 0 ▶ if (! $self->{'__slash'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"__slash"}) 0 0 0
222
223 0 require Net::Blogger::Engine::Slash::slashcode;
224 0 my $slash = Net::Blogger::Engine::Slash::slashcode->new(debug=>$self->{debug});
225
226 # Note that the order in which these items
227 # are passed matters. This is so that the
228 # $slash object has a valid username/password
229 # when it creates the cookie required by the
230 # Slash server.
231
232 0 map { $slash->$_($self->$_()); } qw (BlogId Username Password Proxy Uri);
233 0 $self->{'__slash'} = $slash;
234 }
235
236 0 return $self->{'__slash'};
237 }
238
239 sub _bloggerpost2slash {
240 0 ▶ my @post = split("\n",${$_[0]});
Subroutine _bloggerpost2slash: not called CC=2 SCAR=17.9
241
242 return (
243 0 ▶ subject => $post[0],
Branch: 1 branch
BranchTrueFalseTotal
scalar @post > 1 ? : 0 0 0
244 body => ((scalar(@post) > 1) ? join("\n",@post[1..$#post]) : $post[0]),
245 );
246 }
247
248 sub _slashpost2blogger {
249 0 ▶ my $post = shift;
Subroutine _slashpost2blogger: not called CC=1 SCAR=6.9
250 return {
251 postid => $post->{'id'},
252 userid => $post->{'uid'},
253 dateCreated => $post->{'date'},
254 0 content => join("\n",$post->{'subject'},$post->{'body'}),
255 };
256 }
257
258 =head1 VERSION
259
260 1.0
261
262 =head1 DATE
263
264 $Date: 2005/03/26 19:29:08 $
265
266 =head1 AUTHOR
267
268 Aaron Straup Cope
269
270 =head1 SEE ALSO
271
272 L<Net::Blogger::Engine::Slash::slashcode>
273
274 =head1 LICENSE
275
276 Copyright (c) 2002-2005, Aaron Straup Cope. All Rights Reserved.
277
278 This is free software, you may use it and distribute it under the same terms as Perl itself.
279
280 =cut
281
282 1 return 1;
283
284 }
« blib/lib/Net/Blogger/Engine/Base.pm ↑ Summary blib/lib/Net/Blogger/Engine/Userland.pm »