blib/lib/Net/Blogger/Engine/Movabletype/mt.pm

filter: Statementstmt 24.5% 15 / 61 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 30.0% 3 / 10 Podpod 85.7% 6 / 7 totaltotal 20.8% 24 / 115 SCAR 55.7
CC
20
Cov
15%
setPostCategories
56.0
getRecentPostTitles
42.0
getPostCategories
20.0
CRAP 261.6
« blib/lib/Net/Blogger/API/Extended.pm ↑ Summary blib/lib/Net/Blogger/Engine/Base.pm »
1 {
2
3 1 =head1 NAME
4
5 mt - Adds support for the MovableType XML-RPC API
6
7 =head1 SYNOPSIS
8
9 use Net::Blogger;
10
11 use Carp;
12 use Data::Dumper;
13
14 my $mt = Net::Blogger->new(engine=>"movabletype");
15
16 $mt->Proxy("http://yaddayadda.com/mt-xmlrpc.cgi");
17 $mt->Username("asc");
18 $mt->Password("*****");
19 $mt->BlogId(123);
20
21 $mt->newPost(postbody=>\&fortune(),publish=>1)
22 || croak $mt->LastError();
23
24 my $id = $mt->metaWeblog()->newPost(title=>"test:".time,
25 description=>&fortune(),
26 publish=>1)
27 || croak $mt->LastError();
28
29 my $categories = $mt->mt()->getCategoryList()
30 || croak $mt->LastError();
31
32 my $cid = $categories->[0]->{categoryId};
33
34 $mt->mt()->setPostCategories(postid=>$id,
35 categories=>[{categoryId=>$cid}])
36 || croak $mt->LastError();
37
38 print &Dumper($mt->mt()->getPostCategories(postid=>$id));
39
40 sub fortune {
41 local $/;
42 undef $/;
43
44 system ("fortune > /home/asc/tmp/fortune");
45
46 open F, "</home/asc/tmp/fortune";
47 my $fortune = <F>;
48 close F;
49
50 return $fortune;
51 }
52
53 =head1 DESCRIPTION
54
55 Adds support for the MovableType XML-RPC API
56
57 =cut
58
59 package Net::Blogger::Engine::Movabletype::mt;
60 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
61
62 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 1 ▶use Net::Blogger::Engine::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
64
65 1 $Net::Blogger::Engine::Movabletype::mt::VERSION = '1.0';
66
67 1 @Net::Blogger::Engine::Movabletype::mt::ISA = qw ( Exporter Net::Blogger::Engine::Base );
68 1 @Net::Blogger::Engine::Movabletype::mt::EXPORT = qw ();
69 1 @Net::Blogger::Engine::Movabletype::mt::EXPORT_OK = qw ();
70
71 =head1 OBJECT METHODS
72
73 =cut
74
75 =head2 $obj->getRecentPostTitles(\%args)
76
77 Valid arguments are :
78
79 =over 4
80
81 =item *
82
83 B<count>
84
85 Int.
86
87 The number of post titles to fetch. Default is I<20>
88
89 =item *
90
91 B<asc>
92
93 Boolean.
94
95 As in: return data ordered by ascending date. By default, items are
96 returned 'most recent first'.
97
98 =back
99
100 Returns an array ref of hash refs. Each hash ref contains the following
101 keys :
102
103 =over 4
104
105 =item *
106
107 B<postid>
108
109 =item *
110
111 B<userid>
112
113 =item *
114
115 B<title>
116
117 String.
118
119 =item *
120
121 B<dateCreated>
122
123 String, formatted as a W3CDTF datetime.
124
125 =back
126
127 This method was introduced in Net::Blogger 0.86 and does B<not> accept
128 arguments passed as a list. They B<must> be passed by reference.
129
130 =cut
131
132 sub getRecentPostTitles {
133 0 ▶ my $self = shift;
Subroutine getRecentPostTitles: not called CC=6 SCAR=37.4
Pod documented
134 0 my $args = shift;
135
136 # Translate numbers for humans
137 # to zero-based count.
138
139 0 my $count = 19;
140
141 0 ▶ if (exists($args->{count})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"count"}) 0 0 0
142 0 $count = ($args->{count} - 1);
143 }
144
145 #
146
147 0 ▶ my $call = $self->_Client()->call(
Condition0%0/2
$_[0] || 20
l!l
00
MC/DC0%0/1
$_[0] || 20
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
148 "mt.getRecentPostTitles",
149 $self->_Type(string=>$self->BlogId()),
150 $self->_Type(string=>$self->Username()),
151 $self->_Type(string=>$self->Password()),
152 $self->_Type((int=>$_[0] || 20)),
153 );
154
155 #
156
157 0 ▶ if (! exists($args->{asc})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $args->{'asc'}) { } 0 0 0
elsif (not $call) { } 0 0 0
158 0 ▶ return ($call) ? $call->result() : undef;
Branch: 1 branch
BranchTrueFalseTotal
$call ? : 0 0 0
159 }
160
161 elsif (! $call) {
162 0 return undef;
163 }
164
165 else {
166 0 return [ reverse @{$call->result()} ];
167 }
168 }
169
170 =head2 $obj->getCategoryList()
171
172 Returns an array ref of hash references.
173
174 =cut
175
176 sub getCategoryList {
177 0 ▶ my $self = shift;
Subroutine getCategoryList: not called CC=2 SCAR=17.9
Pod documented
178
179 0 my $call = $self->_Client()->call(
180 "mt.getCategoryList",
181 $self->_Type(string=>$self->BlogId()),
182 $self->_Type(string=>$self->Username()),
183 $self->_Type(string=>$self->Password()),
184 );
185
186 0 ▶ return ($call) ? $call->result() : undef;
Branch: 1 branch
BranchTrueFalseTotal
$call ? : 0 0 0
187 }
188
189 =head2 $obj->getPostCategories(\%args)
190
191 Valid arguments are
192
193 =over
194
195 =item *
196
197 B<postid>
198
199 String. I<required>
200
201 =back
202
203 Releases prior to Net::Blogger 0.85 accepted a list of arguments
204 rather than a reference. Version 0.85+ are backwards compatible.
205
206 Returns an array ref of hash references
207
208 =cut
209
210 sub getPostCategories {
211 0 ▶ my $self = shift;
Subroutine getPostCategories: not called CC=4 SCAR=30.0
Pod documented
212 0 ▶ my $args = (ref($_[0]) eq "HASH") ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
213
214 0 ▶ if (! $args->{'postid'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"postid"}) 0 0 0
215 0 $self->LastError("You must specify a postid");
216 0 return undef;
217 }
218
219 my $call = $self->_Client()->call(
220 "mt.getPostCategories",
221 0 $self->_Type(string=>$args->{'postid'}),
222 $self->_Type(string=>$self->Username()),
223 $self->_Type(string=>$self->Password()),
224 );
225
226 0 ▶ return ($call) ? $call->result() : undef;
Branch: 1 branch
BranchTrueFalseTotal
$call ? : 0 0 0
227 }
228
229 =head2 $obj->setPostCategories(\%args)
230
231 Valid argument are
232
233 =over
234
235 =item *
236
237 B<postid>
238
239 String. Required
240
241 B<categories>
242
243 Array ref. I<required>
244
245 The MT docs state that :
246
247 =over 4
248
249 =item *
250
251 The array categories is an array of structs containing
252
253 =over 4
254
255 =item *
256
257 B<categoryId>
258
259 String.
260
261 =item *
262
263 B<isPrimary>
264
265 Using isPrimary to set the primary category is optional--in the absence of
266 this flag, the first struct in the array will be assigned the primary category for
267 the post
268
269 =back
270
271 =back
272
273 =back
274
275 Releases prior to Net::Blogger 0.85 accepted a list of arguments
276 rather than a reference. Version 0.85+ are backwards compatible.
277
278 Returns true or false
279
280 =cut
281
282 sub setPostCategories {
283 0 ▶ my $self = shift;
Subroutine setPostCategories: not called CC=7 SCAR=40.3
Pod documented
284 0 ▶ my $args = (ref($_[0]) eq "HASH") ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
285
286 0 ▶ if (! $args->{'postid'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args->{"postid"}) 0 0 0
287 0 $self->LastError("You must specify a postid");
288 0 return undef;
289 }
290
291 0 ▶ if (ref($args->{'categories'}) ne "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args->{"categories"} ne "ARRAY") 0 0 0
292 0 $self->LastError("You must pass category data as an array reference.");
293 0 return undef;
294 }
295
296 0 foreach my $struct (@{$args->{'categories'}}) {
297 0 ▶ if (! $struct->{'categoryId'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($struct->{"categoryId"}) 0 0 0
298 0 $self->LastError("Category struct requires a categoryId.");
299 0 return undef;
300 }
301 }
302
303 my $call = $self->_Client()->call(
304 "mt.setPostCategories",
305 $self->_Type(string=>$args->{'postid'}),
306 $self->_Type(string=>$self->Username()),
307 $self->_Type(string=>$self->Password()),
308 0 $self->_Type(array=>$args->{'categories'}),
309 );
310
311 0 ▶ return ($call) ? $call->result() : undef;
Branch: 1 branch
BranchTrueFalseTotal
$call ? : 0 0 0
312 }
313
314 =head2 $obj->getTrackbackPings(\%args)
315
316 =over 4
317
318 =item * *
319
320 B<postid>
321
322 String.
323
324 =back
325
326 Returns an array reference of hash references who keys are :
327
328 =over 4
329
330 =item *
331
332 I<pingTitle>
333
334 =item *
335
336 I<pingURL>
337
338 =item *
339
340 I<pingIP>
341
342 =back
343
344 Releases prior to Net::Blogger 0.85 accepted a list of arguments
345 rather than a reference. Version 0.85+ are backwards compatible.
346
347 =cut
348
349 sub getTrackbackPings {
350 0 ▶ my $self = shift;
Subroutine getTrackbackPings: not called CC=3 SCAR=24.8
Pod documented
351 0 ▶ my $args = (ref($_[0]) eq "HASH") ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
352 my $call = $self->_Client()->call(
353 "mt.getTrackbackPings",
354 0 $self->_Type(string=>$args->{'postid'})
355 );
356
357 0 ▶ return ($call) ? $call->result() : undef;
Branch: 1 branch
BranchTrueFalseTotal
$call ? : 0 0 0
358 }
359
360 =head2 $obj->supportMethods()
361
362 Returns an array reference.
363
364 =cut
365
366 sub supportedMethods {
367 0 ▶ my $self = shift;
Subroutine supportedMethods: not called CC=2 SCAR=17.9
Pod undocumented
368 0 my $call = $self->_Client()->call("mt.setPostCategories");
369 0 ▶ return ($call) ? $call->result() : undef;
Branch: 1 branch
BranchTrueFalseTotal
$call ? : 0 0 0
370 }
371
372 =head2 $obj->publishPost($postid)
373
374 Returns true or false.
375
376 =cut
377
378 sub publishPost {
379 0 ▶ my $self = shift;
Subroutine publishPost: not called CC=2 SCAR=17.9
Pod documented
380
381 0 my $call = $self->_Client()->call(
382 "mt.publishPost",
383 $self->_Type(int=>$_[0]),
384 $self->_Type(string=>$self->Username()),
385 $self->_Type(string=>$self->Password()),
386 );
387
388 0 ▶ return ($call) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$call ? : 0 0 0
389 }
390
391 =head1 VERSION
392
393 1.0
394
395 =head1 DATE
396
397 $Date: 2005/03/26 19:29:08 $
398
399 =head1 AUTHOR
400
401 Aaron Straup Cope
402
403 =head1 SEE ALSO
404
405 L<Net::Blogger::Engine::Base>
406
407 http://www.movabletype.org/mt-static/docs/mtmanual_programmatic.html#xmlrpc%20api
408
409 =head1 LICENSE
410
411 Copyright (c) 2002-2005, Aaron Straup Cope. All Rights Reserved.
412
413 This is free software, you may use it and distribute it under the same terms as Perl itself.
414
415 =cut
416
417 1 return 1;
418
419 }
« blib/lib/Net/Blogger/API/Extended.pm ↑ Summary blib/lib/Net/Blogger/Engine/Base.pm »