line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Lace::ComponentCallback; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
5
|
1
|
|
|
1
|
|
8
|
use Template::Lace::DOM; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
157
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
0
|
23
|
sub new { return bless pop, shift } |
8
|
0
|
|
|
0
|
0
|
0
|
sub cb { return shift->{cb} } |
9
|
1
|
|
|
1
|
0
|
4
|
sub make_dom { return Template::Lace::DOM->new(pop) } |
10
|
1
|
|
|
1
|
0
|
19
|
sub model_class { return ref(shift) } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub create { |
13
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
14
|
1
|
|
|
|
|
7
|
return bless +{ cb => $self, @_ }, ref($self); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub get_processed_dom { |
18
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
19
|
1
|
|
|
|
|
2
|
local $_ = $self; |
20
|
1
|
|
|
|
|
9
|
local %_ = %$self; |
21
|
1
|
|
|
|
|
9
|
my $response = $self->{cb}->($self, %$self); |
22
|
1
|
50
|
|
|
|
17
|
return ref($response) ? |
23
|
|
|
|
|
|
|
$response : |
24
|
|
|
|
|
|
|
$self->make_dom($response); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Template::Lace::ComponentCallback - Create a component easily from a coderef |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
{ |
36
|
|
|
|
|
|
|
package Local::Template::User; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use Moo; |
39
|
|
|
|
|
|
|
with 'Template::Lace::ModelRole'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has [qw/title story/] => (is=>'ro', required=>1); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub template {q[ |
44
|
|
|
|
|
|
|
<html> |
45
|
|
|
|
|
|
|
<head> |
46
|
|
|
|
|
|
|
<title></title> |
47
|
|
|
|
|
|
|
</head> |
48
|
|
|
|
|
|
|
<body> |
49
|
|
|
|
|
|
|
<div id='story'></div> |
50
|
|
|
|
|
|
|
<tag-anchor href='more.html' target='_top'> |
51
|
|
|
|
|
|
|
See More |
52
|
|
|
|
|
|
|
</tag-anchor> |
53
|
|
|
|
|
|
|
</body> |
54
|
|
|
|
|
|
|
</html> |
55
|
|
|
|
|
|
|
]} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub process_dom { |
58
|
|
|
|
|
|
|
my ($self, $dom) = @_; |
59
|
|
|
|
|
|
|
$dom->title($self->title) |
60
|
|
|
|
|
|
|
->at('#story') |
61
|
|
|
|
|
|
|
->content($self->story); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
use Template::Lace::ComponentCallback; |
66
|
|
|
|
|
|
|
my $factory = Template::Lace::Factory->new( |
67
|
|
|
|
|
|
|
model_class=>'Local::Template::User', |
68
|
|
|
|
|
|
|
component_handlers=>+{ |
69
|
|
|
|
|
|
|
tag => { |
70
|
|
|
|
|
|
|
anchor => Template::Lace::ComponentCallback=>new(sub { |
71
|
|
|
|
|
|
|
my ($self, %attrs) = @_; |
72
|
|
|
|
|
|
|
return "<a href='$_{href}' target='$_{target}'>$_{content}</a>"; |
73
|
|
|
|
|
|
|
}), |
74
|
|
|
|
|
|
|
}, |
75
|
|
|
|
|
|
|
}, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
In this case C<%attrs> are the results of processing attributes. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
B<NOTE> You might prefer to call this via L<Template::Lace::Utils> instead. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 DESCRIPTION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Lets you make quick and dirty components from a coderef. To make this even |
85
|
|
|
|
|
|
|
faster and dirtier we localize $_ to $self and %_ to %attrs. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 METHODS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This class defines the following public instance methods: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub make_dom |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Create an instance of L<Template::Lace::DOM>. Useful if you have complex |
94
|
|
|
|
|
|
|
component setup and transformation. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SEE ALSO |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
L<Template::Lace>. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AUTHOR |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Please See L<Template::Lace> for authorship and contributor information. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Please see L<Template::Lace> for copyright and license information. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |