lib/Riji/Model/Article.pm

filter: Statementstmt 90.5% 115 / 127 Branchbran 57.6% 15 / 26 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 93.3% 28 / 30 Podpod 33.3% 1 / 3 totaltotal 79.9% 163 / 204 CC 20 SCAR 14.2
CC
20
Cov
81%
__ANON__
18.1
__ANON__
5.3
_parse_content
4.0
CRAP 4.2
« lib/Riji/CLI.pm ↑ Summary blib/lib/Riji/CLI/Setup.pm »
1 package Riji::Model::Article;
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 Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use YAML::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Text::Markup::Any ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Text::Xslate;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 9 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 9 has file => (
14 is => 'rw',
15 required => 1,
16 );
17  
18 9 has blog => (
19 is => 'ro',
20 isa => 'Riji::Model::Blog',
21 required => 1,
22 handles => [qw/base_dir fqdn author article_dir site_url repo/],
23 );
24  
25 9 has page => (
26 is => 'ro',
27 isa => 'Int',
28 );
29  
30 has markupper => (
31 is => 'ro',
32 isa => 'Text::Markup::Any',
33 40 ▶ default => sub {
Subroutine __ANON__: called CC=3 SCAR=11.4
34 40 ▶ my $markupper = Riji->config->{markup} || 'Text::Markdown::Discount';
Condition50%1/2
'Riji'->config->{'markup'} || 'Text::Markdown::Discount'
l!l
040
MC/DC0%0/1
'Riji'->config->{'markup'} || 'Text::Markdown::Discount'
'Riji'->config->{'markup'}
Truth table50%1/2
A
A= 'Riji'->config->{'markup'}
Aresult
11
00
35 40 my $obj = Text::Markup::Any->new($markupper);
36 40 ▶ Text::Markdown::Discount::with_html5_tags() if $markupper eq 'Text::Markdown::Discount';
Branch: 1 branch
BranchTrueFalseTotal
if $markupper eq "Text::Markdown::Discount" 40 0 40
37 40 $obj;
38 },
39 9 handles => [qw/markup/],
40 );
41  
42 9 has article_ext => (is => 'ro', default => 'md');
43  
44 has file_path => (
45 is => 'ro',
46 lazy => 1,
47 40 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
48 40 my $self = shift;
49 40 path($self->base_dir, $self->article_dir, $self->file);
50 },
51 9 );
52  
53 has content_raw => (
54 is => 'ro',
55 lazy => 1,
56 40 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
57 40 shift->file_path->slurp_utf8;
58 },
59 9 );
60  
61 9 has body => (is => 'rw');
62  
63 has html_body => (
64 is => 'ro',
65 lazy => 1,
66 33 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
67 33 my $self = shift;
68  
69 33 ▶ my $key = $self->isa('Riji::Model::Entry') ? 'entry' : 'article';
Branch: 1 branch
BranchTrueFalseTotal
$self->isa('Riji::Model::Entry') ? : 27 6 33
70 33 my $body = $self->_pre_proccessor->render_string($self->body, {
71 $key => $self,
72 blog => $self->blog,
73 page => $self->page,
74 });
75 33 $self->markup($body);
76 },
77 9 );
78  
79 has html_body_without_title => (
80 is => 'ro',
81 lazy => 1,
82 14 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
83 14 my $html = shift->html_body;
84 14 $html =~ s!\A\s*<h[1-6].*?</h[1-6]>!!ms;
85 14 $html;
86 },
87 9 );
88  
89 has site_path => (
90 is => 'ro',
91 lazy => 1,
92 14 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
93 14 my $self = shift;
94  
95 14 my $path = '/' . $self->file_path->relative(path($self->base_dir, $self->article_dir));
96 14 my $ext = quotemeta $self->article_ext;
97 14 $path =~ s/\.$ext$//;
98 14 ▶ $path .= '.' . $self->page if $self->page;
Branch: 1 branch
BranchTrueFalseTotal
if $self->page 0 14 14
99 14 $path . '.html';
100 },
101 9 );
102  
103 has url => (
104 is => 'ro',
105 lazy => 1,
106 14 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
107 14 my $self = shift;
108 14 my $root = $self->site_url;
109 14 $root =~ s!/+$!!;
110 14 $root . $self->site_path;
111 },
112 9 );
113 0 ▶sub permalink { goto \&url }
Subroutine permalink: not called CC=1 SCAR=6.9
Pod undocumented
114  
115 #############
116 # Meta datas:
117 has title => (
118 is => 'ro',
119 lazy => 1,
120 33 ▶ default => sub {
Subroutine __ANON__: called CC=3 SCAR=16.7
121 33 my $self = shift;
122 33 ▶ $self->header('title') // sub {
Subroutine __ANON__: called CC=6 SCAR=29.0
123 33 my $prev;
124 33 for my $line ( split /\r?\n/, $self->body ){
125 33 ▶ if ( $line =~ /^#/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^#/) 33 0 33
126 33 $line =~ s/^[#\s]+//;
127 33 $line =~ s/[#\s]+$//;
128 33 return $line;
129 }
130 0 ▶ if ( $line =~ /^(?:(?:-+)|(?:=+))$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(?:(?:-+)|(?:=+))$/) 0 0 0
131 0 ▶ return $prev if $prev && $prev =~ /[^\s]/;
Branch: 1 branch
BranchTrueFalseTotal
if $prev and $prev =~ /[^\s]/ 0 0 0
Condition0%0/3
$prev and $prev =~ /[^\s]/
!ll&&!rl&&r
000
MC/DC0%0/2
$prev and $prev =~ /[^\s]/
$prev $prev =~ /[^\s]/
Truth table0%0/3
A and B
A= $prevB= $prev =~ /[^\s]/
ABresult
0X0
100
111
132 }
133 0 $prev = $line;
134 }
135 0 my $ext = quotemeta $self->article_ext;
136 0 my $title = $self->file_path->basename;
137 0 $title =~ s/\.$ext$//;
138 0 $title =~ s/-/ /g;
139 0 $title;
140 33 ▶ }->() // 'unknown';
Condition40%2/5
($self->header("title") // sub { my $prev; foreach my $line (split(/\r?\n/, $self->body, 0)) { if ($line =~ /^#/) { $line =~ s/^[#\s]+//; $line =~ s/[#\s]+$//; return $line; } ; if ($line =~ /^(?:(?:-+)|(?:=+))$/) { return $prev if $prev and $prev =~ /[^\s]/; } ; $prev = $line; } ; my $ext = quotemeta $self->article_ext; my $title = $self->file_path->basename; $title =~ s/\.$ext$//; $title =~ s/-/ /g; $title; } ->()) // "unknown"
l!l
330
$self->header("title") // sub { my $prev; foreach my $line (split(/\r?\n/, $self->body, 0)) { if ($line =~ /^#/) { $line =~ s/^[#\s]+//; $line =~ s/[#\s]+$//; return $line; } ; if ($line =~ /^(?:(?:-+)|(?:=+))$/) { return $prev if $prev and $prev =~ /[^\s]/; } ; $prev = $line; } ; my $ext = quotemeta $self->article_ext; my $title = $self->file_path->basename; $title =~ s/\.$ext$//; $title =~ s/-/ /g; $title; } ->()
l!l&&r!l&&!r
0330
MC/DC0%0/2
($self->header("title") // sub { my $prev; foreach my $line (split(/\r?\n/, $self->body, 0)) { if ($line =~ /^#/) { $line =~ s/^[#\s]+//; $line =~ s/[#\s]+$//; return $line; } ; if ($line =~ /^(?:(?:-+)|(?:=+))$/) { return $prev if $prev and $prev =~ /[^\s]/; } ; $prev = $line; } ; my $ext = quotemeta $self->article_ext; my $title = $self->file_path->basename; $title =~ s/\.$ext$//; $title =~ s/-/ /g; $title; } ->()) // "unknown"
$self->header("title") sub { my $prev; foreach my $line (split(/\r?\n/, $self->body, 0)) { if ($line =~ /^#/) { $line =~ s/^[#\s]+//; $line =~ s/[#\s]+$//; return $line; } ; if ($line =~ /^(?:(?:-+)|(?:=+))$/) { return $prev if $prev and $prev =~ /[^\s]/; } ; $prev = $line; } ; my $ext = quotemeta $self->article_ext; my $title = $self->file_path->basename; $title =~ s/\.$ext$//; $title =~ s/-/ /g; $title; } ->()
Truth table33%1/3
A // B
A= $self->header("title")B= sub { my $prev; foreach my $line (split(/\r?\n/, $self->body, 0)) { if ($line =~ /^#/) { $line =~ s/^[#\s]+//; $line =~ s/[#\s]+$//; return $line; } ; if ($line =~ /^(?:(?:-+)|(?:=+))$/) { return $prev if $prev and $prev =~ /[^\s]/; } ; $prev = $line; } ; my $ext = quotemeta $self->article_ext; my $title = $self->file_path->basename; $title =~ s/\.$ext$//; $title =~ s/-/ /g; $title; } ->()
ABresult
1X1
011
000
141 },
142 9 );
143  
144 has is_draft => (
145 is => 'ro',
146 lazy => 1,
147 14 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
148 14 shift->header('draft');
149 },
150 9 );
151  
152 has raw_tags => (
153 is => 'ro',
154 lazy => 1,
155 27 ▶ default => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
156 27 my $tags = shift->header('tags');
157 27 ▶ return [] unless $tags;
Branch: 1 branch
BranchTrueFalseTotal
unless $tags 23 4 27
158 4 ▶ $tags = [split /[,\s]+/, $tags] unless ref $tags;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tags 4 0 4
159 4 $tags;
160 },
161 9 );
162  
163 has tags => (
164 is => 'ro',
165 isa => 'ArrayRef[Riji::Model::Tag]',
166 lazy => 1,
167 13 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
168 13 my $self = shift;
169 13 [map {$self->blog->tag($_)} @{ $self->raw_tags }];
170 },
171 9 );
172  
173 has template => (
174 is => 'ro',
175 lazy => 1,
176 26 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
177 26 shift->header('template');
178 },
179 9 );
180  
181 has paginate => (
182 is => 'ro',
183 lazy => 1,
184 12 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
185 12 shift->header('paginate');
186 },
187 9 );
188  
189 9 ▶no Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
190  
191 40 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod documented
192 40 my $self = shift;
193  
194 40 my $ext = $self->article_ext;
195 40 ▶ unless ($self->file =~ /\.\Q$ext\E$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->file =~ /\.\Q$ext\E$/) 26 14 40
196 26 $self->file($self->file . ".$ext");
197 }
198 40 ▶ return unless -f -r $self->file_path;
Branch: 1 branch
BranchTrueFalseTotal
unless -f -r $self->file_path 0 40 40
199 40 $self->_parse_content;
200 }
201  
202 140 ▶sub header {
Subroutine header: called CC=2 SCAR=7.6
Pod undocumented
203 140 my ($self, $key) = @_;
204 140 ▶ if (defined $key){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) { } 140 0 140
205 140 return $self->{headers}{$key};
206 }
207 else{
208 0 return $self->{headers};
209 }
210 }
211  
212 40 ▶sub _parse_content {
Subroutine _parse_content: called CC=4 SCAR=14.0
213 40 my $self = shift;
214 40 my $content_raw = $self->content_raw;
215 40 $content_raw =~ s/\A---\r?\n//ms;
216 40 my ($header_raw, $body) = split /^---\n/ms, $content_raw, 2;
217  
218 40 my $headers = {};
219 40 ▶ if (defined $body) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body) { } 18 22 40
220 18 local $@;
221 18 ▶ $headers = eval {
Condition50%1/2
eval { do { YAML::Tiny::Load($header_raw) } } || {}
l!l
180
MC/DC0%0/1
eval { do { YAML::Tiny::Load($header_raw) } } || {}
eval { do { YAML::Tiny::Load($header_raw) } }
Truth table50%1/2
A
A= eval { do { YAML::Tiny::Load($header_raw) } }
Aresult
11
00
222 18 YAML::Tiny::Load($header_raw);
223 } || {};
224 18 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 18 18
225 0 ($header_raw, $body) = ('', $self->content_raw);
226 }
227 }
228 else {
229 22 ($header_raw, $body) = ('', $header_raw);
230 }
231  
232 40 $self->body($body);
233 40 $self->{header_raw} = $header_raw;
234 40 $self->{headers} = $headers;
235 40 $self;
236 }
237  
238 33 ▶sub _pre_proccessor {
Subroutine _pre_proccessor: called CC=1 SCAR=0.4
239 state $xslate = Text::Xslate->new(
240 type => 'text',
241 path => Riji->template_dir,
242 function => {
243 14 ▶ uri_for => sub { Riji->context->uri_for(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
244 0 ▶ config => sub { Riji->config },
Subroutine __ANON__: not called CC=1 SCAR=6.9
245 33 Riji->get_functions,
246 }
247 );
248 }
249  
250 9 1;
« lib/Riji/CLI.pm ↑ Summary blib/lib/Riji/CLI/Setup.pm »