| 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
Condition66%2/3
$stash->{"controller"} and $stash->{"action"}
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"}
| |||||||||||||||||||||||||||||||||
| 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 ||= {}
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
| |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | # Path | ||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | $conf->{home} //= $app->home; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$conf->{"home"} //= $app->home
MC/DC0%0/2
$conf->{"home"} //= $app->home
$conf->{"home"}
$app->home
Truth table33%1/3
A //= B
A= $conf->{"home"}B= $app->home
| |||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | $conf->{public} //= 'public'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$conf->{"public"} //= "public"
MC/DC0%0/1
$conf->{"public"} //= "public"
$conf->{"public"}
Truth table50%1/2
A
A= $conf->{"public"}
| |||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | $conf->{js} //= '/js'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$conf->{"js"} //= "/js"
MC/DC0%0/1
$conf->{"js"} //= "/js"
$conf->{"js"}
Truth table50%1/2
A
A= $conf->{"js"}
| |||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | $conf->{css} //= '/css'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$conf->{"css"} //= "/css"
MC/DC0%0/1
$conf->{"css"} //= "/css"
$conf->{"css"}
Truth table50%1/2
A
A= $conf->{"css"}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 1 | return Mojo::ByteStream->new( $c->javascript( $url )); | |||||||||||||||||||||||||||||||
| 75 | 3 | }); | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 4 | 1; | |||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||||