| 1 | package Riji::Model::Atom; | ||
| 2 | 9 | ▶ | use feature ':5.10'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 9 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 9 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 9 | ▶ | use Time::Piece; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 9 | ▶ | use URI::tag; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 9 | ▶ | use XML::FeedPP; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 9 | ▶ | use Riji::Model::Entry; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 9 | ▶ | use Mouse; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | 9 | 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 | 6 | ▶ | default => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 27 | 6 | my $self = shift; | |
| 28 | [ | ||
| 29 | map { +{ | ||
| 30 | 14 | 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 | 6 | } } @{ $self->blog->entries(sort_by => 'last_modified_at') } | |
| 41 | ] | ||
| 42 | }, | ||
| 43 | 9 | ); | |
| 44 | |||
| 45 | has feed => ( | ||
| 46 | is => 'ro', | ||
| 47 | 6 | ▶ | default => sub { |
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||
| 48 | 6 | my $self = shift; | |
| 49 | |||
| 50 | 6 | my $file_history = $self->repo->file_history($self->entry_dir, {branch => $self->blog->branch}); | |
| 51 | |||
| 52 | 6 | my $updated_at = $file_history->updated_at; | |
| 53 | 6 | my $created_at = $file_history->created_at; | |
| 54 | |||
| 55 | 6 | my $tag_uri = URI->new('tag:'); | |
| 56 | 6 | $tag_uri->authority($self->fqdn); | |
| 57 | 6 | $tag_uri->date(gmtime($created_at)->strftime('%Y-%m-%d')); | |
| 58 | 6 | $tag_uri->specific($self->blog->tag_uri_specific_prefix); | |
| 59 | 6 | 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 | 6 | $feed->add_item(%$_) for @{ $self->entry_datas }; | |
| 72 | 6 | $feed->sort_item; | |
| 73 | |||
| 74 | 6 | $feed; | |
| 75 | }, | ||
| 76 | 9 | ); | |
| 77 | |||
| 78 | 9 | ▶ | no Mouse; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 79 | |||
| 80 | 9 | 1; | |