lib/Mojolicious/Plugin/CSSLoader.pm

filter: Statementstmt 100% 63 / 63 Branchbran 100% 38 / 38 Conditioncond 100% 14 / 14 MC/DCmcdc 100% 8 / 8 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 100% 130 / 130 CC 26 SCAR 25.7
CC
26
Cov
100%
__ANON__
19.0
register
5.0
__ANON__
4.0
CRAP 13.1
↑ Summary
1 package Mojolicious::Plugin::CSSLoader;
2  
3 # ABSTRACT: move css loading to the end of the document
4  
5 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 14 ▶use parent 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 14 our $VERSION = '0.08';
11  
12 14 ▶sub register {
Subroutine register: called CC=5 SCAR=16.1
Pod documented
13 14 my ($self, $app, $config) = @_;
14  
15 14 ▶ my $base = $config->{base} || '';
Condition100%2/2
$config->{'base'} || ''
l!l
59
MC/DC100%1/1
$config->{'base'} || ''
$config->{'base'}
Truth table100%2/2
A
A= $config->{'base'}
Aresult
11
00
16 14 ▶ my $media = $config->{media} || '';
Condition100%2/2
$config->{'media'} || ''
l!l
212
MC/DC100%1/1
$config->{'media'} || ''
$config->{'media'}
Truth table100%2/2
A
A= $config->{'media'}
Aresult
11
00
17  
18 14 ▶ if ( $base and substr( $base, -1 ) ne '/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base and substr($base, -1) ne "/") 4 10 14
Condition100%3/3
$base and substr($base, -1) ne "/"
!ll&&!rl&&r
914
MC/DC100%2/2
$base and substr($base, -1) ne "/"
$base substr($base, -1) ne "/"
Truth table100%3/3
A and B
A= $baseB= substr($base, -1) ne "/"
ABresult
0X0
100
111
19 4 $base .= '/';
20 }
21  
22 43 ▶ $app->helper( css_load => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
23 43 my $c = shift;
24  
25 43 ▶ if ( $_[1]->{check} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1]{"check"}) 8 35 43
26 my $asset = $c->app->static->file(
27 8 ▶ $_[1]->{no_base} ? $_[0] : "$base$_[0]"
Branch: 1 branch
BranchTrueFalseTotal
$_[1]{'no_base'} ? : 1 7 8
28 );
29  
30 8 ▶ return '' if !$asset;
Branch: 1 branch
BranchTrueFalseTotal
unless $asset 3 5 8
31 }
32  
33 40 push @{ $c->stash->{__CSSLOADERFILES__} }, [ @_ ];
34 14 } );
35  
36 32 ▶ $app->hook( after_render => sub {
Subroutine __ANON__: called CC=19 SCAR=29.4
37 32 my ($c, $content, $format) = @_;
38  
39 32 ▶ return if $format ne 'html';
Branch: 1 branch
BranchTrueFalseTotal
if $format ne "html" 1 31 32
40 31 ▶ return if !$c->stash->{__CSSLOADERFILES__};
Branch: 1 branch
BranchTrueFalseTotal
unless $c->stash->{"__CSSLOADERFILES__"} 1 30 31
41 30 ▶ return if 'ARRAY' ne ref $c->stash->{__CSSLOADERFILES__};
Branch: 1 branch
BranchTrueFalseTotal
if "ARRAY" ne ref $c->stash->{"__CSSLOADERFILES__"} 1 29 30
42  
43 my $load_css =
44 join "\n",
45 map{
46 40 my ($file,$config) = @{ $_ };
47 40 ▶ $file //= '';
Condition100%2/2
$file //= ""
l!l
391
MC/DC100%1/1
$file //= ""
$file
Truth table100%2/2
A
A= $file
Aresult
11
00
48  
49 40 ▶ my $local_base = $config->{no_base} ? '' : $base;
Branch: 1 branch
BranchTrueFalseTotal
$config->{'no_base'} ? : 1 39 40
50  
51 40 ▶ $local_base = $c->url_for( $local_base ) if $local_base;
Branch: 1 branch
BranchTrueFalseTotal
if $local_base 11 29 40
52  
53 40 my $local_media = "";
54  
55 40 ▶ $local_media = ' media="' . $media . '"' if $media;
Branch: 1 branch
BranchTrueFalseTotal
if $media 6 34 40
56 40 ▶ $local_media = ' media="' . $config->{media} . '"' if $config->{media};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"media"} 3 37 40
57  
58 40 my $ie_start = '';
59 40 my $ie_end = '';
60  
61 40 ▶ if ( exists $config->{ie} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{"ie"}) 7 33 40
62 7 my $start_extra = '';
63 7 my $end_extra = '';
64 7 my $cmp = '';
65 7 my $version = '';
66  
67 7 ▶ if ( !ref $config->{ie} && !$config->{ie} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $config->{'ie'} || $config->{'ie'}) { } 1 6 7
elsif (ref $config->{'ie'}) { } 5 1 6
Condition100%3/3
ref $config->{'ie'} || $config->{'ie'}
l!l&&r!l&&!r
511
MC/DC100%2/2
ref $config->{'ie'} || $config->{'ie'}
ref $config->{'ie'} $config->{'ie'}
Truth table100%3/3
A || B
A= ref $config->{'ie'}B= $config->{'ie'}
ABresult
1X1
011
000
68 1 $start_extra = '<!-->';
69 1 $end_extra = '<!--';
70 1 $cmp = '!';
71 }
72 elsif( ref $config->{ie} ) {
73 5 my %map = qw/> gt >= gte < lt <= lte/;
74 5 (my $key, $version) = %{ $config->{ie} };
75 5 ▶ $cmp = $map{$key} || '';
Condition100%2/2
$map{$key} || ''
l!l
41
MC/DC100%1/1
$map{$key} || ''
$map{$key}
Truth table100%2/2
A
A= $map{$key}
Aresult
11
00
76 5 ▶ $cmp .= ' ' if $cmp;
Branch: 1 branch
BranchTrueFalseTotal
if $cmp 4 1 5
77 }
78  
79 7 $ie_start = sprintf "<!-- [if %sIE %s]>%s",
80 $cmp,
81 $version,
82 $start_extra;
83  
84 7 $ie_end = sprintf "%s<![endif]-->", $end_extra;
85 }
86  
87 my $return = $config->{no_file} ?
88 40 ▶ qq~$ie_start<style type="text/css">$file</style>$ie_end~ :
Branch: 1 branch
BranchTrueFalseTotal
$config->{'no_file'} ? : 3 37 40
89 qq~$ie_start<link rel="stylesheet" href="$local_base$file"$local_media/>$ie_end~;
90  
91 40 ▶ $file ? $return : ();
Branch: 1 branch
BranchTrueFalseTotal
$file ? : 39 1 40
92 }
93 29 @{ $c->stash->{__CSSLOADERFILES__} };
94  
95 29 ▶ return if !$load_css;
Branch: 1 branch
BranchTrueFalseTotal
unless $load_css 2 27 29
96  
97 27 ▶ ${$content} =~ s!(</head>)!$load_css$1! or ${$content} = $load_css . ${$content};
Branch: 1 branch
BranchTrueFalseTotal
${$content;} =~ s[(</head>)][$load_css$1] or ${$content;} = $load_css . ${$content;} 1 26 27
98 14 });
99 }
100  
101 14 1;
102  
103 __END__
↑ Summary