blib/lib/Net/Blogger.pm

filter: Statementstmt 29.0% 9 / 31 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 33.3% 2 / 6 Podpod 100% 2 / 2 totaltotal 24.5% 13 / 53 SCAR 31.6
CC
6
Cov
21%
init
30.0
new
6.0
DESTROY
2.0
CRAP 23.5
« blib/lib/Net/Blogger/Engine/Movabletype.pm ↑ Summary Build »
1 {
2
3 2 =head1 NAME
4
5 Net::Blogger - an OOP-ish interface for accessing a weblog via
6 the Blogger XML-RPC API.
7
8 =head1 SYNOPSIS
9
10 use Net::Blogger;
11 my $b = Net::Blogger->new(appkey=>APPKEY);
12
13 $b->BlogId(BLOGID);
14 $b->Username(USERNAME);
15 $b->Password(PASSWORD);
16
17 $b->BlogId($b->GetBlogId(blogname=>'superfoobar'));
18
19 # Get recent posts
20
21 my ($ok,@p) = $b->getRecentPosts(numposts=>20);
22
23 if (! $ok) {
24 croak $b->LastError();
25 }
26
27 map { print "\t $_->{'postid'}\n"; } @p;
28
29 # Post from a file
30
31 my ($ok,@p) = $b->PostFromFile(file=>"/usr/blogger-test");
32
33 if (! $ok) {
34 croak $b->LastError();
35 }
36
37 # Deleting posts
38
39 map {
40 $b->deletePost(postid=>"$_") || croak $b->LastError();
41 } @p;
42
43 # Getting and setting templates
44
45 my $t = $b->getTemplate(type => 'main');
46 $b->setTemplate(type=>'main',template=>\$t) || croak $b->LastError();
47
48 # New post
49
50 my $txt = "hello world.";
51 my $id = $b->newPost(postbody=>\$txt) || croak $b->LastError();
52
53 # Get post
54
55 my $post = $b->getPost($id) || croak $b->LastError();
56 print "Text for last post was $post->{'content'}\n";
57
58 =head1 DESCRIPTION
59
60 Blogger.pm provides an OOP-ish interface for accessing a weblog
61 via the Blogger XML-RPC API.
62
63 =head1 ENGINES
64
65 Blogger.pm relies on "engines" to implement it's functionality.
66 The Blogger.pm package itself is little more than a wrapper file
67 that happens to use a default "Blogger" engine is none other is
68 specified.
69
70 my $manila = Net::Blogger->new(engine=>"manila");
71
72 But wait!, you say. It's an API that servers implements and all I should have to
73 do is changed the login data. Why do I need an engine?
74
75 Indeed. Every server pretty much gets the spirit of the API right, but each implements
76 the details slightly differently. For example :
77
78 The MovableType XML-RPC server follows the spec for the I<getRecentPost> but because of
79 the way Perl auto-vivifies hashes it turns out you can slurp all the posts for a blog
80 rather than the just the 20 most recent.
81
82 The Userland Manila server doesn't support the I<getUsersBlogs> method; the Userland
83 RadioUserland server does.
84
85 The Blogger server imposes a limit on the maximum length of a post. Other servers don't.
86 (Granted the server in question will return a fault, if necessary, but Blogger.pm tries
87 to do the right thing and check for these sorts of things before adding to the traffic
88 on the network.)
89
90 Lots of weblog-like applications don't support the Blogger API but do have a traditional
91 REST interface. With the introduction of Blogger.pm "engines", support for these applications
92 via the API can be added with all the magic happening behind the curtain, so to speak.
93
94 =cut
95
96 package Net::Blogger;
97 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
98
99 2 ▶use vars qw ( $AUTOLOAD $LAST_ERROR );
Subroutine BEGIN: called CC=1 SCAR=0.0
100
101 2 $Net::Blogger::VERSION = '1.02';
102
103 =head1 PACKAGE METHODS
104
105 =cut
106
107 =head2 __PACKAGE__->new(\%args)
108
109 Instantiate a new Blogger object.
110
111 Valid arguments are :
112
113 =over 4
114
115 =item *
116
117 B<engine> (required)
118
119 String. Default is "blogger".
120
121 =item *
122
123 B<appkey>
124
125 String. The magic appkey for connecting to the Blogger XMLRPC server.
126
127 =item *
128
129 B<blogid>
130
131 String. The unique ID that Blogger uses for your weblog
132
133 =item *
134
135 B<username>
136
137 String. A valid username for blogid
138
139 =item *
140
141 B<password>
142
143 String. A valid password for the username/blogid pair.
144
145 =back
146
147 Releases prior to Net::Blogger 0.85 accepted a list of arguments
148 rather than a reference. Version 0.85+ are backwards compatible.
149
150 Returns an object. Woot!
151
152 =head2 __PACKAGE__->init()
153
154 Initializes the specified engine
155
156 =cut
157
158 sub new {
159 0 ▶ my $pkg = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
160 0 my $self = {};
161 0 bless $self,$pkg;
162 0 ▶ $self->init(@_) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->init(@_) or return undef 0 0 0
163 0 return $self;
164 }
165
166 sub init {
167 0 ▶ my $self = shift;
Subroutine init: not called CC=5 SCAR=34.0
Pod documented
168 0 ▶ my $args = (ref($_[0]) eq "HASH") ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 0 0
169
170 0 ▶ my $engine = $args->{'engine'} || "blogger";
Condition0%0/2
$args->{'engine'} || 'blogger'
l!l
00
MC/DC0%0/1
$args->{'engine'} || 'blogger'
$args->{'engine'}
Truth table0%0/2
A
A= $args->{'engine'}
Aresult
11
00
171 0 my $class = join("::",__PACKAGE__,"Engine",ucfirst $engine);
172
173 0 eval "require $class";
174
175 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
176 0 print $@,"\n";
177 0 $LAST_ERROR = "Unrecognized implementation of the Blogger API.";
178 0 return 0;
179 }
180
181 $self->{"_class"} = $class->new(%$args)
182 0 ▶ || &{ $LAST_ERROR = Error->prior(); return 0; };
Condition0%0/3
$class->new(%$args) || &{$Net::Blogger::LAST_ERROR = 'Error'->prior; return 0;}
l!l&&r!l&&!r
000
MC/DC0%0/2
$class->new(%$args) || &{$Net::Blogger::LAST_ERROR = 'Error'->prior; return 0;}
$class->new(%$args) &{$Net::Blogger::LAST_ERROR = 'Error'->prior; return 0;}
Truth table0%0/3
A || B
A= $class->new(%$args)B= &{$Net::Blogger::LAST_ERROR = 'Error'->prior; return 0;}
ABresult
1X1
011
000
183
184 0 return 1;
185 }
186
187 =head1 Blogger API METHODS
188
189 =head2 $pkg->getUsersBlogs()
190
191 Fetch the I<blogid>, I<url> and I<blogName> for each of the Blogger blogs
192 the current user is registered to.
193
194 Returns an array ref of hashes.
195
196 =head2 $pkg->newPost(\%args)
197
198 Add a new post to the Blogger server.
199
200 Valid arguments are :
201
202 =over 4
203
204 =item *
205
206 B<postbody>
207
208 Scalar ref. I<required>
209
210 =item *
211
212 B<publish>
213
214 Boolean.
215
216 =back
217
218 If the length of I<postbody> exceeds maximum length allowed by the Blogger servers
219 -- 65,536 characters -- currently the text will be chunked into smaller pieces are
220 each piece will be posted separately.
221
222 Returns an array containing one, or more, post ids.
223
224 =head2 $pkg->getPost($postid)
225
226 Returns a hash ref, containing the following keys : userid, postid, content and dateCreated.
227
228 =head2 $pkg->getRecentPosts(\%args)
229
230 Fetch the latest (n) number of posts for a given blog. The most recent posts are returned
231 first.
232
233 Valid arguments are
234
235 =over 4
236
237 =item *
238
239 B<numposts>
240
241 Int. If no argument is passed to the method, default is 1.
242
243 "NumberOfPosts is limited to 20 at this time. Let me know if this
244 gets annoying. Letting this number get too high could result in some
245 expensive db access, so I want to be careful with it." --Ev
246
247 =back
248
249 Releases prior to Net::Blogger 0.85 accepted a list of arguments
250 rather than a reference. Version 0.85+ are backwards compatible.
251
252 Returns true or false, followed by an array of hash refs. Each hash ref contains the following
253 keys : postid,content,userid,dateCreated
254
255 =head2 $pkg->editPost(\%args)
256
257 Update the Blogger database. Set the body of entry $postid to $body.
258
259 Valid arguments are :
260
261 =over 4
262
263 =item *
264
265 B<postbody> (required)
266
267 Scalar ref or a valid filehandle.
268
269 =item *
270
271 B<postid> (required)
272
273 String.
274
275 =item *
276
277 B<publish>
278
279 Boolean.
280
281 =back
282
283 If the length of I<postbody> exceeds maximum length allowed by the Blogger servers
284 -- 65,536 characters -- currently the text will be chunked into smaller pieces are
285 each piece will be posted separately.
286
287 Releases prior to Net::Blogger 0.85 accepted a list of arguments
288 rather than a reference. Version 0.85+ are backwards compatible.
289
290 Returns an array containing one, or more, post ids.
291
292 =head2 $pkg->deletePost(\%args)
293
294 Delete a post from the Blogger server.
295
296 Valid arguments are
297
298 =over 4
299
300 =item *
301
302 B<postid> (required)
303
304 String.
305
306 =item *
307
308 B<publish>
309
310 Boolean.
311
312 =back
313
314 Releases prior to Net::Blogger 0.85 accepted a list of arguments
315 rather than a reference. Version 0.85+ are backwards compatible.
316
317 Returns true or false.
318
319 =head2 $pkg->setTemplate(\%args)
320
321 Set the body of the template matching type I<$type>.
322
323 "template is the HTML (XML, whatever -- Blogger can output any sort of text).
324 Must contain opening and closing <Blogger> tags to be valid and accepted."
325 --Evan
326
327 Valid arguments are
328
329 =over 4
330
331 =item *
332
333 B<template>
334
335 Scalar ref. I<required>
336
337 =item *
338
339 B<type>
340
341 String. I<required>
342
343 Valid types are "main" and "archiveIndex"
344
345 =back
346
347 Releases prior to Net::Blogger 0.85 accepted a list of arguments
348 rather than a reference. Version 0.85+ are backwards compatible.
349
350 Returns true or false.
351
352 =head2 $pkg->getTemplate(\%args)
353
354 Fetch the body of the template matching type I<$type>.
355
356 Valid types are
357
358 =over 4
359
360 =item *
361
362 B<type>
363
364 String. I<required>
365
366 Valid types are "main" and "archiveIndex"
367
368 =back
369
370 Releases prior to Net::Blogger 0.85 accepted a list of arguments
371 rather than a reference. Version 0.85+ are backwards compatible.
372
373 Returns a string.
374
375 =head1 EXTENDED METHODS
376
377 =cut
378
379 =head2 $pkg->GetBlogId(\%args)
380
381 Return the unique blogid for I<$args->{'blogname'}>.
382
383 Valid arguments are
384
385 =over 4
386
387 =item *
388
389 B<blogname>
390
391 String.
392
393 =back
394
395 Releases prior to Net::Blogger 0.85 accepted a list of arguments
396 rather than a reference. Version 0.85+ are backwards compatible.
397
398 Returns a string. If no blogname is specified, the current blogid for
399 the object is returned.
400
401 =head2 $pkg->DeleteAllPosts(\%args)
402
403 Delete all the posts on a weblog. Valid arguments are :
404
405 =over 4
406
407 =item *
408
409 B<publish>
410
411 Boolean.
412
413 =back
414
415 Releases prior to Net::Blogger 0.85 accepted a list of arguments
416 rather than a reference. Version 0.85+ are backwards compatible.
417
418 =head2 $pkg->PostFromFile(\%args)
419
420 Open a filehandle, and while true, post to Blogger. If the length of the
421 amount read from the file exceeds the per-post limit assigned by the Blogger
422 servers -- currently 65,536 characters -- the contents of the file will be
423 posted in multiple "chunks".
424
425 Valid arguments are
426
427 =over 4
428
429 =item *
430
431 B<file>
432
433 /path/to/file I<required>
434
435 =item *
436
437 B<postid>
438
439 String.
440
441 =item *
442
443 B<publish>
444
445 Boolean.
446
447 =item *
448
449 B<tail>
450
451 Boolean.
452
453 If true, the method will not attempt to post data whose length exceeds the
454 limit set by the Blogger server in the order that the data is read. Translation :
455 last in becomes last post becomes the first thing you see on your weblog.
456
457 =back
458
459 If a I<postid> argument is present, the method will call the Blogger API I<editPost>
460 method with postid. Otherwise the method will call the Blogger API I<newPost> method.
461
462 Releases prior to Net::Blogger 0.85 accepted a list of arguments
463 rather than a reference. Version 0.85+ are backwards compatible.
464
465 Returns true or false, followed by an array of zero, or more, postids.
466
467 =head2 $pkg->PostFromOutline(\%args)
468
469 Like I<PostFromFile>, only this time the file is an outliner document.
470
471 This method uses Simon Kittle's Text::Outline::asRenderedHTML method for posting. As of
472 this writing, the Text::Outline package has not been uploaded to the CPAN. See below for
473 a link to the homepage/source.
474
475 Valid outline formats are OPML, tabbed text outline, Emacs' outline-mode format, and the
476 GNOME Think format.
477
478 Valid arguments are
479
480 =over 4
481
482 =item *
483
484 B<file>
485
486 /path/to/file I<required>
487
488 =item *
489
490 B<postid>
491
492 String.
493
494 =item *
495
496 B<publish>
497
498 Boolean.
499
500 =back
501
502 If a I<postid> argument is present, the method will call the Blogger API
503 I<editPost> method with postid. Otherwise the method will call the Blogger
504 API I<newPost> method.
505
506 Releases prior to Net::Blogger 0.85 accepted a list of arguments
507 rather than a reference. Version 0.85+ are backwards compatible.
508
509 Returns true or false, followed by an array of zero, or more, postids.
510
511 =cut
512
513 sub DESTROY {
514 0 ▶ return 1;
Subroutine DESTROY: not called CC=1 SCAR=6.9
515 }
516
517 sub AUTOLOAD {
518 0 ▶ my $self = shift;
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
519 0 $AUTOLOAD =~ s/.*:://;
520 0 return $self->{"_class"}->$AUTOLOAD(@_);
521 }
522
523 =head1 NOTES
524
525 =head2 The Atom API
526
527 In January 2004, Blogger announced their support for the Atom
528 API.
529
530 As of this writing (version 0.87) this package does B<not>
531 support the Atom API. If you need to do things Atom-ish, your
532 best bet is to use the L<XML::Atom> package.
533
534 =head2 Content negotiation
535
536 Persons trying to connect to a server using shortened URLs and
537 content negotiation should not be surprised if they encounter
538 weirdness and/or errors. Specifically, a HTTP 406 error.
539
540 Some preliminary investigation suggests that, if there's a bug
541 at play here, it's a bug somewhere deep in SOAP::Lite/HTTP::*
542 land.
543
544 Patches are welcome. Otherwise, you've been warned. :-)
545
546 See also :
547
548 =head1 AUTHORS
549
550 Originally authored by Aaron Straup Cope
551 Adopted by Christopher H. Laco
552
553 =head1 SEE ALSO
554
555 L<Net::Blogger::API::Core>
556
557 L<Net::Blogger::Engine::Base>
558
559 http://plant.blogger.com/api/
560
561 =head1 BUGS
562
563 Hopefully, few. Please reports all bugs to :
564
565 http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net::Blogger
566
567 =head1 SOURCE
568
569 You can get the latest version of the source code from the Subversion repository
570 at http://handelframework.com/svn/CPAN/Net-Blogger/
571
572 =head1 LICENSE
573
574 Copyright (c) 2001-2005 Aaron Straup Cope.
575
576 This is free software, you may use it and distribute it under
577 the same terms as Perl itself.
578
579 =cut
580
581 2 return 1;
582
583 }
« blib/lib/Net/Blogger/Engine/Movabletype.pm ↑ Summary Build »