blib/lib/Mojolicious/Plugin/UniqueTagHelpers.pm

filter: Statementstmt 100% 51 / 51 Branchbran 81.8% 18 / 22 Conditioncond 77.2% 17 / 22 MC/DCmcdc 54.5% 6 / 11 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 87.8% 101 / 115 CC 23 SCAR 17.3
CC
23
Cov
91%
__ANON__
7.0
__ANON__
7.0
__ANON__
7.0
CRAP 5.6
↑ Summary
1 package Mojolicious::Plugin::UniqueTagHelpers;
2 11 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use Mojo::Util 'md5_sum';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use Encode qw(encode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 our $VERSION = '1.3';
7  
8 48 ▶sub _block {
Subroutine _block: called CC=3 SCAR=11.2
9 48 ▶ ref $_[0] eq 'CODE' ? $_[0]() :
Branch: 2 branches
BranchTrueFalseTotal
ref $_[0] eq 'CODE' ? : 15 33 48
defined $_[0] ? : 33 0 33
10 defined $_[0] ? "$_[0]" :
11 ''
12 }
13  
14 10 ▶sub register {
Subroutine register: called CC=3 SCAR=11.0
Pod documented
15 10 my ($self, $app, $conf) = @_;
16  
17 10 ▶ $conf ||= {};
Condition50%1/2
$conf ||= {}
l!l
100
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
Aresult
11
00
18 10 ▶ $conf->{max_key_length} //= 256;
Condition50%1/2
$conf->{"max_key_length"} //= 256
l!l
010
MC/DC0%0/1
$conf->{"max_key_length"} //= 256
$conf->{"max_key_length"}
Truth table50%1/2
A
A= $conf->{"max_key_length"}
Aresult
11
00
19  
20 24 ▶ $app->helper(stylesheet_for => sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
21 24 my ($c, $name, $content) = @_;
22 24 ▶ $name ||= 'content';
Condition50%1/2
$name ||= "content"
l!l
240
MC/DC0%0/1
$name ||= "content"
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
23  
24 24 ▶ my $hash = $c->stash->{'uniquetaghelpers.stylesheet'} ||= {};
Condition100%2/2
$c->stash->{"uniquetaghelpers.stylesheet"} ||= {}
l!l
213
MC/DC100%1/1
$c->stash->{"uniquetaghelpers.stylesheet"} ||= {}
$c->stash->{"uniquetaghelpers.stylesheet"}
Truth table100%2/2
A
A= $c->stash->{"uniquetaghelpers.stylesheet"}
Aresult
11
00
25 24 ▶ if( defined $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content) 18 6 24
26 18 ▶ $hash->{$name} ||= {};
Condition100%2/2
$hash->{$name} ||= {}
l!l
126
MC/DC100%1/1
$hash->{$name} ||= {}
$hash->{$name}
Truth table100%2/2
A
A= $hash->{$name}
Aresult
11
00
27 18 my $key = _block($content);
28 $key = md5_sum( encode_utf8($key) )
29 18 ▶ if $conf->{max_key_length} < length $key;
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"max_key_length"} < length $key 0 18 18
30  
31 18 ▶ return $c->content( $name ) if exists $hash->{$name}{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash->{$name}{$key} 12 6 18
32 6 $hash->{$name}{$key} = 1;
33  
34 6 $c->content_for( $name => $c->stylesheet($content) );
35 }
36 12 return $c->content( $name );
37 10 });
38  
39 24 ▶ $app->helper(javascript_for => sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
40 24 my ($c, $name, $content) = @_;
41 24 ▶ $name ||= 'content';
Condition50%1/2
$name ||= "content"
l!l
240
MC/DC0%0/1
$name ||= "content"
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
42  
43 24 ▶ my $hash = $c->stash->{'uniquetaghelpers.javascript'} ||= {};
Condition100%2/2
$c->stash->{"uniquetaghelpers.javascript"} ||= {}
l!l
213
MC/DC100%1/1
$c->stash->{"uniquetaghelpers.javascript"} ||= {}
$c->stash->{"uniquetaghelpers.javascript"}
Truth table100%2/2
A
A= $c->stash->{"uniquetaghelpers.javascript"}
Aresult
11
00
44 24 ▶ if( defined $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content) 18 6 24
45 18 ▶ $hash->{$name} ||= {};
Condition100%2/2
$hash->{$name} ||= {}
l!l
126
MC/DC100%1/1
$hash->{$name} ||= {}
$hash->{$name}
Truth table100%2/2
A
A= $hash->{$name}
Aresult
11
00
46 18 my $key = _block($content);
47 $key = md5_sum( encode_utf8($key) )
48 18 ▶ if $conf->{max_key_length} < length $key;
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"max_key_length"} < length $key 0 18 18
49  
50 18 ▶ return $c->content( $name ) if exists $hash->{$name}{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash->{$name}{$key} 12 6 18
51 6 $hash->{$name}{$key} = 1;
52  
53 6 $c->content_for( $name => $c->javascript($content) );
54 }
55 12 return $c->content( $name );
56 10 });
57  
58 12 ▶ $app->helper(unique_for => sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
59 12 my ($c, $name, $content) = @_;
60 12 ▶ $name ||= 'content';
Condition50%1/2
$name ||= "content"
l!l
120
MC/DC0%0/1
$name ||= "content"
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
61  
62 12 ▶ my $hash = $c->stash->{'uniquetaghelpers.unique'} ||= {};
Condition100%2/2
$c->stash->{"uniquetaghelpers.unique"} ||= {}
l!l
84
MC/DC100%1/1
$c->stash->{"uniquetaghelpers.unique"} ||= {}
$c->stash->{"uniquetaghelpers.unique"}
Truth table100%2/2
A
A= $c->stash->{"uniquetaghelpers.unique"}
Aresult
11
00
63 12 ▶ if( defined $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content) 12 0 12
64 12 ▶ $hash->{$name} ||= {};
Condition100%2/2
$hash->{$name} ||= {}
l!l
84
MC/DC100%1/1
$hash->{$name} ||= {}
$hash->{$name}
Truth table100%2/2
A
A= $hash->{$name}
Aresult
11
00
65 12 my $key = _block($content);
66 $key = md5_sum( encode_utf8($key) )
67 12 ▶ if $conf->{max_key_length} < length $key;
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"max_key_length"} < length $key 3 9 12
68  
69 12 ▶ return $c->content( $name ) if exists $hash->{$name}{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash->{$name}{$key} 8 4 12
70 4 $hash->{$name}{$key} = 1;
71  
72 4 $c->content_for( $name => $content );
73 }
74 4 return $c->content( $name );
75 10 });
76 }
77  
78 11 1;
79 __END__
↑ Summary