lib/Mojolicious/Plugin/ContextResources.pm

filter: Statementstmt 100% 48 / 48 Branchbran 81.2% 13 / 16 Conditioncond 50.0% 7 / 14 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 82.1% 78 / 95 CC 15 SCAR 13.0
CC
15
Cov
87%
register
6.1
_context
4.0
__ANON__
3.0
CRAP 3.7
↑ Summary
1 package Mojolicious::Plugin::ContextResources;
2 4 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use File::Spec::Functions qw(catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 our $VERSION = '0.02';
6  
7 # Get current context path
8 8 ▶sub _context($) {
Subroutine _context: called CC=4 SCAR=14.0
9 8 my ($c) = @_;
10  
11 8 my @path;
12 8 my $stash = $c->stash;
13 8 ▶ if( $stash->{'controller'} && $stash->{'action'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stash->{'controller'} and $stash->{'action'}) { } 4 4 8
elsif ($stash->{'mojo.captures'}{'template'}) { } 4 0 4
Condition66%2/3
$stash->{"controller"} and $stash->{"action"}
!ll&&!rl&&r
404
MC/DC50%1/2
$stash->{"controller"} and $stash->{"action"}
$stash->{"controller"} $stash->{"action"}
Truth table66%2/3
A and B
A= $stash->{"controller"}B= $stash->{"action"}
ABresult
0X0
100
111
14 4 push @path, split m{[/\-]}, $stash->{'controller'};
15 4 push @path, $stash->{'action'};
16 } elsif( $stash->{'mojo.captures'}{'template'} ) {
17 4 push @path, $stash->{'mojo.captures'}{'template'};
18 }
19 8 return @path;
20 }
21  
22 3 ▶sub register {
Subroutine register: called CC=6 SCAR=18.1
Pod documented
23 3 my ($self, $app, $conf) = @_;
24  
25 3 ▶ $conf ||= {};
Condition50%1/2
$conf ||= {}
l!l
30
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
Aresult
11
00
26  
27 # Path
28 3 ▶ $conf->{home} //= $app->home;
Condition33%1/3
$conf->{"home"} //= $app->home
l!l&&r!l&&!r
030
MC/DC0%0/2
$conf->{"home"} //= $app->home
$conf->{"home"} $app->home
Truth table33%1/3
A //= B
A= $conf->{"home"}B= $app->home
ABresult
1X1
011
000
29 3 ▶ $conf->{public} //= 'public';
Condition50%1/2
$conf->{"public"} //= "public"
l!l
03
MC/DC0%0/1
$conf->{"public"} //= "public"
$conf->{"public"}
Truth table50%1/2
A
A= $conf->{"public"}
Aresult
11
00
30 3 ▶ $conf->{js} //= '/js';
Condition50%1/2
$conf->{"js"} //= "/js"
l!l
03
MC/DC0%0/1
$conf->{"js"} //= "/js"
$conf->{"js"}
Truth table50%1/2
A
A= $conf->{"js"}
Aresult
11
00
31 3 ▶ $conf->{css} //= '/css';
Condition50%1/2
$conf->{"css"} //= "/css"
l!l
03
MC/DC0%0/1
$conf->{"css"} //= "/css"
$conf->{"css"}
Truth table50%1/2
A
A= $conf->{"css"}
Aresult
11
00
32  
33 4 ▶ $app->helper(url_context_stylesheet => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
34 4 my ($c) = @_;
35  
36 4 my @path = _context( $c );
37 4 ▶ return undef unless @path;
Branch: 1 branch
BranchTrueFalseTotal
unless @path 0 4 4
38  
39 4 my $file = catfile( $conf->{css}, @path ) . '.css';
40 4 my $path = $conf->{home}->rel_file(catfile $conf->{public}, $file);
41 4 ▶ return undef unless -f $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $path 2 2 4
42  
43 2 return Mojo::URL->new( $file );
44 3 });
45  
46 4 ▶ $app->helper(url_context_javascript => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
47 4 my ($c) = @_;
48  
49 4 my @path = _context( $c );
50 4 ▶ return undef unless @path;
Branch: 1 branch
BranchTrueFalseTotal
unless @path 0 4 4
51  
52 4 my $file = catfile( $conf->{js}, @path ) . '.js';
53 4 my $path = $conf->{home}->rel_file(catfile $conf->{public}, $file);
54 4 ▶ return undef unless -f $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $path 2 2 4
55  
56 2 return Mojo::URL->new( $file );
57 3 });
58  
59 2 ▶ $app->helper(stylesheet_context => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
60 2 my ($c) = @_;
61  
62 2 my $url = $c->url_context_stylesheet;
63 2 ▶ return Mojo::ByteStream->new('') unless $url;
Branch: 1 branch
BranchTrueFalseTotal
unless $url 1 1 2
64  
65 1 return Mojo::ByteStream->new( $c->stylesheet( $url ));
66 3 });
67  
68 2 ▶ $app->helper(javascript_context => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
69 2 my ($c) = @_;
70  
71 2 my $url = $c->url_context_javascript;
72 2 ▶ return Mojo::ByteStream->new('') unless $url;
Branch: 1 branch
BranchTrueFalseTotal
unless $url 1 1 2
73  
74 1 return Mojo::ByteStream->new( $c->javascript( $url ));
75 3 });
76 }
77  
78 4 1;
79 __END__
↑ Summary