| 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
| |||||||||||||||
| 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 ||= {}
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
| |||||||||||||||
| 18 | 10 | ▶ | $conf->{max_key_length} //= 256; | ||||||||||||
|
Condition50%1/2
$conf->{"max_key_length"} //= 256
MC/DC0%0/1
$conf->{"max_key_length"} //= 256
$conf->{"max_key_length"}
Truth table50%1/2
A
A= $conf->{"max_key_length"}
| |||||||||||||||
| 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"
MC/DC0%0/1
$name ||= "content"
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||
| 23 | |||||||||||||||
| 24 | 24 | ▶ | my $hash = $c->stash->{'uniquetaghelpers.stylesheet'} ||= {}; | ||||||||||||
|
Condition100%2/2
$c->stash->{"uniquetaghelpers.stylesheet"} ||= {}
MC/DC100%1/1
$c->stash->{"uniquetaghelpers.stylesheet"} ||= {}
$c->stash->{"uniquetaghelpers.stylesheet"}
Truth table100%2/2
A
A= $c->stash->{"uniquetaghelpers.stylesheet"}
| |||||||||||||||
| 25 | 24 | ▶ | if( defined $content ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | 18 | ▶ | $hash->{$name} ||= {}; | ||||||||||||
|
Condition100%2/2
$hash->{$name} ||= {}
MC/DC100%1/1
$hash->{$name} ||= {}
$hash->{$name}
Truth table100%2/2
A
A= $hash->{$name}
| |||||||||||||||
| 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
| |||||||||||||||
| 30 | |||||||||||||||
| 31 | 18 | ▶ | return $c->content( $name ) if exists $hash->{$name}{$key}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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"
MC/DC0%0/1
$name ||= "content"
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||
| 42 | |||||||||||||||
| 43 | 24 | ▶ | my $hash = $c->stash->{'uniquetaghelpers.javascript'} ||= {}; | ||||||||||||
|
Condition100%2/2
$c->stash->{"uniquetaghelpers.javascript"} ||= {}
MC/DC100%1/1
$c->stash->{"uniquetaghelpers.javascript"} ||= {}
$c->stash->{"uniquetaghelpers.javascript"}
Truth table100%2/2
A
A= $c->stash->{"uniquetaghelpers.javascript"}
| |||||||||||||||
| 44 | 24 | ▶ | if( defined $content ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | 18 | ▶ | $hash->{$name} ||= {}; | ||||||||||||
|
Condition100%2/2
$hash->{$name} ||= {}
MC/DC100%1/1
$hash->{$name} ||= {}
$hash->{$name}
Truth table100%2/2
A
A= $hash->{$name}
| |||||||||||||||
| 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
| |||||||||||||||
| 49 | |||||||||||||||
| 50 | 18 | ▶ | return $c->content( $name ) if exists $hash->{$name}{$key}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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"
MC/DC0%0/1
$name ||= "content"
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||
| 61 | |||||||||||||||
| 62 | 12 | ▶ | my $hash = $c->stash->{'uniquetaghelpers.unique'} ||= {}; | ||||||||||||
|
Condition100%2/2
$c->stash->{"uniquetaghelpers.unique"} ||= {}
MC/DC100%1/1
$c->stash->{"uniquetaghelpers.unique"} ||= {}
$c->stash->{"uniquetaghelpers.unique"}
Truth table100%2/2
A
A= $c->stash->{"uniquetaghelpers.unique"}
| |||||||||||||||
| 63 | 12 | ▶ | if( defined $content ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | 12 | ▶ | $hash->{$name} ||= {}; | ||||||||||||
|
Condition100%2/2
$hash->{$name} ||= {}
MC/DC100%1/1
$hash->{$name} ||= {}
$hash->{$name}
Truth table100%2/2
A
A= $hash->{$name}
| |||||||||||||||
| 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
| |||||||||||||||
| 68 | |||||||||||||||
| 69 | 12 | ▶ | return $c->content( $name ) if exists $hash->{$name}{$key}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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__ | ||||||||||||||