Catalyst-View-Seamstress
view release on metacpan or search on metacpan
lib/Catalyst/View/Seamstress.pm view on Meta::CPAN
If you just configure a LOOM then you are most likely using the "plain meat" method described below. If you also configure a skeleton in your config as well then you're using the "meat and skeleton" method. See below for a more detailed discussion of...
=over
=item * C<< $c->stash->{LOOM} >>
The Seamstress view plugin MUST have a LOOM
to work on or it
will balk with an error:
sub message : Global {
my ( $self, $c ) = @_;
$c->stash->{LOOM} = 'html::hello_world';
$c->stash->{name} = 'Billy Bob';
$c->stash->{date} = 'medjool sahara';
$c->forward('MyApp::View::Seamstress');
}
=item * C<< MyApp::View::Seamstress->config->{skeleton} >>
By default this is not set and the HTML output is simply the result of
taking C<< $c->stash->{LOOM} >>, calling C<new()> to create
an HTML tree and then passing this to C<process()> so that it can rework
the tree.
However, if C<< MyApp::View::Seamstress->config->{skeleton} >> is
set, then both its value and the values of
C<< MyApp::View::Seamstress->config->{meat_pack} >>
and C<< $stash->{LOOM}->fixup() >>
come into effect
as described in L<HTML::Seamstress/"The_meat-skeleton_paradigm">.
Let's take that a little slower: C<< $stash->{LOOM}->fixup() >>
means: given a Seamstress-style Perl class, whose name is
C<< $stash->{LOOM} >>, call the method C<fixup()> in that
class so that it can do a final fixup of the entire HTML that is about
to be shipped back to the client.
=back
The output generated from the LOOM
(and possibly its interaction with a skeleton)
is stored in
C<< $c->response->body >>.
=head2 Other Config Options
=over
=item config->{fixup}
Set this to a coderef to allow the view to change the tree after the main
processing phase.
=item config->{use_xhtml}
By default the view will generate html 4 style html by calling as_HTML on the
tree object. If you set this to a true value it will generate XHTML style HTML
by calling as_XML on the tree object. See L<HTML::Element> for details for
these methods.
Also note that this won't apply proper HTML doctypes and what-have-you unless
you have them in your original HTML.
=item config->{meat_pack}
This is the subref which is called to pack meat into the skeleton for the meat
skeleton method. Tinker with this to have more creative LOOMS. See "Funny
LOOMs" and the meat/skeleton discussions.
=back
=head2 Funny LOOMs
In the examples so far the LOOM has always been a class name.
If instead LOOM is an object then we'll assume that is a useful HTML::Element style
object and just use that instead of calling C<new> on the LOOM. In this case we'll also not ->delete it at the end of the request so you'll have to do that yourself!
If the LOOM is in fact an ARRAY reference filled with class names we'll send the meat_pack a hash of class names mapped to objects.
=cut
# process()
# C<< eval-requires >> the module specified in C<< $c->stash->{LOOM} >>.
# Gets the
# C<HTML::Tree> representation of the file via C<new> and then calls
# C<< $self->process($c, $c->stash) >> to rewrite the tree.
sub page2tree {
my ($self, $c, $page_class, $process_method) = @_;
$c->log->debug(qq/Rendering template "$page_class"/) if $c->debug;
$process_method ||= 'process';
my $page_object;
# IF we've been passed a page class, build an object:
if (not ref $page_class) {
# pull in the page class:
eval "require $page_class";
# emit errors if there were problems with the page_class:
if ($@) {
my $error = qq/Couldn't load $page_class -- "$@"/;
$c->log->error($error);
$c->error($error);
return 0;
}
$page_object = $page_class->new($c); # e.g html::hello_world->new
}
# IF we've been passed a page object, just use it:
else {
( run in 1.694 second using v1.01-cache-2.11-cpan-39bf76dae61 )