NAME

XML::Atom::App - quickly create small efficient scripts to syndicate via Atom

VERSION

This document describes XML::Atom::App version 0.0.5

SYNOPSIS

A complete Atom feed script:

use XML::Atom::App;

XML::Atom::App->new({
    'title'     => _get_title_string(),
    'id'        => _get_id_string(),
    'updated'   => XML::Atom::App->datetime_as_rfc3339( _get_last_updated_datetime_args() ),
    'particles' => _get_latest_particles_arrayref(),
})->output_with_headers();

EXAMPLE SCRIPTS

uber efficient persistent perl process

If using PersistentPerl this script will only create the $feed, update particles, and/or generate $xml if needed instead of on every hit.

#!/usr/bin/perperl

use strict;
use warnings;
use vars ($feed $xml $particles);
use XML::Atom::App;

if (!defined $feed || ref $feed ne 'XML::Atom::App' ) {
    $feed = XML::Atom::App->new({
        'title' => _get_title_string(),
        'id'    => _get_id_string(),
        'updated'   => XML::Atom::App->datetime_as_rfc3339( _get_last_updated_datetime_args() ),
    });
}

if ( !defined $xml || !xml || !defined $particles || ref $particles ne 'ARRAY' || _particles_need_updated() ) {
    $particles = _get_latest_particles_arrayref();
    $feed->create_from_atomic_structure( $particles );
    $xml = $feed->as_xml();
}

$feed->output_with_headers( $xml );

explicit creation basic CGI

#!/usr/bin/perl

use strict;
use warnings;
use XML::Atom::App;

my $feed = XML::Atom::App->new({
    'title'     => _get_title_string(),
    'id'        => _get_id_string(),
    'updated'   => XML::Atom::App->datetime_as_rfc3339( _get_last_updated_datetime_args() ),
});

$feed->create_from_atomic_structure( _get_latest_particles_arrayref() );

$feed->output_with_headers();

implicit creation basic CGI

#!/usr/bin/perl

use strict;
use warnings;
use XML::Atom::App;

my $feed = XML::Atom::App->new({
    'title'     => _get_title_string(),
    'id'        => _get_id_string(),
    'particles' => _get_latest_particles_arrayref(),
    'updated'   => XML::Atom::App->datetime_as_rfc3339( _get_last_updated_datetime_args() ),
});

# this is done (IE implied) for you w/ 'particles' key to new(): 
# $feed->create_from_atomic_structure( _get_latest_particles_arrayref() );

$feed->output_with_headers();

DESCRIPTION

The idea of this module is to make it easy to create Atom feed scripts by packaging up the logic that happens over and over and using a fairly simple data structure that you can generate easily based on your needs.

INTERFACE

METHODS

new()

Accepts no arguments or a hashref with any of the following keys:

Version

Atom version to output. Defaults to 1.0 (which is different than XML::Atom which defaults to 0.3 at the time of writing this)

alert_cant

A coderef to run instead of the default alert_cant method. Internally it called in void context and is passed the name of the method and the object.

particles

An arrayref to create the Atom document from (See "particles" array ref below). If specified it calls create_from_atomic_structure() for you.

