| 1 | package Riji::Model::Blog; | ||||||||||||||||||||||||||||
| 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 File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Git::Repository 'FileHistory'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use List::UtilsBy qw/rev_sort_by rev_nsort_by sort_by/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use Path::Tiny 'path'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use IPC::Cmd (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use Riji::Model::Atom; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use Riji::Model::Entry; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use Riji::Model::Tag; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 9 | has base_dir => (is => 'ro', required => 1); | |||||||||||||||||||||||||||
| 19 | 9 | has author => (is => 'ro', required => 1); | |||||||||||||||||||||||||||
| 20 | 9 | has title => (is => 'ro', required => 1); | |||||||||||||||||||||||||||
| 21 | 9 | has site_url => ( | |||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||
| 23 | isa => 'URI', | ||||||||||||||||||||||||||||
| 24 | required => 1 | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | has fqdn => ( | ||||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||
| 29 | lazy => 1, | ||||||||||||||||||||||||||||
| 30 | 6 | ▶ | default => sub {shift->site_url->host}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 9 | ); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | has tag_uri_specific_prefix => ( | ||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||
| 35 | lazy => 1, | ||||||||||||||||||||||||||||
| 36 | 6 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 37 | 6 | my $pref = shift->site_url->path; | |||||||||||||||||||||||||||
| 38 | 6 | $pref =~ s!/$!!; | |||||||||||||||||||||||||||
| 39 | 6 | $pref =~ s!^/!!; | |||||||||||||||||||||||||||
| 40 | 6 | $pref =~ s!/!-!g; | |||||||||||||||||||||||||||
| 41 | 6 | ▶ | $pref .= ':' if $pref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 6 | $pref; | |||||||||||||||||||||||||||
| 43 | }, | ||||||||||||||||||||||||||||
| 44 | 9 | ); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 9 | has article_dir => ( | |||||||||||||||||||||||||||
| 47 | is => 'ro', | ||||||||||||||||||||||||||||
| 48 | default => 'article', | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 9 | has entry_dir => ( | |||||||||||||||||||||||||||
| 52 | is => 'ro', | ||||||||||||||||||||||||||||
| 53 | default => 'article/entry', | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | has article_path => ( | ||||||||||||||||||||||||||||
| 57 | is => 'ro', | ||||||||||||||||||||||||||||
| 58 | lazy => 1, | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 0 | path($self->base_dir, $self->article_dir); | |||||||||||||||||||||||||||
| 62 | }, | ||||||||||||||||||||||||||||
| 63 | 9 | ); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | has entry_path => ( | ||||||||||||||||||||||||||||
| 66 | is => 'ro', | ||||||||||||||||||||||||||||
| 67 | lazy => 1, | ||||||||||||||||||||||||||||
| 68 | 8 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 69 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 70 | 8 | path($self->base_dir, $self->entry_dir); | |||||||||||||||||||||||||||
| 71 | }, | ||||||||||||||||||||||||||||
| 72 | 9 | ); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | has repo => ( | ||||||||||||||||||||||||||||
| 75 | is => 'ro', | ||||||||||||||||||||||||||||
| 76 | lazy => 1, | ||||||||||||||||||||||||||||
| 77 | 7 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | 7 | Git::Repository->new(work_tree => $self->base_dir); | |||||||||||||||||||||||||||
| 80 | }, | ||||||||||||||||||||||||||||
| 81 | 9 | ); | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | has branch => ( | ||||||||||||||||||||||||||||
| 84 | is => 'ro', | ||||||||||||||||||||||||||||
| 85 | 9 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||
| 86 | 9 | ▶ | my $git = IPC::Cmd::can_run('git') or return 'master'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 9 | my $ret = IPC::Cmd::run_forked(join(' ', $git, 'config', 'init.defaultBranch')); | |||||||||||||||||||||||||||
| 88 | 9 | ▶ | if ($ret->{exit_code} == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | chomp($ret->{stdout}); | |||||||||||||||||||||||||||
| 90 | 0 | return $ret->{stdout}; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 9 | 'master'; | |||||||||||||||||||||||||||
| 93 | }, | ||||||||||||||||||||||||||||
| 94 | 9 | ); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | has atom => ( | ||||||||||||||||||||||||||||
| 97 | is => 'ro', | ||||||||||||||||||||||||||||
| 98 | lazy => 1, | ||||||||||||||||||||||||||||
| 99 | 6 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 100 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 101 | 6 | Riji::Model::Atom->new( | |||||||||||||||||||||||||||
| 102 | blog => $self | ||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||
| 104 | }, | ||||||||||||||||||||||||||||
| 105 | 9 | ); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | has tag_map => ( | ||||||||||||||||||||||||||||
| 108 | is => 'ro', | ||||||||||||||||||||||||||||
| 109 | isa => 'HashRef[Riji::Model::Tag]', | ||||||||||||||||||||||||||||
| 110 | lazy => 1, | ||||||||||||||||||||||||||||
| 111 | 6 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 112 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 113 | 6 | my %map; | |||||||||||||||||||||||||||
| 114 | 6 | for my $entry (@{ $self->entries }) { | |||||||||||||||||||||||||||
| 115 | 14 | for my $tag (@{ $entry->raw_tags }) { | |||||||||||||||||||||||||||
| 116 | 4 | ▶ | $map{$tag} ||= Riji::Model::Tag->new(name => $tag); | ||||||||||||||||||||||||||
|
Condition33%1/3
$map{$tag} ||= "Riji::Model::Tag"->new("name", $tag)
MC/DC0%0/2
$map{$tag} ||= "Riji::Model::Tag"->new("name", $tag)
$map{$tag}
"Riji::Model::Tag"->new("name", $tag)
Truth table33%1/3
A ||= B
A= $map{$tag}B= "Riji::Model::Tag"->new("name", $tag)
| |||||||||||||||||||||||||||||
| 117 | 4 | push @{$map{$tag}->entries}, $entry; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 6 | \%map; | |||||||||||||||||||||||||||
| 121 | }, | ||||||||||||||||||||||||||||
| 122 | 9 | ); | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | has tags => ( | ||||||||||||||||||||||||||||
| 125 | is => 'ro', | ||||||||||||||||||||||||||||
| 126 | isa => 'ArrayRef[Riji::Model::Tag]', | ||||||||||||||||||||||||||||
| 127 | lazy => 1, | ||||||||||||||||||||||||||||
| 128 | 6 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 129 | 6 | ▶ | [rev_nsort_by {$_->count} sort_by {$_->name} values %{ shift->tag_map }] | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 130 | }, | ||||||||||||||||||||||||||||
| 131 | 9 | ); | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 9 | ▶ | no Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 49 | ▶ | sub entries { | ||||||||||||||||||||||||||
|
Subroutine
entries: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 136 | 49 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | $self->{entries} ||= [ | ||||||||||||||||||||||||||||
| 139 | 14 | ▶ | rev_sort_by { $_->published_at->datetime . $_->file } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 140 | 14 | ▶ | grep { $_ && !$_->is_draft } | ||||||||||||||||||||||||||
|
Condition33%1/3
$_ && !$_->is_draft
MC/DC0%0/2
$_ && !$_->is_draft
$_
!$_->is_draft
Truth table33%1/3
A && not(B)
A= $_B= !$_->is_draft
| |||||||||||||||||||||||||||||
| 141 | 14 | map { $self->entry($_->relative($self->entry_path) .'') } | |||||||||||||||||||||||||||
| 142 | 49 | ▶ | do { | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"entries"} ||= [&rev_sort_by(sub {
$_->published_at->datetime . $_->file;
}
, grep({$_ and not $_->is_draft;} map({$self->entry($_->relative($self->entry_path) . '');} do {
my $itr = $self->entry_path->iterator({"recurse", 1});
my @files;
while (my $file = &$itr()) {
do {
next unless -f -r $file;
push @files, $file
};
};
@files
})))]
MC/DC100%1/1
$self->{"entries"} ||= [&rev_sort_by(sub {
$_->published_at->datetime . $_->file;
}
, grep({$_ and not $_->is_draft;} map({$self->entry($_->relative($self->entry_path) . '');} do {
my $itr = $self->entry_path->iterator({"recurse", 1});
my @files;
while (my $file = &$itr()) {
do {
next unless -f -r $file;
push @files, $file
};
};
@files
})))]
$self->{"entries"}
Truth table100%2/2
A
A= $self->{"entries"}
| |||||||||||||||||||||||||||||
| 143 | 6 | my $itr = $self->entry_path->iterator({recurse => 1}); | |||||||||||||||||||||||||||
| 144 | 6 | my @files; | |||||||||||||||||||||||||||
| 145 | 6 | ▶ | while (my $file = $itr->()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 14 | ▶ | next unless -f -r $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 14 | push @files, $file; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 6 | @files; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | ]; | ||||||||||||||||||||||||||||
| 152 | 49 | ▶ | return $self->{entries} unless @args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 12 | $self->_search_entries(@args); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 28 | ▶ | sub entry { | ||||||||||||||||||||||||||
|
Subroutine
entry: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 158 | 28 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 28 | my $entry = Riji::Model::Entry->new( | |||||||||||||||||||||||||||
| 161 | file => File::Spec->catfile('entry', $file), | ||||||||||||||||||||||||||||
| 162 | blog => $self, | ||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||
| 164 | 28 | ▶ | return () unless -f -r $entry->file_path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 28 | $entry; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 12 | ▶ | sub article { | ||||||||||||||||||||||||||
|
Subroutine
article: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 170 | 12 | my ($self, $file, $opt) = @_; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 12 | my $article = Riji::Model::Article->new( | |||||||||||||||||||||||||||
| 173 | file => $file, | ||||||||||||||||||||||||||||
| 174 | blog => $self, | ||||||||||||||||||||||||||||
| 175 | %$opt, | ||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||
| 177 | 12 | ▶ | return () unless -f -r $article->file_path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 12 | ▶ | return () if !$article->paginate && $article->page; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $article->paginate and $article->page
MC/DC0%0/2
not $article->paginate and $article->page
not $article->paginate
$article->page
Truth table33%1/3
not(A) and B
A= not $article->paginateB= $article->page
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 12 | $article; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 8 | ▶ | sub tag { | ||||||||||||||||||||||||||
|
Subroutine
tag: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 184 | 8 | my ($self, $tag) = @_; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 8 | $tag = Riji::Model::Tag->normalize_tag($tag); | |||||||||||||||||||||||||||
| 187 | 8 | $self->tag_map->{$tag}; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # _search_entries(tag => 'hoge', sort_by => 'last_updated_at', sort_order => 'desc', limit => 10); | ||||||||||||||||||||||||||||
| 191 | 12 | ▶ | sub _search_entries { | ||||||||||||||||||||||||||
|
Subroutine
_search_entries: called CC=15 SCAR=32.8
| |||||||||||||||||||||||||||||
| 192 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 193 | 0 | ▶ | my %opt = @_ == 1 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 12 | my @entries = @{ $self->entries }; | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 12 | ▶ | if (my $tag = $opt{tag}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 0 | @entries = grep { grep {$_ eq $tag} @{ $_->raw_tags } } @entries; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 12 | ▶ | if (my $sort_by = $opt{sort_by}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 6 | my @enable_fields = qw/published_at last_modified_at title/; | |||||||||||||||||||||||||||
| 202 | 6 | ▶ | if (grep {$sort_by eq $_} @enable_fields) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 6 | ▶ | if ($sort_by eq 'last_modified_at') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 204 | 6 | ▶ | @entries = rev_sort_by {$_->last_modified_at->datetime . $_->title} @entries; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | elsif ($sort_by ne 'published_at') { | ||||||||||||||||||||||||||||
| 207 | 0 | ▶ | @entries = rev_sort_by {$_->title} @entries; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | else { | ||||||||||||||||||||||||||||
| 211 | 0 | warn "$sort_by is unknown sort item"; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 12 | ▶ | my $sort_order = lc($opt{sort_order} || ''); | ||||||||||||||||||||||||||
|
Condition50%1/2
$opt{'sort_order'} || ''
MC/DC0%0/1
$opt{'sort_order'} || ''
$opt{'sort_order'}
Truth table50%1/2
A
A= $opt{'sort_order'}
| |||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ($sort_order && ! grep {$sort_order eq $_} qw/asc desc/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$sort_order and not grep({$sort_order eq $_;} "asc", "desc")
MC/DC0%0/2
$sort_order and not grep({$sort_order eq $_;} "asc", "desc")
$sort_order
not grep({$sort_order eq $_;} "asc", "desc")
Truth table33%1/3
A and not(B)
A= $sort_orderB= not grep({$sort_order eq $_;} "asc", "desc")
| |||||||||||||||||||||||||||||
| 217 | 0 | warn "$sort_order is unknown sort_order"; | |||||||||||||||||||||||||||
| 218 | 0 | $sort_order = undef; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | 12 | ▶ | if ($opt{sort_by} && !$sort_order) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opt{"sort_by"} and not $sort_order
MC/DC50%1/2
$opt{"sort_by"} and not $sort_order
$opt{"sort_by"}
not $sort_order
Truth table66%2/3
A and not(B)
A= $opt{"sort_by"}B= not $sort_order
| |||||||||||||||||||||||||||||
| 221 | $sort_order = { | ||||||||||||||||||||||||||||
| 222 | last_modified_at => 'desc', | ||||||||||||||||||||||||||||
| 223 | published_at => 'desc', | ||||||||||||||||||||||||||||
| 224 | title => 'asc', | ||||||||||||||||||||||||||||
| 225 | 6 | }->{$opt{sort_by}}; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | 12 | ▶ | $sort_order ||= 'desc'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$sort_order ||= "desc"
MC/DC100%1/1
$sort_order ||= "desc"
$sort_order
Truth table100%2/2
A
A= $sort_order
| |||||||||||||||||||||||||||||
| 228 | 12 | ▶ | @entries = reverse @entries if $sort_order eq 'asc'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 12 | ▶ | if (my $limit = $opt{limit}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 6 | @entries = splice @entries, 0, $limit; | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | 12 | [@entries]; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 9 | 1; | |||||||||||||||||||||||||||