File Coverage

blib/lib/XML/FeedLite/Normalised.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             #########
2             # Author: rmp@psyphi.net
3             # Maintainer: rmp@psyphi.net
4             # Created: 2006-06-08
5             # Last Modified: $Date: 2009/01/09 14:38:54 $
6             # Id: $Id: Normalised.pm,v 1.4 2009/01/09 14:38:54 zerojinx Exp $
7             # Source: $Source: /cvsroot/xml-feedlite/xml-feedlite/lib/XML/FeedLite/Normalised.pm,v $
8             # $HeadURL$
9             #
10             package XML::FeedLite::Normalised;
11 2     2   5003 use strict;
  2         4  
  2         51  
12 2     2   8 use warnings;
  2         4  
  2         51  
13 2     2   10 use base qw(XML::FeedLite);
  2         4  
  2         133  
14              
15             our $VERSION = do { my @r = (q$Revision: 1.4 $ =~ /\d+/smxg); sprintf '%d.'.'%03d' x $#r, @r };
16              
17             sub entries {
18             my ($self, @args) = @_;
19             my $rawdata = $self->SUPER::entries(@args);
20              
21             for my $feed (keys %{$self->{'format'}}) {
22             my $format = $self->{'format'}->{$feed};
23              
24             if($format !~ /^(atom|rss)/smx) {
25             next;
26             }
27              
28             my $method = "process_$format";
29              
30             $self->$method($rawdata->{$feed});
31             }
32             return $rawdata;
33             }
34              
35             sub process_rss {
36             my ($self, $feeddata) = @_;
37              
38             for my $entry (@{$feeddata}) {
39             %{$entry} = (
40             'title' => $entry->{'title'}->[0]->{'content'} ||q(),
41             'content' => $entry->{'description'}->[0]->{'content'} ||q(),
42             'author' => $entry->{'dc:creator'}->[0]->{'content'} ||q(),
43             'date' => $entry->{'dc:date'}->[0]->{'content'} ||q(),
44             'link' => [map { $_->{'content'}||q() } @{$entry->{'link'}}],
45             );
46             }
47             return;
48             }
49              
50             sub process_atom {
51             my ($self, $feeddata) = @_;
52              
53             for my $entry (@{$feeddata}) {
54             %{$entry} = (
55             'title' => $entry->{'title'}->[0]->{'content'} ||q(),
56             'content' => $entry->{'content'}->[0]->{'content'} ||q(),
57             'author' => $entry->{'author'}->[0]->{'content'} ||q(),
58             'date' => $entry->{'updated'}->[0]->{'content'} ||q(),
59             'link' => [map { $_->{'href'}||q() } @{$entry->{'link'}}],
60             );
61             }
62             return;
63             }
64              
65             1;
66              
67             __END__
68              
69             =head1 NAME
70              
71             XML::FeedLite::Normalised
72              
73             =head1 VERSION
74              
75             $Revision: 1.4 $
76              
77             =head1 SYNOPSIS
78              
79             =head1 DESCRIPTION
80              
81             =head1 SUBROUTINES/METHODS
82              
83             =head2 entries - Data structure of processed feed entries
84              
85             my $hrEntries = $xfln->entries();
86              
87             =head2 process_rss - Processor for RSS 1.0-format entries
88              
89             Used by X::FL::N::entries
90              
91             $xfln->process_rss([...]);
92              
93             =head2 process_atom - Processor for Atom-format entries
94              
95             Used by X::FL::N::entries
96              
97             $xfln->process_atom([...]);
98              
99             =head1 DIAGNOSTICS
100              
101             =head1 CONFIGURATION AND ENVIRONMENT
102              
103             =head1 DEPENDENCIES
104              
105             =head1 INCOMPATIBILITIES
106              
107             =head1 BUGS AND LIMITATIONS
108              
109             =head1 AUTHOR
110              
111             Roger Pettett, E<lt>rmp@psyphi.netE<gt>
112              
113             =head1 LICENSE AND COPYRIGHT
114              
115             Copyright (C) 2005 by Roger Pettett
116              
117             This library is free software; you can redistribute it and/or modify
118             it under the same terms as Perl itself, either Perl version 5.8.4 or,
119             at your option, any later version of Perl 5 you may have available.
120              
121             =cut