lib/Riji.pm

filter: Statementstmt 94.2% 99 / 105 Branchbran 53.8% 14 / 26 Conditioncond 60.0% 9 / 15 MC/DCmcdc 44.4% 4 / 9 Subroutinesub 91.3% 21 / 23 Podpod 0.0% 0 / 4 totaltotal 80.7% 147 / 182 CC 21 SCAR 18.3
CC
21
Cov
84%
__ANON__
19.4
get_functions
6.0
__ANON__
4.0
CRAP 6.2
« lib/Riji/CLI/NewEntry.pm ↑ Summary lib/Riji/CLI.pm »
1 package Riji;
2 15 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use Puncheur::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 15 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶use YAML::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 15 ▶use version 0.77; our $VERSION = version->declare("v1.2.0");
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 15 __PACKAGE__->setting(
14 handle_static => 1,
15 );
16 15 __PACKAGE__->load_plugins(qw/Model ShareDir/);
17  
18 38 ▶sub base_dir { state $b = File::Spec->rel2abs('./') }
Subroutine base_dir: called CC=1 SCAR=0.0
Pod undocumented
19  
20 11 ▶sub load_config {
Subroutine load_config: called CC=2 SCAR=6.9
Pod undocumented
21 11 my $self = shift;
22 11 my $file = File::Spec->catfile($self->base_dir, 'riji.yml');
23 11 ▶ unless (-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 2 9 11
24 2 die sprintf "config file: [%s] not found.\n", $file;
25 }
26 9 YAML::Tiny::LoadFile($file);
27 }
28  
29 12 ▶get '/{match:(?:[-_a-zA-Z0-9]+(?:\.[0-9]+)?.html)?}' => sub {
Subroutine __ANON__: called CC=10 SCAR=29.6
30 12 my ($c, $args) = @_;
31  
32 12 ▶ my $match = $args->{match} || 'index.html';
Condition100%2/2
$args->{'match'} || 'index.html'
l!l
66
MC/DC100%1/1
$args->{'match'} || 'index.html'
$args->{'match'}
Truth table100%2/2
A
A= $args->{'match'}
Aresult
11
00
33 12 my ($basename, $page) = $match =~ m!^([-_a-zA-Z0-9]+)(?:\.([0-9]+))?\.html$!;
34  
35 12 my $blog = $c->model('Blog');
36 12 ▶ my $article = $blog->article($basename, {$page ? (page => $page) : ()});
Branch: 1 branch
BranchTrueFalseTotal
$page ? : 0 12 12
37  
38 12 ▶ if (!$article && $basename ne 'index') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $article and $basename ne "index") 0 12 12
Condition33%1/3
not $article and $basename ne "index"
!ll&&!rl&&r
1200
MC/DC0%0/2
not $article and $basename ne "index"
not $article $basename ne "index"
Truth table33%1/3
not(A) and B
A= not $articleB= $basename ne "index"
ABresult
0X0
100
111
39 0 return $c->res_404;
40 }
41  
42 12 ▶ my $tmpl = $article && $article->template;
Condition33%1/3
$article && $article->template
!ll&&!rl&&r
0012
MC/DC0%0/2
$article && $article->template
$article $article->template
Truth table33%1/3
A && B
A= $articleB= $article->template
ABresult
0X0
100
111
43 12 ▶ unless (defined $tmpl) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tmpl) 0 12 12
44 0 ▶ $tmpl = $basename if $basename eq 'index';
Branch: 1 branch
BranchTrueFalseTotal
if $basename eq "index" 0 0 0
45 0 ▶ $tmpl //= 'default';
Condition0%0/2
$tmpl //= "default"
l!l
00
MC/DC0%0/1
$tmpl //= "default"
$tmpl
Truth table0%0/2
A
A= $tmpl
Aresult
11
00
46 }
47 12 ▶ $tmpl .= '.tx' unless $tmpl =~ /\.tx$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tmpl =~ /\.tx$/ 12 0 12
48  
49 12 $c->render($tmpl, {
50 blog => $blog,
51 page => $page,
52 article => $article,
53 });
54 15 };
55  
56 15 my $s = '[-_a-zA-Z0-9]+';
57 14 ▶get "/entry/{name:$s(?:\.$s)*(?:/$s(?:\.$s)*)*}.html" => sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
58 14 my ($c, $args) = @_;
59  
60 14 my $name = $args->{name};
61 14 my $blog = $c->model('Blog');
62 14 my $entry = $blog->entry($name);
63 14 ▶ return $c->res_404 unless $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry 0 14 14
64  
65 14 ▶ my $tmpl = $entry->template // 'entry';
Condition100%2/2
$entry->template // "entry"
l!l
113
MC/DC100%1/1
$entry->template // "entry"
$entry->template
Truth table100%2/2
A
A= $entry->template
Aresult
11
00
66 14 ▶ $tmpl .= '.tx' unless $tmpl =~ /\.tx$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tmpl =~ /\.tx$/ 14 0 14
67  
68 14 $c->render($tmpl, {
69 blog => $blog,
70 entry => $entry,
71 });
72 15 };
73  
74 4 ▶get '/tag/:tag.html' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
75 4 my ($c, $args) = @_;
76  
77 4 my $tag = $args->{tag};
78 4 my $blog = $c->model('Blog');
79 4 $tag = $blog->tag($tag);
80 4 ▶ return $c->res_404 unless $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless $tag 0 4 4
81  
82 4 $c->render('tag.tx', {
83 blog => $blog,
84 tag => $tag,
85 });
86 15 };
87  
88 6 ▶get '/atom.xml' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
89 6 my $c = shift;
90  
91 6 my $atom = $c->model('Blog')->atom;
92 6 my $xml = $atom->feed->to_string;
93 6 my $atom_url = $atom->site_url . '/atom.xml';
94 6 $atom_url =~ s{//atom\.xml$}{/atom.xml};
95 6 $xml =~ s{(\s+)(<link[^>]+>)}{$1$2$1<link rel="self" type="application/atom+xml" href="$atom_url" />};
96 6 $c->create_response(200, ['Content-Type' => 'application/atom+xml'], [encode($c->encoding, $xml)]);
97 15 };
98  
99 12 ▶sub get_functions {
Subroutine get_functions: called CC=6 SCAR=18.0
Pod undocumented
100 12 my $self = shift;
101  
102 12 state %functions;
103 12 my $functionspl = File::Spec->catfile($self->base_dir, 'share', 'functions.pl');
104 12 ▶ if (-f -r $functionspl && !%functions) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f -r $functionspl and not %functions) 2 10 12
Condition100%3/3
-f -r $functionspl and not %functions
!ll&&!rl&&r
822
MC/DC100%2/2
-f -r $functionspl and not %functions
-f -r $functionspl not %functions
Truth table100%3/3
A and not(B)
A= -f -r $functionsplB= not %functions
ABresult
0X0
100
111
105 2 my $code = do {
106 2 local $/;
107 2 ▶ open my $fh, '<', $functionspl or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $functionspl or die $! 2 0 2
108 <$fh>
109 2 };
110 2 my $package = 'Riji::_Sandbox::Functions';
111 2 ▶ eval <<"..."; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
112 package $package;
113 use strict;
114 use warnings;
115 use utf8;
116  
117 $code
118 1;
119 ...
120 2 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 2 2
121 0 die "$err\n";
122 }
123 2 require Module::Functions;
124 2 my @functions = Module::Functions::get_public_functions($package);
125 2 for my $func (@functions) {
126 4 $functions{$func} = $package->can($func);
127 }
128 }
129 12 %functions;
130 }
131  
132 7 ▶sub create_view {
Subroutine create_view: called CC=2 SCAR=7.9
Pod undocumented
133 7 my $self = shift;
134  
135 Text::Xslate->new(
136 path => $self->template_dir,
137 module => [
138 'Text::Xslate::Bridge::Star',
139 ],
140 function => {
141 4 ▶ c => sub { $self->context },
Subroutine __ANON__: called CC=1 SCAR=0.0
142 105 ▶ uri_for => sub { $self->context->uri_for(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
143 0 ▶ uri_with => sub { $self->context->req->uri_with(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
144 $self->get_functions,
145 },
146 0 ▶ ($self->debug_mode ? ( warn_handler => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
147 0 Text::Xslate->print( # print method escape html automatically
148 '[[', @_, ']]',
149 );
150 7 ▶ } ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
$self->debug_mode ? : 0 6 6
151 );
152 }
153  
154 15 1;
155 __END__
« lib/Riji/CLI/NewEntry.pm ↑ Summary lib/Riji/CLI.pm »