NAME
Blog::BlogML::Reader - Read data from a BlogML formatted XML document.
SYNOPSIS
use Blog::BlogML::Reader;
my $reader = new Blog::BlogML::Reader('some/file/blogml.xml');
my @posts = @{$reader->{blog}{posts};
DEPENDENCIES
XML::Parser::Expat
This module uses
XML::Parser::Expat
to parse the XML in the BlogML source file. I chose an expat based parser primarily for its speed. Check the docs for XML::Parser::Expat for further dependencies.HTTP::Date
This module uses
HTTP::Date
to transform date strings into sortable timestamps. Necessary when, for example, sorting blog posts and retrieving the most recent.
EXPORT
None.
INTERFACE
filters
When creating a new reader, the default bahaviour is to parse and load the entire BlogML structure into memory. This can be inefficient if, for example, you have ten-thousand posts and only want the first one. For this reason it is possible (and recommended) that you give the parser some limits before letting it go. This is done by adding filters to the constructor.
to=>n
Limits the parser to only the first n post in the BlogML file.
$reader = new Blog::BlogML::Reader('blogml.xml', to=>3);
from=>n
The parser will only start at the nth item in the BlogML file. Note that this can optionally be used with
to
in order to limit the parser to a range of posts.$reader = new Blog::BlogML::Reader('blogml.xml', from=>11, to=>20);
before=>date
Limits the parser to posts with a creation-date before date.
$reader = new Blog::BlogML::Reader('blogml.xml', before=>"2006-05-01T00:00:00");
after=>date
Limits the parser to posts with a creation-date after date. Can optionally be used with
before
to limit the parser to a range of dates.$reader = new Blog::BlogML::Reader('blogml.xml', after=>"2006-08-01T00:00:00");
id=>n
If you know the specific post you want, why parse the entire file?
$reader = new Blog::BlogML::Reader('blogml.xml', id=>123);
cat=>n
Limits the parser to only the posts that belong to the category with the given id.
$reader = new Blog::BlogML::Reader('blogml.xml', cat=>'news');
methods
meta()
Returns a hash ref of information about the blog.
my $meta = $reader->meta(); print $meta->{title}; print $meta->{author}, $meta->{email};
posts()
Returns an array ref of blog posts.
my $posts = $reader->posts(); print $posts->[0]{title}; foreach my $post (@$posts) { print $post->{title}; print $post->{content}; }
cats()
Returns a hash ref of blog categories, with the keys bsing the category id.
my $cats = $reader->cats(); print $cats->{'news'}{title};
SEE ALSO
The website http://BlogML.com has the latest documentation on the BlogML standard. Note that the reference document "example.xml" included with this module illustrates the expected format.
AUTHOR
Michael Mathews, <mmathews@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2006 by Michael Mathews
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.