line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Pure::Component; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
533
|
use Template::Pure; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
3
|
use Digest::MD5 (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use base 'Template::Pure'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
420
|
|
7
|
|
|
|
|
|
|
|
8
|
0
|
|
|
0
|
1
|
0
|
sub node { shift->{node} } |
9
|
|
|
|
|
|
|
sub inner { |
10
|
5
|
|
|
5
|
0
|
4
|
my $self = shift; |
11
|
|
|
|
|
|
|
return $self->encoded_string( |
12
|
5
|
|
|
|
|
13
|
$self->{node}->content); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
0
|
0
|
0
|
sub container { $_[0]->{container} } |
16
|
8
|
|
|
8
|
0
|
27
|
sub parent { shift->{parent} } |
17
|
7
|
|
|
7
|
0
|
6
|
sub children { @{shift->{children}} } |
|
7
|
|
|
|
|
16
|
|
18
|
|
|
|
|
|
|
sub add_child { |
19
|
4
|
|
|
4
|
0
|
4
|
my ($self, $child) = @_; |
20
|
4
|
|
|
|
|
4
|
push @{shift->{children}}, $child; |
|
4
|
|
|
|
|
9
|
|
21
|
4
|
|
|
|
|
10
|
return $self->children; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
5
|
0
|
17
|
sub style { shift->{style} } |
25
|
|
|
|
|
|
|
sub style_fragment { |
26
|
8
|
|
100
|
8
|
0
|
24
|
my $style = $_[0]->style || return; |
27
|
3
|
|
|
|
|
22
|
my $checksum = Digest::MD5::md5_hex($style); |
28
|
3
|
|
|
|
|
14
|
return $checksum, "<style type='text/css' id='$checksum'>$style</style>"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
5
|
|
|
5
|
0
|
15
|
sub script { shift->{script} } |
32
|
|
|
|
|
|
|
sub script_fragment { |
33
|
8
|
|
100
|
8
|
0
|
20
|
my $script = $_[0]->script || return; |
34
|
3
|
|
|
|
|
19
|
my $checksum = Digest::MD5::md5_hex($script); |
35
|
3
|
|
|
|
|
15
|
return $checksum, "<script type='text/javascript' id='$checksum'>$script</script>"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub process_root { |
39
|
8
|
|
|
8
|
0
|
375
|
my ($self, $root) = @_; |
40
|
8
|
100
|
|
|
|
20
|
if(my($md5, $style) = $self->style_fragment) { |
41
|
3
|
100
|
|
|
|
9
|
unless($root->at("style#$md5")) { |
42
|
1
|
|
|
|
|
310
|
$root->at('head')->append_content("$style\n"); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
8
|
100
|
|
|
|
747
|
if(my($md5, $script) = $self->script_fragment) { |
46
|
3
|
100
|
|
|
|
8
|
unless($root->at("script#$md5")) { |
47
|
1
|
|
|
|
|
296
|
$root->at('head')->append_content("$script\n"); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub prepare_render_callback { |
53
|
8
|
|
|
8
|
0
|
6
|
my $self = shift; |
54
|
|
|
|
|
|
|
return sub { |
55
|
8
|
|
|
8
|
|
9
|
my ($t, $dom, $data) = @_; |
56
|
8
|
|
|
|
|
14
|
$self->process_root($dom->root, $data); |
57
|
8
|
|
|
|
|
793
|
$t->encoded_string($self->render({data=>$data})); |
58
|
8
|
|
|
|
|
85
|
}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 NAME |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Template::Pure::Components - Reusable HTML components |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 SYNOPSIS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
package Local::Timestamp; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
use Moo; |
72
|
|
|
|
|
|
|
use DateTime; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
extends 'Template::Pure::Component'; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
has 'tz' => (is=>'ro', predicate=>'has_tz'); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub style {q[ |
79
|
|
|
|
|
|
|
.timestamp { |
80
|
|
|
|
|
|
|
color: blue; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
]} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub script {q[ |
85
|
|
|
|
|
|
|
function hello() { |
86
|
|
|
|
|
|
|
alert('Hi'); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
]} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub template { |
91
|
|
|
|
|
|
|
q[<span class='timestamp' onclick="hello()">time</span>]; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub directives { |
95
|
|
|
|
|
|
|
'.timestamp' => 'self.time', |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub time { |
99
|
|
|
|
|
|
|
my ($self) = @_; |
100
|
|
|
|
|
|
|
my $now = DateTime->now; |
101
|
|
|
|
|
|
|
$now->set_time_zone($self->tz) |
102
|
|
|
|
|
|
|
if $self->has_tz; |
103
|
|
|
|
|
|
|
return $now; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 DESCRIPTION |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Work in progress. Play here only if you are willing to get you hands |
109
|
|
|
|
|
|
|
dirty and have stuff break. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SEE ALSO |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
L<Template::Pure>. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
John Napiorkowski L<email:jjnapiork@cpan.org> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
But lots of this code was copied from L<Template::Filters> and other prior art on CPAN. Thanks! |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Please see L<Template::Pure> for copyright and license information. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |