line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::UniqueTagHelpers; |
2
|
10
|
|
|
10
|
|
30637
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
10
|
|
|
|
|
11523
|
|
|
10
|
|
|
|
|
80
|
|
3
|
10
|
|
|
10
|
|
4367
|
use Mojo::Util 'md5_sum'; |
|
10
|
|
|
|
|
63592
|
|
|
10
|
|
|
|
|
8850
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub _block { |
8
|
45
|
50
|
|
45
|
|
248
|
ref $_[0] eq 'CODE' ? $_[0]() : |
|
|
100
|
|
|
|
|
|
9
|
|
|
|
|
|
|
defined $_[0] ? "$_[0]" : |
10
|
|
|
|
|
|
|
'' |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub register { |
14
|
9
|
|
|
9
|
1
|
425
|
my ($self, $app, $conf) = @_; |
15
|
|
|
|
|
|
|
|
16
|
9
|
|
50
|
|
|
42
|
$conf ||= {}; |
17
|
9
|
|
50
|
|
|
99
|
$conf->{max_key_length} //= 256; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$app->helper(stylesheet_for => sub { |
20
|
24
|
|
|
24
|
|
77450
|
my ($c, $name, $content) = @_; |
21
|
24
|
|
50
|
|
|
102
|
$name ||= 'content'; |
22
|
|
|
|
|
|
|
|
23
|
24
|
|
100
|
|
|
85
|
my $hash = $c->stash->{'uniquetaghelpers.stylesheet'} ||= {}; |
24
|
24
|
100
|
|
|
|
474
|
if( defined $content ) { |
25
|
18
|
|
100
|
|
|
73
|
$hash->{$name} ||= {}; |
26
|
18
|
|
|
|
|
42
|
my $key = _block($content); |
27
|
|
|
|
|
|
|
$key = md5_sum( $key ) |
28
|
18
|
50
|
|
|
|
1592
|
if $conf->{max_key_length} < length $key; |
29
|
|
|
|
|
|
|
|
30
|
18
|
100
|
|
|
|
117
|
return $c->content( $name ) if exists $hash->{$name}{$key}; |
31
|
6
|
|
|
|
|
67
|
$hash->{$name}{$key} = 1; |
32
|
|
|
|
|
|
|
|
33
|
6
|
|
|
|
|
69
|
$c->content_for( $name => $c->stylesheet($content) ); |
34
|
|
|
|
|
|
|
} |
35
|
12
|
|
|
|
|
3242
|
return $c->content( $name ); |
36
|
9
|
|
|
|
|
130
|
}); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$app->helper(javascript_for => sub { |
39
|
24
|
|
|
24
|
|
63604
|
my ($c, $name, $content) = @_; |
40
|
24
|
|
50
|
|
|
105
|
$name ||= 'content'; |
41
|
|
|
|
|
|
|
|
42
|
24
|
|
100
|
|
|
65
|
my $hash = $c->stash->{'uniquetaghelpers.javascript'} ||= {}; |
43
|
24
|
100
|
|
|
|
230
|
if( defined $content ) { |
44
|
18
|
|
100
|
|
|
74
|
$hash->{$name} ||= {}; |
45
|
18
|
|
|
|
|
36
|
my $key = _block($content); |
46
|
|
|
|
|
|
|
$key = md5_sum( $key ) |
47
|
18
|
50
|
|
|
|
869
|
if $conf->{max_key_length} < length $key; |
48
|
|
|
|
|
|
|
|
49
|
18
|
100
|
|
|
|
131
|
return $c->content( $name ) if exists $hash->{$name}{$key}; |
50
|
6
|
|
|
|
|
28
|
$hash->{$name}{$key} = 1; |
51
|
|
|
|
|
|
|
|
52
|
6
|
|
|
|
|
63
|
$c->content_for( $name => $c->javascript($content) ); |
53
|
|
|
|
|
|
|
} |
54
|
12
|
|
|
|
|
2692
|
return $c->content( $name ); |
55
|
9
|
|
|
|
|
400
|
}); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$app->helper(unique_for => sub { |
58
|
9
|
|
|
9
|
|
52316
|
my ($c, $name, $content) = @_; |
59
|
9
|
|
50
|
|
|
85
|
$name ||= 'content'; |
60
|
|
|
|
|
|
|
|
61
|
9
|
|
100
|
|
|
30
|
my $hash = $c->stash->{'uniquetaghelpers.unique'} ||= {}; |
62
|
9
|
50
|
|
|
|
105
|
if( defined $content ) { |
63
|
9
|
|
100
|
|
|
33
|
$hash->{$name} ||= {}; |
64
|
9
|
|
|
|
|
23
|
my $key = _block($content); |
65
|
|
|
|
|
|
|
$key = md5_sum( $key ) |
66
|
9
|
100
|
|
|
|
143
|
if $conf->{max_key_length} < length $key; |
67
|
|
|
|
|
|
|
|
68
|
9
|
100
|
|
|
|
57
|
return $c->content( $name ) if exists $hash->{$name}{$key}; |
69
|
3
|
|
|
|
|
14
|
$hash->{$name}{$key} = 1; |
70
|
|
|
|
|
|
|
|
71
|
3
|
|
|
|
|
43
|
$c->content_for( $name => $content ); |
72
|
|
|
|
|
|
|
} |
73
|
3
|
|
|
|
|
353
|
return $c->content( $name ); |
74
|
9
|
|
|
|
|
287
|
}); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
__END__ |