| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::UniqueTagHelpers; |
|
2
|
11
|
|
|
11
|
|
20326
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
|
11
|
|
|
|
|
7001
|
|
|
|
11
|
|
|
|
|
71
|
|
|
3
|
11
|
|
|
11
|
|
3252
|
use Mojo::Util 'md5_sum'; |
|
|
11
|
|
|
|
|
74286
|
|
|
|
11
|
|
|
|
|
757
|
|
|
4
|
11
|
|
|
11
|
|
51
|
use Encode qw(encode_utf8); |
|
|
11
|
|
|
|
|
16
|
|
|
|
11
|
|
|
|
|
6146
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.3'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub _block { |
|
9
|
48
|
50
|
|
48
|
|
147
|
ref $_[0] eq 'CODE' ? $_[0]() : |
|
|
|
100
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
defined $_[0] ? "$_[0]" : |
|
11
|
|
|
|
|
|
|
'' |
|
12
|
|
|
|
|
|
|
} |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub register { |
|
15
|
10
|
|
|
10
|
1
|
384
|
my ($self, $app, $conf) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
10
|
|
50
|
|
|
39
|
$conf ||= {}; |
|
18
|
10
|
|
50
|
|
|
58
|
$conf->{max_key_length} //= 256; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$app->helper(stylesheet_for => sub { |
|
21
|
24
|
|
|
24
|
|
45039
|
my ($c, $name, $content) = @_; |
|
22
|
24
|
|
50
|
|
|
56
|
$name ||= 'content'; |
|
23
|
|
|
|
|
|
|
|
|
24
|
24
|
|
100
|
|
|
43
|
my $hash = $c->stash->{'uniquetaghelpers.stylesheet'} ||= {}; |
|
25
|
24
|
100
|
|
|
|
222
|
if( defined $content ) { |
|
26
|
18
|
|
100
|
|
|
52
|
$hash->{$name} ||= {}; |
|
27
|
18
|
|
|
|
|
26
|
my $key = _block($content); |
|
28
|
|
|
|
|
|
|
$key = md5_sum( encode_utf8($key) ) |
|
29
|
18
|
50
|
|
|
|
788
|
if $conf->{max_key_length} < length $key; |
|
30
|
|
|
|
|
|
|
|
|
31
|
18
|
100
|
|
|
|
76
|
return $c->content( $name ) if exists $hash->{$name}{$key}; |
|
32
|
6
|
|
|
|
|
16
|
$hash->{$name}{$key} = 1; |
|
33
|
|
|
|
|
|
|
|
|
34
|
6
|
|
|
|
|
48
|
$c->content_for( $name => $c->stylesheet($content) ); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
12
|
|
|
|
|
2061
|
return $c->content( $name ); |
|
37
|
10
|
|
|
|
|
84
|
}); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$app->helper(javascript_for => sub { |
|
40
|
24
|
|
|
24
|
|
45805
|
my ($c, $name, $content) = @_; |
|
41
|
24
|
|
50
|
|
|
54
|
$name ||= 'content'; |
|
42
|
|
|
|
|
|
|
|
|
43
|
24
|
|
100
|
|
|
60
|
my $hash = $c->stash->{'uniquetaghelpers.javascript'} ||= {}; |
|
44
|
24
|
100
|
|
|
|
157
|
if( defined $content ) { |
|
45
|
18
|
|
100
|
|
|
48
|
$hash->{$name} ||= {}; |
|
46
|
18
|
|
|
|
|
27
|
my $key = _block($content); |
|
47
|
|
|
|
|
|
|
$key = md5_sum( encode_utf8($key) ) |
|
48
|
18
|
50
|
|
|
|
685
|
if $conf->{max_key_length} < length $key; |
|
49
|
|
|
|
|
|
|
|
|
50
|
18
|
100
|
|
|
|
67
|
return $c->content( $name ) if exists $hash->{$name}{$key}; |
|
51
|
6
|
|
|
|
|
19
|
$hash->{$name}{$key} = 1; |
|
52
|
|
|
|
|
|
|
|
|
53
|
6
|
|
|
|
|
43
|
$c->content_for( $name => $c->javascript($content) ); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
12
|
|
|
|
|
2143
|
return $c->content( $name ); |
|
56
|
10
|
|
|
|
|
272
|
}); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$app->helper(unique_for => sub { |
|
59
|
12
|
|
|
12
|
|
49778
|
my ($c, $name, $content) = @_; |
|
60
|
12
|
|
50
|
|
|
52
|
$name ||= 'content'; |
|
61
|
|
|
|
|
|
|
|
|
62
|
12
|
|
100
|
|
|
42
|
my $hash = $c->stash->{'uniquetaghelpers.unique'} ||= {}; |
|
63
|
12
|
50
|
|
|
|
110
|
if( defined $content ) { |
|
64
|
12
|
|
100
|
|
|
36
|
$hash->{$name} ||= {}; |
|
65
|
12
|
|
|
|
|
24
|
my $key = _block($content); |
|
66
|
|
|
|
|
|
|
$key = md5_sum( encode_utf8($key) ) |
|
67
|
12
|
100
|
|
|
|
84
|
if $conf->{max_key_length} < length $key; |
|
68
|
|
|
|
|
|
|
|
|
69
|
12
|
100
|
|
|
|
78
|
return $c->content( $name ) if exists $hash->{$name}{$key}; |
|
70
|
4
|
|
|
|
|
12
|
$hash->{$name}{$key} = 1; |
|
71
|
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
42
|
$c->content_for( $name => $content ); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
4
|
|
|
|
|
331
|
return $c->content( $name ); |
|
75
|
10
|
|
|
|
|
107
|
}); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
|
79
|
|
|
|
|
|
|
__END__ |