| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XML::Atom::Filter; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
83138
|
use warnings; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
98
|
|
|
4
|
3
|
|
|
3
|
|
15
|
use strict; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
155
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
XML::Atom::Filter - easy creation of command line Atom processing tools |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.06 |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package Uppercaser; |
|
21
|
|
|
|
|
|
|
use XML::Atom::Filter; |
|
22
|
|
|
|
|
|
|
use base qw( XML::Atom::Filter ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub entry { |
|
25
|
|
|
|
|
|
|
my ($class, $e) = @_; |
|
26
|
|
|
|
|
|
|
$e->content(uc $e->content); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package main; |
|
30
|
|
|
|
|
|
|
Uppercaser->filter; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
C supports creation of command line tools to filter and |
|
35
|
|
|
|
|
|
|
process Atom feeds. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 USAGE |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
package XML::Atom::Filter; |
|
42
|
3
|
|
|
3
|
|
3317
|
use XML::Atom; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
use XML::Atom::Feed; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 XML::Atom::Filter->new() |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Creates an instance of the identity filter. C can be used as |
|
48
|
|
|
|
|
|
|
a class or an instance. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub new { |
|
53
|
|
|
|
|
|
|
my $class = shift; |
|
54
|
|
|
|
|
|
|
return bless {}, $class; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 $f->filter([ $fh ]) |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Reads an Atom feed document and applies the filtering process to it. The Atom |
|
60
|
|
|
|
|
|
|
feed is read from C<$fh>, or C if not given. After the feed is read and |
|
61
|
|
|
|
|
|
|
parsed, it will be run through the C, C (entry by entry), and |
|
62
|
|
|
|
|
|
|
C methods. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub filter { |
|
67
|
|
|
|
|
|
|
my ($self, $fh) = @_; |
|
68
|
|
|
|
|
|
|
my $feed = XML::Atom::Feed->new($fh || \*STDIN) |
|
69
|
|
|
|
|
|
|
or die XML::Atom::Feed->errstr; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$self->pre($feed); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my @entries = $feed->entries; |
|
74
|
|
|
|
|
|
|
@entries = grep { $_ } map { $self->entry($_) } @entries; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
## Remove existing entries so we can add back the processed ones without duplication. |
|
77
|
|
|
|
|
|
|
my @entryNodes; |
|
78
|
|
|
|
|
|
|
if(*XML::Atom::LIBXML) { |
|
79
|
|
|
|
|
|
|
@entryNodes = $feed->elem->getElementsByTagNameNS($feed->ns, 'entry') or return; |
|
80
|
|
|
|
|
|
|
} else { |
|
81
|
|
|
|
|
|
|
for my $el ($feed->elem->getDocumentElement->childNodes) { |
|
82
|
|
|
|
|
|
|
push @entryNodes, $el if $el->getName eq 'entry'; |
|
83
|
|
|
|
|
|
|
}; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
$_->parentNode->removeChild($_) for @entryNodes; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$feed->add_entry($_) for @entries; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$self->post($feed); |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 $f->pre($feed) |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Prepares to process the entries of the feed, an C object. By |
|
95
|
|
|
|
|
|
|
default, no operation is performed. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub pre { 1; } |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 $f->entry($entry) |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Processes an entry of the feed, an C object. Returns the new |
|
104
|
|
|
|
|
|
|
or modified entry reference, or C if the entry should be removed from |
|
105
|
|
|
|
|
|
|
the filtered feed. By default, no change is made. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
If your filter modifies the content of the entry, you B also modify the |
|
108
|
|
|
|
|
|
|
entry's C. The Atom feed specification requires entries' C fields to be |
|
109
|
|
|
|
|
|
|
universally unique. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub entry { $_[1]; } |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 $f->post($feed) |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Postprocesses the feed, an C object, after the entries are |
|
118
|
|
|
|
|
|
|
individually processed. By default, the feed's XML is printed to C. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub post { print STDOUT $_[1]->as_xml; } |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 AUTHOR |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Mark Paschal, C<< >> |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 BUGS |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
131
|
|
|
|
|
|
|
C, or through the web interface at |
|
132
|
|
|
|
|
|
|
L. |
|
133
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
134
|
|
|
|
|
|
|
your bug as I make changes. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Copyright 2005-2006 Mark Paschal, All Rights Reserved. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
141
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; # End of XML::Atom::Filter |
|
146
|
|
|
|
|
|
|
|