line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: match an RSS item by category |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
82869
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
99
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package App::Rssfilter::Match::Category; |
8
|
|
|
|
|
|
|
$App::Rssfilter::Match::Category::VERSION = '0.08'; # TRIAL |
9
|
2
|
|
|
2
|
|
924
|
use Method::Signatures; |
|
2
|
|
|
|
|
88435
|
|
|
2
|
|
|
|
|
13
|
|
10
|
2
|
|
|
2
|
|
1978
|
use List::MoreUtils qw( any ); |
|
2
|
|
|
|
|
13138
|
|
|
2
|
|
|
|
|
62
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
100
|
|
2
|
|
152166
|
func match ( $item, @bad_cats ) { |
|
15
|
|
|
15
|
|
3342
|
|
|
14
|
|
|
|
|
22
|
|
|
14
|
|
|
|
|
37
|
|
14
|
14
|
|
|
15
|
|
47
|
my @categories = $item->find("category")->map( sub { $_->text } )->each; |
|
15
|
|
|
|
|
2880
|
|
15
|
14
|
|
|
|
|
1312
|
my @split_categories = map { ( / \A ( [^:]+ ) ( [:] .* ) \z /xms, $_ ) } @categories; |
|
15
|
|
|
|
|
62
|
|
16
|
14
|
|
|
|
|
31
|
my %cats = map { $_ => 1 } @split_categories; |
|
27
|
|
|
|
|
75
|
|
17
|
14
|
|
|
14
|
|
81
|
return List::MoreUtils::any { defined $_ } @cats{ @bad_cats }; |
|
14
|
|
|
|
|
84
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
1; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
__END__ |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=pod |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=encoding UTF-8 |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
App::Rssfilter::Match::Category - match an RSS item by category |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 VERSION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
version 0.08 |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 SYNOPSIS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use App::Rssfilter::Match::Category; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
use Mojo::DOM; |
41
|
|
|
|
|
|
|
my $rss = Mojo::DOM->new( <<"End_of_RSS" ); |
42
|
|
|
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
43
|
|
|
|
|
|
|
<rss> |
44
|
|
|
|
|
|
|
<channel> |
45
|
|
|
|
|
|
|
<item> |
46
|
|
|
|
|
|
|
<title>Jumping jackrabbit smash long jump record</title> |
47
|
|
|
|
|
|
|
<category>Sport:leporine</category> |
48
|
|
|
|
|
|
|
</item> |
49
|
|
|
|
|
|
|
<item> |
50
|
|
|
|
|
|
|
<title>Online poll proves programmers cool, successful</title> |
51
|
|
|
|
|
|
|
<category>Internet:very_real_and_official</category> |
52
|
|
|
|
|
|
|
</item> |
53
|
|
|
|
|
|
|
</channel> |
54
|
|
|
|
|
|
|
</rss> |
55
|
|
|
|
|
|
|
End_of_RSS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
print $_, "\n" for $rss->find( 'item' )->grep( |
58
|
|
|
|
|
|
|
sub { |
59
|
|
|
|
|
|
|
App::Rssfilter::Match::Category::match( shift, 'Sport' ) ) { |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# or with an App::Rssfilter::Rule |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
use App::Rssfilter::Rule; |
66
|
|
|
|
|
|
|
App::Rssfilter::Rule->new( |
67
|
|
|
|
|
|
|
condition => 'Category[Sport]', |
68
|
|
|
|
|
|
|
action => sub { print shift->to_string, "\n" }, |
69
|
|
|
|
|
|
|
)->constrain( $rss ); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# either way, prints |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# <item> |
74
|
|
|
|
|
|
|
# <title>Jumping jackrabbit smash long jump record</title> |
75
|
|
|
|
|
|
|
# <category>Sport:leporine</category> |
76
|
|
|
|
|
|
|
# </item> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 DESCRIPTION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This module will match an RSS item if it has one or more specific category. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 FUNCTIONS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 match |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $item_has_category = App::Rssfilter::Match::Category::match( $item, @categories ); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Returns true if C<$item> has a category which matches any of C<@categories>. Since some RSS feeds specify categories & subcategories as 'C<main category:subcategory>', elements of C<@categories> can be: |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=over 4 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item * |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
C<category> - this category, with any subcategory |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item * |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
C<category:subcategory> - only this category with this subcategory |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item * |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
C<:subcategory> - any category with a matching subcategory |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=back |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SEE ALSO |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=over 4 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L<App::Rssfilter> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
L<App::Rssfilter::Rule> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=back |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 AUTHOR |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Daniel Holz <dgholz@gmail.com> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Daniel Holz. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
129
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |