| 1 | package Riji::Model::Entry; | ||||||||||
| 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 HTTP::Date; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 9 | ▶ | use Time::Piece; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 9 | ▶ | use URI::tag; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 9 | ▶ | use Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 9 | extends 'Riji::Model::Article'; | |||||||||
| 13 | |||||||||||
| 14 | has repo_path => ( | ||||||||||
| 15 | is => 'ro', | ||||||||||
| 16 | lazy => 1, | ||||||||||
| 17 | 28 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 28 | my $self = shift; | |||||||||
| 19 | 28 | my $repo_dir = $self->repo->run(qw/rev-parse --show-toplevel/); | |||||||||
| 20 | 28 | $self->file_path->relative($repo_dir) | |||||||||
| 21 | }, | ||||||||||
| 22 | 9 | ); | |||||||||
| 23 | |||||||||||
| 24 | has file_history => ( | ||||||||||
| 25 | is => 'ro', | ||||||||||
| 26 | lazy => 1, | ||||||||||
| 27 | 28 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 28 | my $self = shift; | |||||||||
| 29 | 28 | $self->repo->file_history($self->repo_path.'', {branch => $self->blog->branch}); | |||||||||
| 30 | }, | ||||||||||
| 31 | 9 | handles => [qw/created_by last_modified_by/], | |||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | has tag_uri => ( | ||||||||||
| 35 | is => 'ro', | ||||||||||
| 36 | lazy => 1, | ||||||||||
| 37 | 14 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 14 | my $self = shift; | |||||||||
| 39 | |||||||||||
| 40 | 14 | my $tag_uri = URI->new('tag:'); | |||||||||
| 41 | 14 | $tag_uri->authority($self->fqdn); | |||||||||
| 42 | 14 | $tag_uri->date($self->created_at->strftime('%Y-%m-%d')); | |||||||||
| 43 | 14 | $tag_uri->specific($self->blog->tag_uri_specific_prefix . join('-', grep {$_ ne ''} split(m{/}, $self->site_path))); | |||||||||
| 44 | |||||||||||
| 45 | 14 | $tag_uri; | |||||||||
| 46 | }, | ||||||||||
| 47 | 9 | ); | |||||||||
| 48 | |||||||||||
| 49 | has next => ( | ||||||||||
| 50 | is => 'rw', | ||||||||||
| 51 | lazy => 1, | ||||||||||
| 52 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 53 | 0 | my $self = shift; | |||||||||
| 54 | 0 | my ($prev, $next) = $self->_search_prev_and_next; | |||||||||
| 55 | 0 | $self->prev($prev); | |||||||||
| 56 | 0 | $next; | |||||||||
| 57 | }, | ||||||||||
| 58 | 9 | ); | |||||||||
| 59 | |||||||||||
| 60 | has prev => ( | ||||||||||
| 61 | is => 'rw', | ||||||||||
| 62 | lazy => 1, | ||||||||||
| 63 | 13 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 13 | my $self = shift; | |||||||||
| 65 | 13 | my ($prev, $next) = $self->_search_prev_and_next; | |||||||||
| 66 | 13 | $self->next($next); | |||||||||
| 67 | 13 | $prev; | |||||||||
| 68 | }, | ||||||||||
| 69 | 9 | ); | |||||||||
| 70 | |||||||||||
| 71 | has last_modified_at => ( | ||||||||||
| 72 | is => 'ro', | ||||||||||
| 73 | lazy => 1, | ||||||||||
| 74 | 28 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||
| 75 | 28 | my $self = shift; | |||||||||
| 76 | |||||||||||
| 77 | 28 | my $updated_at = $self->updated_at; | |||||||||
| 78 | 28 | my $published_at = $self->published_at; | |||||||||
| 79 | 28 | ▶ | $published_at > $updated_at ? $published_at : $updated_at; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | }, | ||||||||||
| 81 | 9 | ); | |||||||||
| 82 | |||||||||||
| 83 | has created_at => ( | ||||||||||
| 84 | is => 'ro', | ||||||||||
| 85 | lazy => 1, | ||||||||||
| 86 | 28 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 87 | 28 | localtime($_[0]->file_history->created_at); | |||||||||
| 88 | }, | ||||||||||
| 89 | 9 | ); | |||||||||
| 90 | |||||||||||
| 91 | has updated_at => ( | ||||||||||
| 92 | is => 'ro', | ||||||||||
| 93 | lazy => 1, | ||||||||||
| 94 | 28 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 95 | 28 | localtime($_[0]->file_history->updated_at); | |||||||||
| 96 | }, | ||||||||||
| 97 | 9 | ); | |||||||||
| 98 | |||||||||||
| 99 | has published_at => ( | ||||||||||
| 100 | is => 'ro', | ||||||||||
| 101 | lazy => 1, | ||||||||||
| 102 | 28 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||
| 103 | 28 | my $self = shift; | |||||||||
| 104 | 28 | ▶ | if (my $pubdate = $self->header('pubdate')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 0 | return localtime(str2time($pubdate)); | |||||||||
| 106 | } | ||||||||||
| 107 | 28 | $self->created_at; | |||||||||
| 108 | } | ||||||||||
| 109 | 9 | ); | |||||||||
| 110 | |||||||||||
| 111 | 9 | ▶ | no Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 112 | |||||||||||
| 113 | 28 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 114 | 28 | my $self = shift; | |||||||||
| 115 | 28 | ▶ | return unless $self->file_history; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | |||||||||||
| 117 | # surely assign them | ||||||||||
| 118 | 28 | $self->last_modified_at; | |||||||||
| 119 | 28 | $self->created_at; | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | 13 | ▶ | sub _search_prev_and_next { | ||||||||
|
Subroutine
_search_prev_and_next: called CC=4 SCAR=13.9
| |||||||||||
| 123 | 13 | my $self = shift; | |||||||||
| 124 | 13 | my ($prev, $next); | |||||||||
| 125 | |||||||||||
| 126 | 13 | my $found; | |||||||||
| 127 | 13 | my @entries = @{ $self->blog->entries }; | |||||||||
| 128 | 13 | ▶ | while (my $entry = shift @entries) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | 24 | ▶ | if ($entry->file eq $self->file) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | 13 | $prev = shift @entries; | |||||||||
| 131 | 13 | $found++; last; | |||||||||
| 132 | } | ||||||||||
| 133 | 11 | $next = $entry; | |||||||||
| 134 | } | ||||||||||
| 135 | 13 | ▶ | return () unless $found; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 13 | ($prev, $next); | |||||||||
| 137 | } | ||||||||||
| 138 | |||||||||||
| 139 | 9 | 1; | |||||||||