line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Caribou::Tags; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
3
|
|
|
3
|
|
1506
|
$Template::Caribou::Tags::AUTHORITY = 'cpan:YANICK'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
#ABSTRACT: generates tags functions for Caribou templates |
6
|
|
|
|
|
|
|
$Template::Caribou::Tags::VERSION = '0.2.4'; |
7
|
3
|
|
|
3
|
|
23
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
89
|
|
8
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
9354
|
|
|
3
|
|
|
|
|
92
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
15
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
194
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
514
|
use Template::Caribou::Utils; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
218
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
|
|
56
|
use Sub::Exporter -setup => { |
15
|
|
|
|
|
|
|
exports => [ |
16
|
|
|
|
|
|
|
qw/ attr render_tag /, |
17
|
|
|
|
|
|
|
mytag => \&_gen_generic_tag, |
18
|
|
|
|
|
|
|
], |
19
|
|
|
|
|
|
|
groups => { default => [ 'attr' ] }, |
20
|
3
|
|
|
3
|
|
22
|
}; |
|
3
|
|
|
|
|
5
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _gen_generic_tag { |
23
|
86
|
|
|
86
|
|
2998
|
my ( undef, undef, $arg ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $groom = $arg->{groom} || sub { |
26
|
0
|
|
|
0
|
|
|
my( $attr ) = @_; |
27
|
0
|
|
0
|
|
|
|
$attr->{class} ||= $arg->{class} if $arg->{class}; |
28
|
0
|
|
|
|
|
|
if ( $arg->{attr} ) { |
29
|
0
|
|
0
|
|
|
|
$attr->{$_} ||= $arg->{attr}{$_} for keys %{ $arg->{attr} }; |
|
0
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
} |
31
|
86
|
|
50
|
|
|
496
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
return sub(&) { |
34
|
0
|
|
|
0
|
|
|
my $inner = shift; |
35
|
0
|
|
0
|
|
|
|
render_tag( $arg->{name} || 'div', $inner, $groom ); |
36
|
|
|
|
|
|
|
} |
37
|
86
|
|
|
|
|
334
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub attr(@){ |
40
|
0
|
0
|
|
0
|
0
|
|
return $Template::Caribou::attr{$_[0]} if @_ == 1; |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
croak "number of attributes must be even" if @_ % 2; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
while( my ( $k, $v ) = splice @_, 0, 2 ) { |
45
|
0
|
0
|
|
|
|
|
if ( $k =~ s/^\+// ) { |
46
|
0
|
|
|
|
|
|
$Template::Caribou::attr{$k} .= ' '. $v; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
0
|
|
|
|
|
|
$Template::Caribou::attr{$k} = $v; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub render_tag { |
57
|
0
|
|
|
0
|
0
|
|
my ( $tag, $inner_sub, $groom ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $inner; |
60
|
|
|
|
|
|
|
my %attr; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
{ |
63
|
3
|
|
|
3
|
|
2650
|
no warnings qw/ uninitialized /; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
536
|
|
|
0
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
local *STDOUT; |
66
|
0
|
|
|
|
|
|
local *::RAW; |
67
|
0
|
|
|
|
|
|
local $Template::Caribou::OUTPUT; |
68
|
0
|
|
|
|
|
|
local %Template::Caribou::attr; |
69
|
0
|
|
|
|
|
|
tie *STDOUT, 'Template::Caribou::Output'; |
70
|
0
|
|
|
|
|
|
tie *::RAW, 'Template::Caribou::OutputRaw'; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
my $res = ref $inner_sub ? $inner_sub->() : $inner_sub; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
0
|
|
|
|
$inner = $Template::Caribou::OUTPUT |
75
|
|
|
|
|
|
|
|| ( ref $res ? $res : Template::Caribou::Output::escape( $res ) ); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
%attr = %Template::Caribou::attr; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
$groom->( \%attr, \$inner ) if $groom; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $attrs; |
83
|
0
|
|
|
|
|
|
for( sort keys %attr ) { |
84
|
|
|
|
|
|
|
# TODO deal with the quotes |
85
|
0
|
|
|
|
|
|
$attrs .= qq{ $_="$attr{$_}"}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
3
|
|
|
3
|
|
14
|
no warnings qw/ uninitialized /; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
348
|
|
89
|
0
|
0
|
|
|
|
|
my $output = $inner |
90
|
|
|
|
|
|
|
? Template::Caribou::String->new( "<${tag}$attrs>$inner</$tag>" ) |
91
|
|
|
|
|
|
|
: Template::Caribou::String->new( "<${tag}$attrs />" ) |
92
|
|
|
|
|
|
|
; |
93
|
0
|
|
|
|
|
|
print ::RAW $output; |
94
|
0
|
|
|
|
|
|
return $output; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=pod |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=encoding UTF-8 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 NAME |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Template::Caribou::Tags - generates tags functions for Caribou templates |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 VERSION |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
version 0.2.4 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 AUTHOR |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Yanick Champoux <yanick@cpan.org> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Yanick Champoux. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
122
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |