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

NAME

App::Rssfilter::Match::Category - match an RSS item by category

VERSION

version 0.07

SYNOPSIS

    use App::Rssfilter::Match::Category;

    use Mojo::DOM;
    my $rss = Mojo::DOM->new( <<"End_of_RSS" );
<?xml version="1.0" encoding="UTF-8"?>
<rss>
  <channel>
    <item>
      <title>Jumping jackrabbit smash long jump record</title>
      <category>Sport:leporine</category>
    </item>
    <item>
      <title>Online poll proves programmers cool, successful</title>
      <category>Internet:very_real_and_official</category>
    </item>
  </channel>
</rss>
End_of_RSS

    print $_, "\n" for $rss->find( 'item' )->grep(
        sub {
            App::Rssfilter::Match::Category::match( shift, 'Sport' ) ) {
        }
    );

    # or with an App::Rssfilter::Rule

    use App::Rssfilter::Rule;
    App::Rssfilter::Rule->new(
        condition => 'Category[Sport]',
        action    => sub { print shift->to_xml, "\n" },
    )->constrain( $rss );

    # either way, prints

    # <item>
    #   <title>Jumping jackrabbit smash long jump record</title>
    #   <category>Sport:leporine</category>
    # </item>

DESCRIPTION

This module will match an RSS item if it has one or more specific category.

FUNCTIONS

match

    my $item_has_category = App::Rssfilter::Match::Category::match( $item, @categories );

Returns true if $item has a category which matches any of @categories. Since some RSS feeds specify categories & subcategories as 'main category:subcategory', elements of @categories can be:

  • category - this category, with any subcategory

  • category:subcategory - only this category with this subcategory

  • :subcategory - any category with a matching subcategory

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.