line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::UniqueTagHelpers; |
2
|
8
|
|
|
8
|
|
26325
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
8
|
|
|
|
|
8538
|
|
|
8
|
|
|
|
|
67
|
|
3
|
8
|
|
|
8
|
|
3388
|
use Mojo::Util 'md5_sum'; |
|
8
|
|
|
|
|
82467
|
|
|
8
|
|
|
|
|
7614
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.1'; |
6
|
|
|
|
|
|
|
|
7
|
33
|
100
|
|
33
|
|
106
|
sub _block { ref $_[0] eq 'CODE' ? $_[0]() : $_[0] } |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub register { |
10
|
7
|
|
|
7
|
1
|
280
|
my ($self, $app, $conf) = @_; |
11
|
|
|
|
|
|
|
|
12
|
7
|
|
50
|
|
|
30
|
$conf ||= {}; |
13
|
7
|
|
50
|
|
|
50
|
$conf->{max_key_length} //= 256; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$app->helper(stylesheet_for => sub { |
16
|
16
|
|
|
16
|
|
38349
|
my ($c, $name, $content) = @_; |
17
|
16
|
|
50
|
|
|
47
|
$name ||= 'content'; |
18
|
|
|
|
|
|
|
|
19
|
16
|
|
100
|
|
|
38
|
my $hash = $c->stash->{'uniquetaghelpers.stylesheet'} ||= {}; |
20
|
16
|
100
|
|
|
|
145
|
if( defined $content ) { |
21
|
12
|
|
100
|
|
|
44
|
$hash->{$name} ||= {}; |
22
|
12
|
|
|
|
|
23
|
my $key = _block($content); |
23
|
|
|
|
|
|
|
$key = md5_sum( $key // '' ) |
24
|
12
|
50
|
0
|
|
|
139
|
if $conf->{max_key_length} < length $key; |
25
|
|
|
|
|
|
|
|
26
|
12
|
100
|
|
|
|
64
|
return $c->content( $name ) if exists $hash->{$name}{$key}; |
27
|
4
|
|
|
|
|
19
|
$hash->{$name}{$key} = 1; |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
|
|
48
|
$c->content_for( $name => $c->stylesheet($content) ); |
30
|
|
|
|
|
|
|
} |
31
|
8
|
|
|
|
|
1836
|
return $c->content( $name ); |
32
|
7
|
|
|
|
|
87
|
}); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$app->helper(javascript_for => sub { |
35
|
16
|
|
|
16
|
|
38466
|
my ($c, $name, $content) = @_; |
36
|
16
|
|
50
|
|
|
47
|
$name ||= 'content'; |
37
|
|
|
|
|
|
|
|
38
|
16
|
|
100
|
|
|
44
|
my $hash = $c->stash->{'uniquetaghelpers.javascript'} ||= {}; |
39
|
16
|
100
|
|
|
|
147
|
if( defined $content ) { |
40
|
12
|
|
100
|
|
|
42
|
$hash->{$name} ||= {}; |
41
|
12
|
|
|
|
|
22
|
my $key = _block($content); |
42
|
|
|
|
|
|
|
$key = md5_sum( $key // '' ) |
43
|
12
|
50
|
0
|
|
|
101
|
if $conf->{max_key_length} < length $key; |
44
|
|
|
|
|
|
|
|
45
|
12
|
100
|
|
|
|
58
|
return $c->content( $name ) if exists $hash->{$name}{$key}; |
46
|
4
|
|
|
|
|
16
|
$hash->{$name}{$key} = 1; |
47
|
|
|
|
|
|
|
|
48
|
4
|
|
|
|
|
43
|
$c->content_for( $name => $c->javascript($content) ); |
49
|
|
|
|
|
|
|
} |
50
|
8
|
|
|
|
|
1742
|
return $c->content( $name ); |
51
|
7
|
|
|
|
|
258
|
}); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$app->helper(unique_for => sub { |
54
|
9
|
|
|
9
|
|
51942
|
my ($c, $name, $content) = @_; |
55
|
9
|
|
50
|
|
|
38
|
$name ||= 'content'; |
56
|
|
|
|
|
|
|
|
57
|
9
|
|
100
|
|
|
26
|
my $hash = $c->stash->{'uniquetaghelpers.unique'} ||= {}; |
58
|
9
|
50
|
|
|
|
103
|
if( defined $content ) { |
59
|
9
|
|
100
|
|
|
39
|
$hash->{$name} ||= {}; |
60
|
9
|
|
|
|
|
22
|
my $key = _block($content); |
61
|
|
|
|
|
|
|
$key = md5_sum( $key // '' ) |
62
|
9
|
100
|
50
|
|
|
113
|
if $conf->{max_key_length} < length $key; |
63
|
|
|
|
|
|
|
|
64
|
9
|
100
|
|
|
|
59
|
return $c->content( $name ) if exists $hash->{$name}{$key}; |
65
|
3
|
|
|
|
|
14
|
$hash->{$name}{$key} = 1; |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
41
|
$c->content_for( $name => $content ); |
68
|
|
|
|
|
|
|
} |
69
|
3
|
|
|
|
|
335
|
return $c->content( $name ); |
70
|
7
|
|
|
|
|
179
|
}); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |