Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of LTjake (4001)

Thursday November 24, 2005
03:37 PM


[ #27729 ]

I was stealing an idea from Catalyst::Helper and embedding my template files in the __DATA__ section of my code. But i was slightly annoyed by the way i had to read in the wrapper file and assign it as a scalar ref.

I was able to figure out how to make Template::Toolkit read directly from my __DATA__ section -- I figured it was useful enough to release it to CPAN -- Thus, Template::Provider::FromDATA was born.

Here's a little sample script you can play with to see how easy it is.


use strict;
use warnings;

use Template;
use Template::Provider::FromDATA;

my $provider = Template::Provider::FromDATA->new;
my $template = Template->new( {
    LOAD_TEMPLATES => [ $provider ],
    WRAPPER        => 'wrapper'
} );

my $world = shift || 'world';

$template->process( 'hello', { world => $world } );


[% content %]

Hello, [% world %]!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Inline::TT does something similar and fun. I like it a lot. Soon, I will release the code I've got a t work that mixes in to any class to give it a template store that respects inheritance and does some other fun stuff... but first I need to make a few more tests pass!
  • If the files are needed for something that will be installed to the system, you may want to take a look at File::ShareDir, which demonstrates how to make use of the (little used) shared file facility in installers.