File Coverage

blib/lib/XML/RSS/Parser/Feed.pm
Criterion Covered Total %
statement 28 37 75.6
branch 3 4 75.0
condition 1 2 50.0
subroutine 9 15 60.0
pod 8 11 72.7
total 49 69 71.0


line stmt bran cond sub pod time code
1             package XML::RSS::Parser::Feed;
2              
3 1     1   1199 use strict;
  1         2  
  1         44  
4 1     1   5 use base qw(XML::Elemental::Document);
  1         2  
  1         944  
5              
6 1     1   2771 use XML::Elemental::Util qw(process_name);
  1         283  
  1         67  
7 1     1   685 use XML::RSS::Parser::Util;
  1         3  
  1         453  
8              
9             sub new {
10 2     2 1 672 my $class = shift;
11 2         17 my $self = $class->SUPER::new(@_);
12 2         16 $self->{rss_namespace_uri} = '';
13 2         7 $self;
14             }
15              
16             # Very loose determination of the RSS namespace (if any). Goes to the
17             # first child of the root element (most likely the channel) and extracts
18             # its namespace URI. We don't use the root element because in RSS 1.0
19             # the root element is not in the RSS (default) namespace.
20             sub find_rss_namespace {
21 2     2 0 969 my $doc = shift;
22 2         15 my $root = $doc->contents->[0];
23 2         13 foreach my $node (@{$root->contents}) {
  2         12  
24 4 100       25 if (ref($node) eq 'XML::RSS::Parser::Element') {
25 2         10 my ($n, $ns) = process_name($node->name);
26 2   50     39 $doc->{rss_namespace_uri} = $ns || '';
27 2         7 return $doc->{rss_namespace_uri};
28             }
29             }
30 0         0 return '';
31             }
32              
33             sub rss_namespace_uri {
34 88 50   88 1 721 $_[0]->{rss_namespace_uri} = $_[1] if defined $_[1];
35 88         428 $_[0]->{rss_namespace_uri};
36             }
37              
38             # sub name { 'rss' }
39 1     1 1 12 sub query { $_[0]->contents->[0]->query($_[1]) }
40 0     0 1 0 sub channel { my @c = $_[0]->query('/channel'); $c[0]; }
  0         0  
41 0     0 1 0 sub image { $_[0]->query('image'); }
42 0     0 1 0 sub items { $_[0]->query('item'); }
43 0     0 1 0 sub item_count { my @i = $_[0]->items; scalar @i; }
  0         0  
44 0     0 1 0 sub as_xml { XML::RSS::Parser::Util::as_xml($_[0]->contents->[0],1,$_[1]) }
45              
46             ###--- hack to keep Class::XPath happy.
47 0     0 0 0 sub qname { '' }
48 1     1 0 30 sub attribute_qnames { }
49              
50             1;
51              
52             __END__