package XML::Atom::Feed::JavaScript; use strict; use warnings; use base qw( XML::Atom::Feed ); our $VERSION = 0.5; =head1 NAME XML::Atom::Feed::JavaScript - Atom syndication with JavaScript =head1 SYNOPSIS ## get an Atom feed from the network use XML::Atom::Client use XML::Atom::Feed::JavaScript; my $client = XML::Atom::Client->new(); my $feed = $client->getFeed( 'http://example.com/atom.xml' ); print $feed->asJavascript(); ## or get an atom feed from disk use XML::Atom::Feed::JavaScript; my $feed = XML::Atom::Feed->new( Stream => 'atom.xml' ); print $feed->asJavascript(); =head1 DESCRIPTION XML::Atom::Feed::JavaScript exports an additional function into the XML::Atom package for outputting Atom feeds as javascript. =head1 FUNCTIONS =head2 asJavascript() Returns a XML::Atom::Feed object as a string of JavaScript code. If you want to limit the amount of entries you can pass in an integer argument: ## limit to first 10 entries my $javascript = $feed->asJavascript( 10 ); =cut sub XML::Atom::Feed::asJavascript { my ( $feed, $max ) = @_ or die q( can't get feed ); my @entries = $feed->entries(); my $items = scalar @entries; if ( not $max or $max > $items ) { $max = $items; } ## open javascript section my $output = _jsPrint( '