Yeb/Plugin/Static.pm

filter: Statementstmt 95.3% 41 / 43 Branchbran 58.3% 7 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 2 totaltotal 80.0% 60 / 75 CC 8 SCAR 13.5
CC
8
Cov
84%
add_middleware_static
8.8
BUILD
2.0
__ANON__
1.1
CRAP 3.8
« Yeb/Application.pm ↑ Summary Yeb/Class.pm »
1 package Yeb::Plugin::Static;
2 2 our $AUTHORITY = 'cpan:GETTY';
3 # ABSTRACT: Yeb Plugin for Plack::Middleware::Static
4 2 $Yeb::Plugin::Static::VERSION = '0.104';
5 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Plack::Middleware::Static;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 has app => ( is => 'ro', required => 1 );
11 2 has class => ( is => 'ro', required => 1 );
12  
13 has middleware_statics => (
14 is => 'ro',
15 lazy => 1,
16 1 ▶ builder => sub {[]},
Subroutine _build_middleware_statics: called CC=1 SCAR=0.0
17 2 );
18  
19 has local_static => (
20 is => 'ro',
21 lazy => 1,
22 0 ▶ builder => sub { 0 },
Subroutine _build_local_static: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=1.2
23 2 );
24  
25 2 has content_type => (
26 is => 'ro',
27 predicate => 1,
28 );
29  
30 2 has default_root => (
31 is => 'ro',
32 predicate => 1,
33 );
34  
35 2 ▶sub add_middleware_static {
Subroutine add_middleware_static: called CC=7 SCAR=21.8
Pod undocumented
36 2 my ( $self, $from, $root, $pass_through, $content_type ) = @_;
37 2 ▶ $root = $self->default_root if !defined $root and $self->has_default_root;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $root and $self->has_default_root 0 2 2
Condition33%1/3
not defined $root and $self->has_default_root
!ll&&!rl&&r
200
MC/DC0%0/2
not defined $root and $self->has_default_root
not defined $root $self->has_default_root
Truth table33%1/3
not(A) and B
A= not defined $rootB= $self->has_default_root
ABresult
0X0
100
111
38 2 ▶ croak "Static needs a root directory for a static directory" unless defined $root;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root 0 2 2
39 2 ▶ unshift @{$self->middleware_statics}, Plack::Middleware::Static->new(
Branch: 3 branches
BranchTrueFalseTotal
$pass_through ? : 1 1 2
defined $content_type ? : 0 2 2
$self->has_content_type ? : 0 2 2
40 path => $from,
41 root => path($root)->absolute,
42 pass_through => $pass_through ? 1 : 0,
43 defined $content_type
44 ? ( content_type => $content_type )
45 : $self->has_content_type
46 ? ( content_type => $self->content_type )
47 : (),
48 );
49 }
50  
51 1 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=7.0
Pod undocumented
52 1 my ( $self ) = @_;
53 1 ▶ $self->app->register_function('static',sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
54 1 my ( $from, $root, $content_type ) = @_;
55 1 $self->add_middleware_static($from,$root,1,$content_type);
56 1 });
57 1 ▶ $self->app->register_function('static_404',sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
58 1 my ( $from, $root, $content_type ) = @_;
59 1 $self->add_middleware_static($from,$root,0,$content_type);
60 1 });
61 1 ▶ my $class = $self->local_static
Branch: 1 branch
BranchTrueFalseTotal
$self->local_static ? : 0 1 1
62 ? $self->class
63 : $self->app->y_main;
64 16 ▶ $class->prepend_to_chain("/...",sub {
Subroutine __ANON__: called CC=1 SCAR=0.1
65 0 ▶ map { my $mw = $_; sub () { $mw } } @{$self->middleware_statics}
Subroutine __ANON__: not called CC=1 SCAR=0.1
66 1 });
67 }
68  
69 2 1;
70  
71 __END__
« Yeb/Application.pm ↑ Summary Yeb/Class.pm »