[Petal] Creating template from string

Michael Graham magog at the-wire.com
Wed Jul 20 23:28:31 BST 2005


I'm the author of CGI::Application::Plugin::AnyTemplate, which tries to
create a unified template API for CGI::Application.  Currently it
supports HTML::Template, Template::Toolkit and Petal.

Where possible, I've tried to smooth over the API differences between
the modules so that the user can switch templating systems without
changing application code.

One feature that I haven't been able to emulate in Petal is the ability
to create a template from a string instead of a file.

    my $string = <<EOF;
    ...some template text...
    EOF

    # HTML::Template
    my $template = HTML::Template->new(
        scalarref => \$string,
    );

    # Template::Toolkit
    my $template = Template->new;
    $template->process(\$string);

There doesn't seem to be a way to do this in Petal, short of writing the
string to a temporary file and then passing the file to Petal.

Is this something that could be supported in Petal some day?

It's a useful feature for authors who want to bundle a default set of
generic templates in the .pm file of their application.


Michael




--
Michael Graham <magog at the-wire.com>




More information about the Petal mailing list