Same as the particle array ref 'link' but for the feed (see below). If not specified a simple link is created: rel="self" (as recommended by http://feedvalidator.org)

author

Same as the particle array ref 'author' but for the feed (see below).

contributor

Same as the particle array ref 'contributor', but for the feed (see below).

Additionally it takes as a key any XML::Atom::Feed method name which is subsequently called by new() for you.

The value can be a valid argument to said function or an array of valid arguments.

my $feed = XML::Atom::App->new({
    'title'     => _get_title_string(),
    'id'        => _get_id_string(),       
    'updated'   => XML::Atom::App->datetime_as_rfc3339( _get_last_updated_datetime_args() ),
});

is the same as

my $feed = XML::Atom::App->new();
$feed->title( _get_title_string() );
$feed->id( _get_id_string() );
$feed->updated( $feed->datetime_as_rfc3339( _get_last_updated_datetime_args() ) );

Any unknown keys will cause and alert_cant().

create_entry_from_atomic_structure()

Takes the particle hashref representing one entry and does the work needed to turn it into an Atom Entry document. (See "particles" array ref below).

The newly created XML::Atom::Entry object is returned, but not added to the current feed. To add the entry to the XML::Atom::Feed object, use the add_entry method.

create_from_atomic_structure()

Takes the particle arrayref passed and does all the necessary calls to make it into an Atom document. (See "particles" array ref below).

It clears the previous particles for you before creating the new one (unless you tell it not to)

A second argument can be a hashref of options. Currently the only option is the 'do_not_clear_particles' key which if true does not clear the previouse particles.

$feed->{'time_of_last_create_from_atomic_structure'} gets set to Time::HiRes::time for your use in seeing if the particles need updated. (IE say your database was updated since this was generated)

output_with_headers()

This outputs (in void context) or returns as a string (in non void context) all HTTP headers and XML necessary to serve the Atom feed.

You can avoid having it call $feed->as_xml() internally by passing it as an argument. This is useful for perisistent environments so you only have to generate the XML when the particles are updated.

alert_cant()

Generally you won't ever call this in your scripts.

This is called internally when an item that can't be used is found in the particles array ref. See DIAGNOSTICS.

By default it just does a warning. It can be changed by using the 'alert_cant' key.

clear_particles()

Generally you won't ever call this in your scripts.

This clears all particles from the $feed.

CONVIENIENCE

atom_date_string()

Clone of datetime_as_rfc3339()

datetime_as_rfc3339()

Returns a string suitable for any Atom date related entry.

It must be passed a DateTime object or an array ref of DateTime->new() arguments.

my $atom_safe_date_string = $feed->datetime_as_rfc3339( DateTime->now() );

my $atom_safe_date_string = $feed->datetime_as_rfc3339(
    [
        'year'      => 1999, 
        'month'     => 7, 
        'day'       => 17, 
        'hour'      => 12,
        'minute'    => 01,
        'second'    => 00,
        'time_zone' => 'EST',               
    ]
);

orange_atom_icon_32_32_base64()

Returns a base64 string (Plus leading "header" info) of the binary that makes up a 32 x 32 pixel orange Atom icon png image.

orange_atom_icon_32_32_body_with_headers()

Returns HTTP headers and binary data suitable for serving a 32 x 32 pixel orange Atom icon png image.

if ( $action eq 'icon' ) {
    print XML::Atom::App->orange_atom_icon_32_32_body_with_headers();
}
else {
    my $feed = ...
    ...
    $feed->output_with_headers();
}

orange_atom_icon_32_32_img_tag()

Returns an HTML image tag for a 32 x 32 pixel orange Atom icon png image using the base 64 data instead of a normal URL.

Any attributes (height and width are already done) can be added by passing a string as the method's argument.

orange_atom_icon_16_16_base64()

16 pixel x 16 pixel version of corresponding '32_32' method

orange_atom_icon_16_16_body_with_headers()

16 pixel x 16 pixel version of corresponding '32_32' method

orange_atom_icon_16_16_img_tag()

16 pixel x 16 pixel version of corresponding '32_32' method

"particles" array ref

Each item in this array ref is an entry in your feed. It is represented as a hashref with the following keys:

title, id, content, updated, created, etc...

Any XML::Atom::Entry method name may be used as a key. The value can be a valid argument to said function or an array of valid arguments.

author

This is a hashref whose keys should be any XML::Atom::Person method name (E.g. name, email, uri, url, homepage).

The value can be a valid argument to said function or an array of valid arguments.

link

This is an array ref of links. Each item is a hashref whose keys should be any XML::Atom::Link method name (E.g. type, rel, href, hreflang, title, length).

The value can be a valid argument to said function or an array of valid arguments.

contributors

This is an array ref of hashrefs whose keys should be any XML::Atom::Person method name (See author above).

The value can be a valid argument to said function or an array of valid arguments.

DIAGNOSTICS

Can't locate object method "%s" via package "%s"

The particles data structure had a key that was not specially handled and not a method of the given class.

This warning can be overridden by the 'alert_cant' key.

CONFIGURATION AND ENVIRONMENT

XML::Atom::App requires no configuration files or environment variables.

DEPENDENCIES

XML::Atom, XML::Atom::Entry, XML::Atom::Feed

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to bug-xml-atom-app@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

Daniel Muey <http://drmuey.com/cpan_contact.pl>

LICENCE AND COPYRIGHT

Copyright (c) 2007, Daniel Muey <http://drmuey.com/cpan_contact.pl>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.