The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::Rssfilter::Group - associate one or more rules with more than one feed

VERSION

version 0.07

SYNOPSIS

    use App::RssFilter::Group;

    my $news_group = App::Rssfilter::Group->new( 'news' );
    # shorthand for
    $news_group = App::Rssfilter::Group( name => 'news' );

    $news_group->add_group( 'USA' );
    # shorthand for
    $news_group->add_group(
        App::Rssfilter::Group->new(
            name => 'USA',
        )
    );
    my $uk_news_group = $news_group->add_group( name => 'UK' );

    $uk_news_group->add_rule( 'Category[Politics]' => 'MarkTitle' );
    # shorthand for
    $uk_news_group->add_rule(
        App::Rssfilter::Rule->new(
            condition => 'Category[Politics]',
            action    => 'MarkTitle',
        )
    );

    my $dupe_rule = $news_group->group( 'USA' )->add_rule( condition => 'Duplicate', action => 'DeleteItem' );
    $uk_news_group->add_rule( $dupe_rule );

    $news_group->group( 'USA' )->add_feed( WashPost => 'http://feeds.washingtonpost.com/rss/national' );
    # shorthand for
    $news_group->group( 'USA' )->add_feed(
        App::Rssfilter::Feed->new(
            name => 'WashPost',
            url  => 'http://feeds.washingtonpost.com/rss/national',
       )
    );
    $news_group->group( 'USA' )->add_feed( name => 'NYTimes', url => 'http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml' );

    $uk_news_group->add_feed( $news_group->group( 'USA' )->feed( 'WashPost' ) );

    $news_group->update;

DESCRIPTION

This module groups together feeds so that the same rules will be used to constrain them.

It consumes the App::Rssfilter::Logger role.

Use a group to:

  • allow rules which retain state (e.g. Duplicates) to constrain over multiple feeds

  • apply the same rules configuration to multiple feeds

ATTRIBUTES

logger

This is a object used for logging; it defaults to a Log::Any object. It is provided by the App::Rssfilter::Logger role.

name

This is the name of the group. Group names are used when storing a feed so that feeds from the same group are kept together. The default value is '.' (a single period).

storage

This is a feed storage object for feeds to use when they are updated. The default value is a fresh instance of App::Rssfilter::Feed::Storage. See "update" for details on when the default value is used.

groups

This is an arrayref of subgroups attatched to this group.

rules

This is an arrayref of rules to apply to the feeds in this group (and subgroups).

feeds

This is an arrayref of feeds.

METHODS

update

    $group->update( rules => $rules, storage => $storage );

Recursively calls update on the feeds and subgroups of this group.

$rules is an arrayref of additional rules to constrain the feed and groups, in addition to the group's current list of rules.

$storage is the feed storage object that feeds and subgroups will use to store their updated contents. If not specified, groups will use their default storage. The group's name is appended to the current path of $storage before being passed to feeds and subgroups.

add_group

    $group = $group->add_group( $app_rssfilter_group | %group_options );

Adds $app_rssfilter_group (or creates a new App::RssFilter::Group instance from the %group_options) to the list of subgroups for this group. Returns this group (for chaining).

group

    my $subgroup = $group->group( $name );

Returns the last subgroup added to this group whose name is $name, or undef if no matching group.

add_rule

    $group = $group->add_rule( $app_rssfilter_rule | %rule_options )

Adds $app_rssfilter_rule (or creates a new App::RssFilter::Rule instance from the %rule_options) to the list of rules for this group. Returns this group (for chaining).

add_feed

    $group = $group->add_feed( $app_rssfilter_feed | %feed_options );

Adds $app_rssfilter_feed (or creates a new App::RssFilter::Feed instance from the %feed_options) to the list of feeds for this group. Returns this group (for chaining).

feed

    my $feed = $group->feed( $name );

Returns the last feed added to this group whose name is $name, or undef if no matching feed.

from_hash

    my $group = App::Rssfilter::Group::from_hash( %config );

Returns a new instance of this class with the feeds, rules, and subgroups specifed in %config. This method is provided by "from_hash" in App::Rssfilter::FromHash, which has additional documentation & examples.

from_yaml

    my $group = App::Rssfilter::Group::from_yaml( $yaml_config );

Returns a new instance of this class with the feeds, rules, and subgroups specifed in $yaml_config. This method is provided by "from_yaml" in App::Rssfilter::FromYaml, which has additional documentation & examples.

SEE ALSO

AUTHOR

Daniel Holz <dgholz@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Daniel Holz.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.