Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 53 lines (42 sloc) 1.384 kb
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
use strict;
use Test::More;

use XML::Feed;
use DateTime;

my $now = DateTime->now();

my $feed = XML::Feed->new('Atom');
$feed->title("foo");
$feed->description("Atom 1.0 feed");
$feed->link("http://example.org/");
$feed->id("tag:cpan.org;xml-feed-atom");
$feed->modified($now);

my $entry = XML::Feed::Entry->new('Atom');
$entry->title("1st Entry");
$entry->link("http://example.org/");
$entry->category("blah");
$entry->content("<p>Hello world.</p>");
$entry->id("tag:cpan.org;xml-feed-atom-entry");
$entry->modified($now);

$feed->add_entry($entry);

my $xml = $feed->as_xml;
like $xml, qr!<feed xmlns="http://www.w3.org/2005/Atom"!;
like $xml, qr!<content .*type="xhtml">!;
like $xml, qr!<div xmlns="http://www.w3.org/1999/xhtml">!;

# roundtrip
$feed = XML::Feed->parse(\$xml);
is $feed->format, 'Atom';
is $feed->title, "foo";
is $feed->description, "Atom 1.0 feed";
is $feed->link, "http://example.org/";
is $feed->id, "tag:cpan.org;xml-feed-atom";
is $feed->modified->iso8601, $now->iso8601;

my @entries = $feed->entries;
is @entries, 1;
$entry = $entries[0];

is $entry->title, '1st Entry';
is $entry->link, 'http://example.org/';
is $entry->category, 'blah';
is $entry->content->type, 'text/html';
like $entry->content->body, qr!\s*<p>Hello world.</p>\s*!s;

is $entry->id, "tag:cpan.org;xml-feed-atom-entry";
is $entry->modified->iso8601, $now->iso8601;

done_testing();
Something went wrong with that request. Please try again.