File Coverage

blib/lib/App/Rssfilter/Match/BbcSports.pm
Criterion Covered Total %
statement 14 14 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 23 23 100.0


line stmt bran cond sub pod time code
1             # ABSTRACT: match a BBC sport RSS item
2              
3 1     1   91901 use strict;
  1         2  
  1         39  
4 1     1   5 use warnings;
  1         3  
  1         69  
5              
6              
7             package App::Rssfilter::Match::BbcSports;
8             $App::Rssfilter::Match::BbcSports::VERSION = '0.08'; # TRIAL
9 1     1   1054 use Method::Signatures;
  1         90195  
  1         9  
10              
11              
12 1 100   1   187957 func match ( $item ) {
  6 100   6   4121  
  5         7  
  5         18  
13 4         15 return $item->at('guid')->text =~ qr{ www [.] bbc [.] co [.] uk / sport [1]? / }xms;
14             }
15              
16             1;
17              
18             __END__
19              
20             =pod
21              
22             =encoding UTF-8
23              
24             =head1 NAME
25              
26             App::Rssfilter::Match::BbcSports - match a BBC sport RSS item
27              
28             =head1 VERSION
29              
30             version 0.08
31              
32             =head1 SYNOPSIS
33              
34             use App::Rssfilter::Match::BbcSports;
35              
36             use Mojo::DOM;
37             my $rss = Mojo::DOM->new( <<"End_of_RSS" );
38             <?xml version="1.0" encoding="UTF-8"?>
39             <rss>
40             <channel>
41             <item>
42             <guid>http://www.bbc.co.uk/sport/some_article</guid>
43             <description>here is an article about a sporting event</description>
44             </item>
45             <item>
46             <guid>http://www.bbc.co.uk/tech/new_rss_tool_changes_how_we_read_news</guid>
47             <description>here is an article about an rss tool</description>
48             </item>
49             </channel>
50             </rss>
51             End_of_RSS
52              
53             print $_, "\n" for $rss->find( 'item' )->grep( \&App::Rssfilter::Match::BbcSports::match );
54              
55             # or with an App::Rssfilter::Rule
56              
57             use App::Rssfilter::Rule;
58             App::Rssfilter::Rule->new(
59             condition => 'BbcSports',
60             action => sub { print shift->to_string, "\n" },
61             )->constrain( $rss );
62              
63             # either way, prints
64            
65             # <item>
66             # <guid>http://www.bbc.co.uk/tech/new_rss_tool_changes_how_we_read_news</guid>
67             # <description>here is an article about an rss tool</description>
68             # </item>
69              
70             =head1 DESCRIPTION
71              
72             This module will match items from BBC RSS feeds which are about sporting events.
73              
74             =head1 FUNCTIONS
75              
76             =head2 match
77              
78             my $item_is_BBC_sport = App::Rssfilter::Match::BbcSports::match( $item );
79              
80             Returns true if ther GUID of C<$item> looks like a BBC sport GUID (like C<http://www.bbc.co.uk/sport>).
81              
82             =head1 SEE ALSO
83              
84             =over 4
85              
86             =item *
87              
88             L<App::Rssfilter>
89              
90             =item *
91              
92             L<App::Rssfilter::Rule>
93              
94             =back
95              
96             =head1 AUTHOR
97              
98             Daniel Holz <dgholz@gmail.com>
99              
100             =head1 COPYRIGHT AND LICENSE
101              
102             This software is copyright (c) 2015 by Daniel Holz.
103              
104             This is free software; you can redistribute it and/or modify it under
105             the same terms as the Perl 5 programming language system itself.
106              
107             =cut