| 1 | package Miril::Util; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use autodie; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use File::Spec::Functions qw(catfile); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use List::Util qw(first); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Miril::URL qw(); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Miril::DateTime qw(); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | ### ACCESSORS ### | ||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | use Object::Tiny qw(cfg); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | ### CONSTRUCTOR ### | ||||||||||
| 17 | |||||||||||
| 18 | sub new | ||||||||||
| 19 | 0 | ▶ | { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 20 | 0 | my ($class, $cfg) = @_; | |||||||||
| 21 | 0 | my $self = bless {}, $class; | |||||||||
| 22 | 0 | $self->{cfg} = $cfg; | |||||||||
| 23 | 0 | return $self; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | ### PUBLIC METHODS ### | ||||||||||
| 27 | |||||||||||
| 28 | sub inflate_date_published | ||||||||||
| 29 | 0 | ▶ | { | ||||||||
|
Subroutine
inflate_date_published: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 30 | 0 | my ($self, $old_date, $new_status) = @_; | |||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | if ($new_status eq 'published') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | { | ||||||||||
| 34 | 0 | ▶ | return $old_date | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | ? Miril::DateTime->new($old_date) | ||||||||||
| 36 | : Miril::DateTime->new(time); | ||||||||||
| 37 | } | ||||||||||
| 38 | else | ||||||||||
| 39 | { | ||||||||||
| 40 | 0 | return undef; | |||||||||
| 41 | } | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | sub inflate_date_modified | ||||||||||
| 45 | 0 | ▶ | { | ||||||||
|
Subroutine
inflate_date_modified: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 46 | 0 | my ($self, $filename) = @_; | |||||||||
| 47 | 0 | return time - ( (-M $filename) * 86400 ); | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | sub inflate_in_path | ||||||||||
| 51 | 0 | ▶ | { | ||||||||
|
Subroutine
inflate_in_path: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 52 | 0 | my ($self, $id) = @_; | |||||||||
| 53 | 0 | return catfile($self->cfg->data_path, $id); | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | sub inflate_out_path | ||||||||||
| 57 | 0 | ▶ | { | ||||||||
|
Subroutine
inflate_out_path: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 58 | 0 | my ($self, $name, $type) = @_; | |||||||||
| 59 | 0 | return catfile($self->cfg->output_path, $type->location, $name . ".html"); | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | sub inflate_type | ||||||||||
| 63 | 0 | ▶ | { | ||||||||
|
Subroutine
inflate_type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 64 | 0 | my ($self, $id) = @_; | |||||||||
| 65 | 0 | ▶ | return first { $_->id eq $id } $self->cfg->types->list; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | sub inflate_author | ||||||||||
| 69 | 0 | ▶ | { | ||||||||
|
Subroutine
inflate_author: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 70 | 0 | my ($self, $author) = @_; | |||||||||
| 71 | 0 | ▶ | return $author ? $author : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | sub inflate_topics | ||||||||||
| 75 | 0 | ▶ | { | ||||||||
|
Subroutine
inflate_topics: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 76 | 0 | my ($self, @topics) = @_; | |||||||||
| 77 | 0 | my %topics_lookup = map {$_ => 1} @topics; | |||||||||
| 78 | 0 | my @topic_objects = grep { $topics_lookup{$_->{id}} } $self->cfg->topics->list; | |||||||||
| 79 | 0 | return \@topic_objects; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | sub inflate_post_url | ||||||||||
| 83 | 0 | ▶ | { | ||||||||
|
Subroutine
inflate_post_url: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 84 | 0 | my ($self, $name, $type, $date) = @_; | |||||||||
| 85 | 0 | my $cfg = $self->cfg; | |||||||||
| 86 | 0 | my $url = Miril::URL->new( | |||||||||
| 87 | abs => 'http://' . $cfg->domain . $cfg->http_dir . $type->location . $name . '.html', | ||||||||||
| 88 | rel => $cfg->http_dir . $type->location . $name . '.html', | ||||||||||
| 89 | tag => 'tag:' . $cfg->domain . ',' . $date->strftime('%Y-%m-%d') . ':/' . $name, | ||||||||||
| 90 | ); | ||||||||||
| 91 | 0 | return $url; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | sub inflate_list_url | ||||||||||
| 95 | 0 | ▶ | { | ||||||||
|
Subroutine
inflate_list_url: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 96 | 0 | my ($self, $id, $location) = @_; | |||||||||
| 97 | 0 | my $cfg = $self->cfg; | |||||||||
| 98 | 0 | my $date = Miril::DateTime->new(time()); | |||||||||
| 99 | 0 | ▶ | return Miril::URL->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | abs => 'http://' . $cfg->domain . $cfg->http_dir . $location, | ||||||||||
| 101 | rel => $cfg->http_dir . $location, | ||||||||||
| 102 | tag => $id ? 'tag:' . $cfg->domain . ',' . $date->strftime('%Y-%m-%d') . ':/list/' . $id : undef, | ||||||||||
| 103 | ); | ||||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 1 | 1; | |||||||||