File: example4.pl

package info (click to toggle)
libhtml-microformats-perl 0.105-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 1,340 kB
  • sloc: perl: 14,121; makefile: 10; sh: 1
file content (33 lines) | stat: -rwxr-xr-x 1,153 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use 5.010;
use lib "lib";
use HTML::Microformats;
use strict;
use JSON;
use Data::Dumper;
use RDF::TrineShortcuts;

my $html = <<HTML;
	<div class="hentry hnews" id="foo">
	<h1>Foo</h1>
	<p class="dateline">London, UK (<span class="geo">12.34,56.78</span>).</p>
	<p class="entry-summary entry-content">Foo bar.</p>
	<p class="vcard author"><a href="mailto:eve\@example.com" class="fn url">Eve</a></p>
	<a rel="tag" href="test">Test</a>
	<span class="updated published">2010-03-01T15:00:00+0000</span>
	</div>
HTML

my $doc  = HTML::Microformats->new_document($html, 'http://example.net/')->assume_all_profiles;
my @news = $doc->objects('hNews');

say $news[0]->get_summary;
$news[0]->set_summary('Bar foo.');
$news[0]->set_updated('2010-03-02T16:00:00+0000', '2010-03-03T16:00:00+0000');
$news[0]->add_updated('2010-03-04T16:00:00+0000', '2010-03-05T16:00:00+0000');
$news[0]->set_link('http://example.com/');
say $news[0]->get_author->[0]->get_nickname->[0];
print to_json($news[0]->data, {pretty=>1,canonical=>1,convert_blessed=>1});

#print $doc->json(pretty=>1,canonical=>1)."\n";
#print rdf_string($doc->model, 'rdfxml')."\n";
#print Dumper($doc);