| 1 | package Perlanet::Feed; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use 5.24.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use XML::Feed; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Perlanet::Feed - represents a feed | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =cut | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 12 | has 'title' => ( | |||||||||||||||||||||||||||
| 17 | isa => 'Str', | ||||||||||||||||||||||||||||
| 18 | is => 'rw', # Ew! | ||||||||||||||||||||||||||||
| 19 | required => 1, | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 12 | has 'feed' => ( | |||||||||||||||||||||||||||
| 23 | isa => 'Str', | ||||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 12 | has 'web' => ( | |||||||||||||||||||||||||||
| 28 | isa => 'Str', | ||||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 12 | has 'format' => ( | |||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 12 | has 'description' => ( | |||||||||||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 12 | has 'author' => ( | |||||||||||||||||||||||||||
| 41 | is => 'ro', | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 12 | has 'email' => ( | |||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 12 | has '_xml_feed' => ( | |||||||||||||||||||||||||||
| 49 | isa => 'XML::Feed', | ||||||||||||||||||||||||||||
| 50 | is => 'rw', # Ew! | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 12 | has 'id' => ( | |||||||||||||||||||||||||||
| 54 | is => 'ro', | ||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 12 | has 'self_link' => ( | |||||||||||||||||||||||||||
| 58 | is => 'ro', | ||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 12 | has 'modified' => ( | |||||||||||||||||||||||||||
| 62 | is => 'ro', | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 12 | has 'max_entries' => ( | |||||||||||||||||||||||||||
| 66 | is => 'ro', | ||||||||||||||||||||||||||||
| 67 | isa => 'Int', | ||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | has 'entries' => ( | ||||||||||||||||||||||||||||
| 71 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 72 | is => 'ro', | ||||||||||||||||||||||||||||
| 73 | 13 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 74 | 12 | traits => [ 'Array' ], | |||||||||||||||||||||||||||
| 75 | handles => { | ||||||||||||||||||||||||||||
| 76 | add_entry => 'push', | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # Handle the url -> feed renaming | ||||||||||||||||||||||||||||
| 81 | 17 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 82 | 17 | my $orig = shift; | |||||||||||||||||||||||||||
| 83 | 17 | my $class = shift; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 17 | my $args; | |||||||||||||||||||||||||||
| 86 | 17 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 13 | $args = $_[0]; | |||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||
| 89 | 4 | $args = { @_ }; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 17 | ▶ | if ($args->{url} and ! $args->{feed}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args->{"url"} and not $args->{"feed"}
MC/DC50%1/2
$args->{"url"} and not $args->{"feed"}
$args->{"url"}
not $args->{"feed"}
Truth table66%2/3
A and not(B)
A= $args->{"url"}B= not $args->{"feed"}
| |||||||||||||||||||||||||||||
| 93 | 1 | warn "Your config file uses 'url' for the URL of the feed. ", | |||||||||||||||||||||||||||
| 94 | "Please update that to 'feed'.\n"; | ||||||||||||||||||||||||||||
| 95 | 1 | $args->{feed} = $args->{url}; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 17 | return $args; | |||||||||||||||||||||||||||
| 99 | 12 | }; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 METHODS | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head2 slug | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | Returns the title of the feed, munged in such a way that if is suitable | ||||||||||||||||||||||||||||
| 106 | for use as an ID or classname in HTML. Or as part of a URL. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 2 | ▶ | sub slug { | ||||||||||||||||||||||||||
|
Subroutine
slug: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 2 | my $slug = lc $self->title; | |||||||||||||||||||||||||||
| 114 | 2 | $slug =~ s/\P{Alnum}+/-/g; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 2 | return $slug; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head2 as_xml | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | Returns a string containing the XML for this feed and all its entries | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 2 | ▶ | sub as_xml { | ||||||||||||||||||||||||||
|
Subroutine
as_xml: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 127 | 2 | my ($format) = @_; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 2 | my $feed = XML::Feed->new($format); | |||||||||||||||||||||||||||
| 130 | 2 | $feed->title($self->title); | |||||||||||||||||||||||||||
| 131 | 2 | $feed->link($self->feed); | |||||||||||||||||||||||||||
| 132 | 2 | $feed->description($self->description); | |||||||||||||||||||||||||||
| 133 | 2 | $feed->author($self->author); | |||||||||||||||||||||||||||
| 134 | 2 | ▶ | if ($format eq 'Atom') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 2 | $feed->{atom}->author->email($self->email); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | 2 | $feed->modified($self->modified); | |||||||||||||||||||||||||||
| 138 | 2 | $feed->self_link($self->self_link); | |||||||||||||||||||||||||||
| 139 | 2 | $feed->id($self->id); | |||||||||||||||||||||||||||
| 140 | 2 | $feed->add_entry($_->_entry) for $self->entries->@*; | |||||||||||||||||||||||||||
| 141 | 2 | return $feed->as_xml; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =head2 url | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | We've renamed the old 'url' attribute to 'feed'. | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | This allows the old name to still work, but generates a warning. | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =cut | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 1 | ▶ | sub url { | ||||||||||||||||||||||||||
|
Subroutine
url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 1 | warn "The url() method has been renamed to feed()\n"; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 1 | return $self->feed; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 12 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 161 | 12 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 162 | 12 | 1; | |||||||||||||||||||||||||||