[Petal] new() or process() on a string rather than a file?
Corey
corey_s at qwest.net
Wed Sep 27 04:10:22 BST 2006
Well, I started looking into the Petal code, and it looks like this wouldn't be
too difficult... in fact, I already have it working after making just a few very
quick ( and dirty ) changes:
corey at scanner ~ $ cat test_string.pl
#!/usr/bin/perl
use strict;
use warnings;
use Petal;
my ( $input, $petal, $output );
$input = 'a is: ${my_var}';
$petal = Petal->new(
'string' => $input,
'disk_cache' => 0, # necessary to avoid warnings
'memory_cache' => 0, # necessary to avoid warnings
);
$output = $petal->process( 'my_var' => 'Woot!' );
print "$output\n";
corey at scanner ~ $ ./test_string.pl
a is: Woot!
... anyone interested in seeing this officially go into Petal?
On Tuesday 26 September 2006 19:03, Corey wrote:
>
> Subject says it all - what if I have a string that I'd like to process
> using Petal? How do I do so? It appears that Petal only supports
> processing external files?
>
> What if my template was stored in a database, then retrieved with
> the DBI into a variable?
>
> It seems that it would be extremely useful to be able to do something
> along the lines of:
>
> # or assume this came from some other datasource, like a database
> $input = '
> <html xmlns:tal="http://purl.org/petal/1.0/">
> <body tal:content="bar">Dummy Content</body>
> </html>
> ';
>
> # obviously, this does not work:
> $template = Petal->new( $input );
>
> $output = $template->process ( bar => 'BAZ' );
>
> print $output;
>
>
> Which would print:
>
> <html>
> <body>BAZ</body>
> </html>
>
>
> Did I miss what I'm looking for in the docs somewhere? Or if not, is there
> some specific reason why processing a string rather than a file is not made
> possible via Petal?
>
>
> Many thanks!
>
> Corey
>
>
>
>
More information about the Petal
mailing list