Template::Lace::ComponentCallback - Create a component easily from a coderef
{ package Local::Template::User; use Moo; with 'Template::Lace::ModelRole'; has [qw/title story/] => (is=>'ro', required=>1); sub template {q[ <html> <head> <title></title> </head> <body> <div id='story'></div> <tag-anchor href='more.html' target='_top'> See More </tag-anchor> </body> </html> ]} sub process_dom { my ($self, $dom) = @_; $dom->title($self->title) ->at('#story') ->content($self->story); } } use Template::Lace::ComponentCallback; my $factory = Template::Lace::Factory->new( model_class=>'Local::Template::User', component_handlers=>+{ tag => { anchor => Template::Lace::ComponentCallback=>new(sub { my ($self, %attrs) = @_; return "<a href='$_{href}' target='$_{target}'>$_{content}</a>"; }), }, }, );
In this case %attrs are the results of processing attributes.
%attrs
NOTE You might prefer to call this via Template::Lace::Utils instead.
Lets you make quick and dirty components from a coderef. To make this even faster and dirtier we localize $_ to $self and %_ to %attrs.
This class defines the following public instance methods:
sub make_dom
Create an instance of Template::Lace::DOM. Useful if you have complex component setup and transformation.
Template::Lace.
Please See Template::Lace for authorship and contributor information.
Please see Template::Lace for copyright and license information.
To install Template::Lace, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Lace
CPAN shell
perl -MCPAN -e shell install Template::Lace
For more information on module installation, please visit the detailed CPAN module installation guide.