File Coverage

/root/.cpan/build/Riji-v1.1.4-0/lib/Riji/Model/Atom.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod n/a
total 36 36 100.0


line stmt bran cond sub pod time code
1             package Riji::Model::Atom;
2 9     9   57 use feature ':5.10';
  9         169  
  9         1658  
3 9     9   58 use strict;
  9         14  
  9         283  
4 9     9   33 use warnings;
  9         15  
  9         578  
5              
6 9     9   4210 use Time::Piece;
  9         71958  
  9         61  
7 9     9   4949 use URI::tag;
  9         4492  
  9         305  
8 9     9   7862 use XML::FeedPP;
  9         272157  
  9         458  
9              
10 9     9   5755 use Riji::Model::Entry;
  9         40  
  9         470  
11              
12 9     9   123 use Mouse;
  9         19  
  9         63  
13              
14             has blog => (
15             is => 'ro',
16             isa => 'Riji::Model::Blog',
17             required => 1,
18             handles => [qw/fqdn author title entry_dir site_url repo/],
19             weak_ref => 1,
20             );
21              
22             has entry_datas => (
23             is => 'ro',
24             isa => 'ArrayRef[HashRef]',
25             lazy => 1,
26             default => sub {
27             my $self = shift;
28             [
29             map { +{
30             title => $_->title,
31             description => {
32             '#text' => \$_->html_body_without_title, #pass scalar ref for CDATA
33             -type => 'html',
34             },
35             pubDate => $_->last_modified_at->epoch,
36             author => $_->created_by,
37             guid => $_->tag_uri->as_string,
38             published => XML::FeedPP::Util::epoch_to_w3cdtf($_->published_at->epoch),
39             link => $_->url,
40             } } @{ $self->blog->entries(sort_by => 'last_modified_at') }
41             ]
42             },
43             );
44              
45             has feed => (
46             is => 'ro',
47             default => sub {
48             my $self = shift;
49              
50             my $file_history = $self->repo->file_history($self->entry_dir, {branch => $self->blog->branch});
51              
52             my $updated_at = $file_history->updated_at;
53             my $created_at = $file_history->created_at;
54              
55             my $tag_uri = URI->new('tag:');
56             $tag_uri->authority($self->fqdn);
57             $tag_uri->date(gmtime($created_at)->strftime('%Y-%m-%d'));
58             $tag_uri->specific($self->blog->tag_uri_specific_prefix);
59             my $feed = XML::FeedPP::Atom::Atom10->new(
60             link => $self->site_url,
61             author => {name => $self->author},
62             title => $self->title,
63             pubDate => $updated_at,
64             id => $tag_uri->as_string,
65             generator => {
66             '#text' => 'Perl Riji',
67             -version => $Riji::VERSION,
68             -uri => 'https://github.com/Songmu/p5-Riji',
69             },
70             );
71             $feed->add_item(%$_) for @{ $self->entry_datas };
72             $feed->sort_item;
73              
74             $feed;
75             },
76             );
77              
78 9     9   10014 no Mouse;
  9         20  
  9         51  
79              
80             1;