| 1 | package XML::Atom::Filter; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 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 | 4 | 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<XML::Atom::Filter> 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 | 4 | ▶ | use XML::Atom; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 43 | 4 | ▶ | use XML::Atom::Feed; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | =head2 XML::Atom::Filter->new() | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | Creates an instance of the identity filter. C<XML::Atom::Filter> can be used as | ||||||||||||||||||||
| 48 | a class or an instance. | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 53 | 0 | my $class = shift; | |||||||||||||||||||
| 54 | 0 | 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<STDIN> if not given. After the feed is read and | ||||||||||||||||||||
| 61 | parsed, it will be run through the C<pre>, C<entry> (entry by entry), and | ||||||||||||||||||||
| 62 | C<post> methods. | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 1 | ▶ | sub filter { | ||||||||||||||||||
|
Subroutine
filter: called CC=9 SCAR=24.6
Pod
documented
| |||||||||||||||||||||
| 67 | 1 | my ($self, $fh) = @_; | |||||||||||||||||||
| 68 | 1 | ▶ | my $feed = XML::Atom::Feed->new($fh || \*STDIN) | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$fh || \*STDIN
MC/DC0%0/1
$fh || \*STDIN
$fh
Truth table50%1/2
A
A= $fh
| |||||||||||||||||||||
| 69 | or die XML::Atom::Feed->errstr; | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 1 | $self->pre($feed); | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 1 | my @entries = $feed->entries; | |||||||||||||||||||
| 74 | 1 | @entries = grep { $_ } map { $self->entry($_) } @entries; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | ## Remove existing entries so we can add back the processed ones without duplication. | ||||||||||||||||||||
| 77 | 1 | my @entryNodes; | |||||||||||||||||||
| 78 | 1 | ▶ | if(*XML::Atom::LIBXML) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | 1 | ▶ | @entryNodes = $feed->elem->getElementsByTagNameNS($feed->ns, 'entry') or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||
| 81 | 0 | for my $el ($feed->elem->getDocumentElement->childNodes) { | |||||||||||||||||||
| 82 | 0 | ▶ | push @entryNodes, $el if $el->getName eq 'entry'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | 1 | $_->parentNode->removeChild($_) for @entryNodes; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 1 | $feed->add_entry($_) for @entries; | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 1 | $self->post($feed); | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | =head2 $f->pre($feed) | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | Prepares to process the entries of the feed, an C<XML::Atom::Feed> object. By | ||||||||||||||||||||
| 95 | default, no operation is performed. | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | ▶ | sub pre { 1; } | ||||||||||||||||||
|
Subroutine
pre: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =head2 $f->entry($entry) | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | Processes an entry of the feed, an C<XML::Atom::Entry> object. Returns the new | ||||||||||||||||||||
| 104 | or modified entry reference, or C<undef> 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<must> also modify the | ||||||||||||||||||||
| 108 | entry's C<id>. The Atom feed specification requires entries' C<id> fields to be | ||||||||||||||||||||
| 109 | universally unique. | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | =cut | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 0 | ▶ | sub entry { $_[1]; } | ||||||||||||||||||
|
Subroutine
entry: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =head2 $f->post($feed) | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | Postprocesses the feed, an C<XML::Atom::Feed> object, after the entries are | ||||||||||||||||||||
| 118 | individually processed. By default, the feed's XML is printed to C<STDOUT>. | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 0 | ▶ | sub post { print STDOUT $_[1]->as_xml; } | ||||||||||||||||||
|
Subroutine
post: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =head1 AUTHOR | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | Mark Paschal, C<< <markpasc@markpasc.org> >> | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =head1 BUGS | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | Please report any bugs or feature requests to | ||||||||||||||||||||
| 131 | C<bug-xml-atom-filter@rt.cpan.org>, or through the web interface at | ||||||||||||||||||||
| 132 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-Atom-Filter>. | ||||||||||||||||||||
| 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 | 4 | 1; # End of XML::Atom::Filter | |||||||||||||||||||
| 146 | |||||||||||||||||||||