This file is indexed.

/usr/share/perl5/Catmandu/Importer/Atom.pm is in libcatmandu-atom-perl 0.02-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package Catmandu::Importer::Atom;

use namespace::clean;
use Catmandu::Sane;
use Catmandu::Util qw(trim);
use XML::Atom::Client;
use Moo;

with 'Catmandu::Importer';

my $ENTRY_ATTRS    = [qw(id title published updated summary rights)];
my $CONTENT_ATTRS  = [qw(mode type body)];
my $PERSON_ATTRS   = [qw(name email uri url homepage)];
my $LINK_ATTRS     = [qw(rel href hreflang title type length)];
my $CATEGORY_ATTRS = [qw(term label scheme)];

has url     => (is => 'ro', required => 1);
has entries => (is => 'ro', init_arg => undef, lazy => 1, builder => '_build_entries');

sub _build_entries {
    my $self = $_[0];
    my $feed = XML::Atom::Client->new->getFeed($self->url);
    [map {
        my $entry = $_;
        my $entry_data = {};
        for my $key (@$ENTRY_ATTRS) {
            $entry_data->{$key} = trim($entry->$key || next) || next;
        }
        if (my $content = $entry->content) {
            for my $key (@$CONTENT_ATTRS) {
                $entry_data->{content}{$key} = trim($content->$key || next) || next;
            }
        }
        if (my $author = $entry->author) {
            for my $key (@$PERSON_ATTRS) {
                $entry_data->{author}{$key} = trim($author->$key || next) || next;
            }
        }
        if (my $contributor = $entry->contributor) {
            for my $key (@$PERSON_ATTRS) {
                $entry_data->{contributor}{$key} = trim($contributor->$key || next) || next;
            }
        }
        if (my @category = $entry->category) {
            $entry_data->{category} = [map {
                my $category = $_;
                my $category_data = {};
                for my $key (@$CATEGORY_ATTRS) {
                    $category_data->{$key} = trim($category->$key || next) || next;
                }
                $category_data;
            } @category];
        }
        if (my @links = $entry->link) {
            $entry_data->{link} = [map {
                my $link = $_;
                my $link_data = {};
                for my $key (@$LINK_ATTRS) {
                    $link_data->{$key} = trim($link->$key || next) || next;
                }
                $link_data;
            } @links];
        }
        for my $node ($entry->elem->childNodes) {
            my $uri = $node->namespaceURI;
            next if (! $uri || $uri eq 'http://purl.org/atom/ns#');
            my $name  = $node->nodeName;
            my $value = $node->textContent;
            $entry_data->{$name} = $value;
        }
        $entry_data;
    } $feed->entries];
}

sub to_array { goto &entries }

sub generator {
    my ($self) = @_;
    my $n = 0;
    sub {
        $self->entries->[$n++];
    };
}

=head1 NAME

Catmandu::Importer::Atom - Package that imports Atom feeds

=head1 SYNOPSIS

    use Catmandu::Importer::Atom;

    my $importer = Catmandu::Importer::Atom->new(url => "...");

    my $n = $importer->each(sub {
        my $hashref = $_[0];
        # ...
    });

=head1 METHODS

=head2 new(url => URL,[entries => [qw(...)])

Create a new Atom importer for the URL. Optionally provide a entries parameter with the
feed items you want to import.

=head2 count

=head2 each(&callback)

=head2 ...

Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. The
Catmandu::Importer::Atom methods are not idempotent: Atom feeds can only be read once.

=head1 SEE ALSO

L<Catmandu::Iterable>

=cut

1;