blib/lib/Plack/App/Directory/Xslate.pm

filter: Statementstmt 100% 55 / 55 Branchbran 62.5% 5 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 93.7% 15 / 16 Podpod 25.0% 1 / 4 totaltotal 89.7% 79 / 88 CC 6 SCAR 6.3
CC
6
Cov
94%
new
4.1
serve_path
3.0
__ANON__
1.0
CRAP 1.9
↑ Summary
1 package Plack::App::Directory::Xslate;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 our $VERSION = '0.07';
6  
7 2 ▶use parent qw(Plack::App::Directory);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Text::Xslate;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use Plack ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Plack::App::File ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Plack::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Plack::Util::Accessor qw(xslate_opt xslate_path xslate_param);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
Pod documented
19 1 my $class = shift;
20 1 my $self = $class->SUPER::new(@_);
21  
22 1 $self->xslate_opt->{path} = $self->root;
23 1 $self->{xslate} = Text::Xslate->new($self->xslate_opt);
24 1 $self->{encoder} = Encode::find_encoding('utf-8');
25 1 ▶ $self->xslate_param(+{}) unless $self->xslate_param;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->xslate_param 0 1 1
26  
27 1 ▶ $self->xslate_path(sub {}) unless $self->xslate_path;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $self->xslate_path 0 1 1
28 1 ▶ if (ref $self->xslate_path eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->xslate_path eq "Regexp") 1 0 1
29 1 my $re = $self->xslate_path;
30 1 ▶ $self->xslate_path(sub { $_ =~ $re });
Subroutine __ANON__: called CC=1 SCAR=0.0
31 }
32  
33 1 return $self;
34 }
35  
36 2 ▶sub serve_path {
Subroutine serve_path: called CC=3 SCAR=11.0
Pod undocumented
37 2 my ($self, $env, $path, $fullpath) = @_;
38  
39 2 ▶ if (-f $path && $self->is_xslate_path($path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $path and $self->is_xslate_path($path)) { } 1 1 2
Condition66%2/3
-f $path and $self->is_xslate_path($path)
!ll&&!rl&&r
011
MC/DC50%1/2
-f $path and $self->is_xslate_path($path)
-f $path $self->is_xslate_path($path)
Truth table66%2/3
A and B
A= -f $pathB= $self->is_xslate_path($path)
ABresult
0X0
100
111
40 1 return $self->serve_xslate($env, $path, $fullpath);
41 }
42 else {
43 1 return $self->SUPER::serve_path($env, $path, $fullpath);
44 }
45 }
46  
47 2 ▶sub is_xslate_path {
Subroutine is_xslate_path: called CC=1 SCAR=0.0
Pod undocumented
48 2 my ($self, $path) = @_;
49  
50 2 local $_ = $path;
51 2 return $self->xslate_path->($path);
52 }
53  
54 1 ▶sub serve_xslate {
Subroutine serve_xslate: called CC=1 SCAR=0.0
Pod undocumented
55 1 my ($self, $env, $path, $fullpath) = @_;
56  
57 1 my $tmpl_path = File::Spec->abs2rel($path, $self->root);
58 my $content = $self->{encoder}->encode(
59 1 $self->{xslate}->render($tmpl_path, $self->xslate_param)
60 );
61 return [
62 1 200,
63 [
64 'Content-Type' => 'text/html',
65 'Content-Length' => Plack::Util::content_length($content),
66 ],
67 [$content]
68 ];
69 }
70  
71 2 1;
72 __END__
↑ Summary