HTML::Latemp::News - News Maintenance Module for Latemp (and possibly other


HTML-Latemp-News documentation  | view source Contained in the HTML-Latemp-News distribution.

Index


NAME

Top

HTML::Latemp::News - News Maintenance Module for Latemp (and possibly other web frameworks)

SYNOPSIS

Top

    #!/usr/bin/perl

    use strict;
    use warnings;

    use MyManageNews;

    my @news_items = 
    (
        .
        .
        .
        {
            'title' => "Changes of 18-April-2005",
            'id' => "changes-2005-04-18",
            'description' => q{Around 18 April, 2005, Jane's Site has seen a
                lot of changes. Click the link for details on them.},
            'date' => "2005-04-18",
            'author' => "Jane Smith",
            'category' => "Jane's Site",
        },
        .
        .
        .
    );

    my $news_manager = 
        HTML::Latemp::News->new(
            'news_items' => \@news_items,
            'title' => "Better SCM News",
            'link' => "http://janes-site.tld/",
            'language' => "en-US",
            'copyright' => "Copyright by Jane Smith, (c) 2005",
            'webmaster' => "Jane Smith <jane@janes-site.tld>",
            'managing_editor' => "Jane Smith <jane@janes-site.tld>",
            'description' => "News of Jane's Site - a personal site of " . 
                "Jane Smith",
        );

    $news_manager->generate_rss_feed(
        'output_filename' => "dest/rss.xml"
    );

    1;
=cut

package HTML::Latemp::News::Base;

use base 'Class::Accessor'; use CGI;

sub new { my $class = shift; my $self = {}; bless $self, $class; $self->initialize(@_); return $self; }

package HTML::Latemp::News::Item;

our @ISA=(qw(HTML::Latemp::News::Base));

__PACKAGE__->mk_accessors(qw(index title id description author date category text));

sub initialize { my $self = shift;

    my (%args) = (@_);

    foreach my $k (keys(%args))
    {
        if (! $self->can($k))
        {
            die "Unknown property for HTML::Latemp::News::Item - \"$k\"!";
        }
        $self->set($k, $args{$k});
    }
}

package HTML::Latemp::News;

our @ISA=(qw(HTML::Latemp::News::Base));

__PACKAGE__->mk_accessors(qw(copyright description docs generator items language link managing_editor rating title ttl webmaster));

use XML::RSS;

sub input_items { my $self = shift;

    my $items = shift;

    return 
    [ 
        map 
        { $self->input_single_item($_, $items->[$_]) } 
        (0 .. $#$items)
    ];
}

sub input_single_item { my $self = shift; my ($index, $inputted_item) = (@_);

    return 
        HTML::Latemp::News::Item->new(
            %$inputted_item,
            'index' => $index,
        );
}

sub initialize { my $self = shift;

    my %args = (@_);

    my $items = $args{'news_items'};

    $self->items(
        $self->input_items($items)
    );

    $self->title($args{'title'});
    $self->link($args{'link'});
    $self->language($args{'language'});
    $self->rating($args{'rating'} || '(PICS-1.1 "http://www.classify.org/safesurf/" 1 r (SS~~000 1))');
    $self->copyright($args{'copyright'} || "");
    $self->docs($args{'docs'} || "http://blogs.law.harvard.edu/tech/rss");
    $self->ttl($args{'ttl'} || "360");
    $self->generator($args{'generator'} || "Perl and XML::RSS");
    $self->webmaster($args{'webmaster'});
    $self->managing_editor($args{'managing_editor'} || $self->webmaster());
    $self->description($args{'description'});

    return 0;
}

DESCRIPTION

Top

This is a module that maintains news item for a web-site. It can generate an RSS feed, as well as a news page, and an HTML newsbox, all from the same data.

FUNCTION

Top

HTML::Latemp::News->new(...)

This is the constructor for the news manager. It accepts the following named parameters:

'news_items'

This is a reference to a list of news_items. See below.

'title'

The title of the RSS feed.

The link to the homepage of the site.

'language'

The language of the text.

The copyright notice of the text.

'webmaster'

The Webmaster.

'managing_editor'

The managing editor.

'description'

A description of the news feed as will be put in the RSS feed.

Format of the news_items

The news_items is a reference to an array, of which each element is a hash reference. The hash may contain the following keys:

'title'

The title of the item.

'id'

The ID of the item. This will also be used to calculate URLs.

'description'

A text description explaining what the item is all about.

'author'

The author of the item.

'date'

A string representing the daet.

'category'

The cateogry of the item.

$news_manager->generate_rss_feed('output_filename' => "rss.xml")

This generates an RSS feed. It accepts two named arguments. 'output_filename' is the name of the RSS file to write to. 'num_items' is the number of items to include, which defaults to 10.

$news_manager->get_navmenu_items('num_items' => 5)

This generates navigation menu items for input to the navigation menu of HTML::Widgets::NavMenu. It accepts a named argument 'num_items' which defaults to 10.

$news_manager->get_news_page_entries('num_items' => 5, 'base_url' => "news/")

This generates HTML for the news page. 'base_url' points to a URL to be appended to each item's ID.

$news_manager->get_news_box('num_items' => 5)

This generates an HTML news box with the recent headlines.

AUTHOR

Top

Shlomi Fish, <shlomif@iglu.org.il>

BUGS

Top

Please report any bugs or feature requests to bug-html-latemp-news@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-Latemp-News. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SEE ALSO

Top

XML::RSS, HTML::Widgets::NavMenu.

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


HTML-Latemp-News documentation  | view source Contained in the HTML-Latemp-News distribution.