File Coverage

blib/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 1     1   10 use feature ':5.10';
  1         3  
  1         139  
3 1     1   9 use strict;
  1         3  
  1         24  
4 1     1   5 use warnings;
  1         2  
  1         45  
5              
6 1     1   6 use Time::Piece;
  1         11  
  1         21  
7 1     1   615 use URI::tag;
  1         579  
  1         33  
8 1     1   895 use XML::FeedPP;
  1         28692  
  1         51  
9              
10 1     1   591 use Riji::Model::Entry;
  1         7  
  1         47  
11              
12 1     1   7 use Mouse;
  1         3  
  1         6  
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', limit => 20) }
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 1     1   830 no Mouse;
  1         4  
  1         7  
79              
80             1;