Re: [htmltmpl] using __DATA__ section as template in module
Brought to you by:
samtregar
From: Carl F. <C.A...@du...> - 2004-10-04 15:11:06
|
Hi Ken, I've tried this, and it works. How does it compare with what you're doing? File test.pl ------------ #!/usr/bin/perl use warnings; use strict; use lib '.'; use Bar; Bar::foo(); File Bar.pm ----------- package Bar; use strict; use HTML::Template; sub foo { my $tmpl = HTML::Template->new (filehandle => *DATA); $tmpl->param(bar => 'works'); print $tmpl->output; } 1; __DATA__ foo <TMPL_VAR bar> baz ----- Carl >>> ken <ke...@sp...> 04/10/2004 11:43:16 >>> Carl Franks wrote: > > >>> <gr...@sp...> 02/10/2004 23:41:36 >>> > > > >Anyone ideas on what is going on? Any suggestions welcome. > > > >Thanks in advance, > >-Ken > > Hi Ken, > > Try this instead (below), noticed that I pass the DATA fileglob (*DATA) > directly to HTML::Template->new > > Carl > > #!/usr/bin/perl > use strict; > use warnings; > Foo->run(); > package Foo; > use HTML::Template; > sub run{ > my $template = HTML::Template->new(filehandle => *DATA, > die_on_bad_params=>1, strict=>1); > $template->param(VALUE=>'xx'); > print $template->output; > } > > 1; > __DATA__ > <html> > <head> > </head> > <body> > <TMPL_VAR NAME=VALUE> > </body> > </html> > [ken@darkstar DBWebForm]$ ./Foo.pm > <html> > <head> > </head> > <body> > xx > </body> > </html> > This gives me the same result. I have tried using the __DATA__ as a filehandle directly, copying to a arrayref, and copying to a scallarref, but all yield the same results. I do notice that running the file directly (e.g. ./Foo.pm) works, while using the module (e.g. perl -MFoo) gives a syntax error. The odd thing is, I can find no difference in the contents of the template file between invocations. I am completely stumped. Thanks for the suggestion, though. -Ken |