HTML-Microformats
view release on metacpan or search on metacpan
lib/HTML/Microformats/Format/hEntry.pm view on Meta::CPAN
=head1 NAME
HTML::Microformats::Format::hEntry - an hAtom entry
=head1 SYNOPSIS
use Data::Dumper;
use HTML::Microformats::DocumentContext;
use HTML::Microformats::Format::hAtom;
my $context = HTML::Microformats::DocumentContext->new($dom, $uri);
my @feeds = HTML::Microformats::Format::hAtom->extract_all(
$dom->documentElement, $context);
foreach my $feed (@feeds)
{
foreach my $entry ($feed->get_entry)
{
print $entry->get_link . "\n";
}
}
=head1 DESCRIPTION
HTML::Microformats::Format::hEntry is a helper module for HTML::Microformats::Format::hAtom.
This class is used to represent entries within feeds. Generally speaking, you want to
use HTML::Microformats::Format::hAtom instead.
HTML::Microformats::Format::hEntry inherits from HTML::Microformats::Format. See the
base class definition for a description of property getter/setter methods,
constructors, etc.
=head2 Additional Method
=over
=item * C<< to_atom >>
This method exports the data as an XML file containing an Atom <entry>.
It requires L<XML::Atom::FromOWL> to work, and will throw an error at
run-time if it's not available.
=item * C<< to_icalendar >>
This method exports the data in iCalendar format (as a VJOURNAL). It
requires L<RDF::iCalendar> to work, and will throw an error at run-time
if it's not available.
=back
=cut
package HTML::Microformats::Format::hEntry;
use base qw(HTML::Microformats::Format HTML::Microformats::Mixin::Parser);
use strict qw(subs vars); no warnings;
use 5.010;
use HTML::Microformats::Utilities qw(searchClass searchAncestorClass stringify);
use HTML::Microformats::Datatype::String qw(isms);
use HTML::Microformats::Format::hCard;
use HTML::Microformats::Format::hEvent;
use HTML::Microformats::Format::hNews;
use Object::AUTHORITY;
BEGIN {
$HTML::Microformats::Format::hEntry::AUTHORITY = 'cpan:TOBYINK';
$HTML::Microformats::Format::hEntry::VERSION = '0.105';
}
our $HAS_ATOM_EXPORT;
BEGIN
{
local $@ = undef;
eval 'use XML::Atom::FromOWL;';
$HAS_ATOM_EXPORT = 1
if XML::Atom::FromOWL->can('new');
}
sub new
{
my ($class, $element, $context) = @_;
my $cache = $context->cache;
# Use hNews if more appropriate.
if ($element->getAttribute('class') =~ /\b(hnews)\b/)
{
return HTML::Microformats::Format::hNews->new($element, $context)
if $context->has_profile( HTML::Microformats::Format::hNews->profiles );
}
return $cache->get($context, $element, $class)
if defined $cache && $cache->get($context, $element, $class);
my $self = {
'element' => $element ,
'context' => $context ,
'cache' => $cache ,
'id' => $context->make_bnode($element) ,
};
bless $self, $class;
lib/HTML/Microformats/Format/hEntry.pm view on Meta::CPAN
}
$model->add_statement(RDF::Trine::Statement->new(
$self->id(1),
RDF::Trine::Node::Resource->new("${ical}uid"),
$self->_make_literal($self->data->{link} => 'anyURI'),
))
if $self->data->{link};
foreach my $field (qw(enclosure))
{
for (my $i=0; defined $self->data->{$field}->[$i]; $i++)
{
$model->add_statement(RDF::Trine::Statement->new(
$self->id(1),
RDF::Trine::Node::Resource->new("${ical}attach"),
RDF::Trine::Node::Resource->new($self->data->{$field}->[$i]->data->{href}),
));
}
}
$model->add_statement(RDF::Trine::Statement->new(
$self->id(1),
RDF::Trine::Node::Resource->new("${ical}created"),
$self->_make_literal($self->data->{published}),
))
if $self->data->{published};
if ($self->data->{updated})
{
foreach my $u (@{ $self->data->{updated} })
{
$model->add_statement(RDF::Trine::Statement->new(
$self->id(1),
RDF::Trine::Node::Resource->new("${ical}dtstamp"),
$self->_make_literal($u),
));
$model->add_statement(RDF::Trine::Statement->new(
$self->id(1),
RDF::Trine::Node::Resource->new("${ical}last-modified"),
$self->_make_literal($u),
));
}
}
# todo - CATEGORIES
HTML::Microformats::Format::hEvent::_add_to_model_related($self, $model);
return $self;
}
sub to_atom
{
my ($self) = @_;
die "Need XML::Atom::FromOWL to export Atom.\n" unless $HAS_ATOM_EXPORT;
my $exporter = XML::Atom::FromOWL->new;
return $exporter->export_entry($self->model, $self->id(1))->as_xml;
}
sub to_icalendar
{
my ($self) = @_;
die "Need RDF::iCalendar to export iCalendar data.\n"
unless $HTML::Microformats::Format::hCalendar::HAS_ICAL_EXPORT;
my $model = $self->model;
$self->add_to_model_ical($model);
my $exporter = RDF::iCalendar::Exporter->new;
return $exporter->export_component($model, $self->id(1))->to_string;
}
sub profiles
{
my @p = qw(http://microformats.org/profile/hatom
http://ufs.cc/x/hatom
http://purl.org/uF/hAtom/0.1/);
push @p, HTML::Microformats::Format::hNews->profiles;
return @p;
}
1;
=head1 BUGS
Please report any bugs to L<http://rt.cpan.org/>.
=head1 SEE ALSO
L<HTML::Microformats::Format>,
L<HTML::Microformats>,
L<HTML::Microformats::Format::hAtom>,
L<HTML::Microformats::Format::hNews>.
=head1 AUTHOR
Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
=head1 COPYRIGHT AND LICENCE
Copyright 2008-2012 Toby Inkster
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=head1 DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
=cut
( run in 2.499 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )