Thread: [htmltmpl] using __DATA__ section as template in module
Brought to you by:
samtregar
From: <gr...@sp...> - 2004-10-02 22:51:50
|
I have been having some trouble with a module I am working on that requir= es HTML::Template. I am trying to use the __DATA__ section of the module as a default templa= te to fall back on if one is not supplied to my constructor. Here is a simple script that illustrates the issue: [ken@darkstar DBWebForm]$ cat Foo.pm #!/usr/bin/perl use strict; use warnings; Foo->run(); package Foo; use HTML::Template; sub run{ my @html =3D <DATA>; my $template =3D HTML::Template->new(arrayref =3D> \@html, die_on_bad_params=3D>1, strict=3D>1); $template->param(VALUE=3D>'xx'); print $template->output; } =20 1; __DATA__ <html> <head> </head> <body> <TMPL_VAR NAME=3DVALUE> </body> </html> [ken@darkstar DBWebForm]$ ./Foo.pm <html> <head> </head> <body> xx </body> </html> [ken@darkstar DBWebForm]$ perl -MFoo HTML::Template->new() : Syntax error in <TMPL_*> tag at /fake/path/for/non/file/template : 5. at /usr/lib/perl5/site_perl/5.8.0/HTML/Template.pm line 2288, <DATA> line 7. Compilation failed in require, <DATA> line 7. BEGIN failed--compilation aborted, <DATA> line 7. Anyone ideas on what is going on? Any suggestions welcome. Thanks in advance, -Ken=20 ------------------------------------------------- This mail sent through IMP: http://horde.org/imp/ |
From: Gabor S. <ga...@pe...> - 2004-10-02 23:51:57
|
On Sat, 2 Oct 2004 gr...@sp... wrote: > > > I have been having some trouble with a module I am working on that requires > HTML::Template. > > I am trying to use the __DATA__ section of the module as a default template to > fall back on if one is not supplied to my constructor. In one of my projects I am also using templates within the code. I put the templates in a scalar variables. You can take a look at the code at http://search.cpan.org/dist/CGI-FileManager/ Gabor |
From: <gr...@sp...> - 2004-10-03 01:25:47
|
Quoting Gabor Szabo <ga...@pe...>: > On Sat, 2 Oct 2004 gr...@sp... wrote: >=20 > > > > > > I have been having some trouble with a module I am working on that > requires > > HTML::Template. > > > > I am trying to use the __DATA__ section of the module as a default te= mplate > to > > fall back on if one is not supplied to my constructor. >=20 > In one of my projects I am also using templates within the > code. I put the templates in a scalar variables. >=20 > You can take a look at the code at > http://search.cpan.org/dist/CGI-FileManager/ >=20 > Gabor Hey, thanks for the tip. I have already resorted to using a scalar, but i= t bugs me that I could not get my original attempt to work. I would still prefer= to use the __DATA__ section, or at least understand why I can't.=20 Thanks, -Ken ------------------------------------------------- This mail sent through IMP: http://horde.org/imp/ |
From: Brad B. <bmb@Mail.Libs.UGA.EDU> - 2004-10-03 12:06:32
|
On Sat, 2 Oct 2004 gr...@sp... wrote: > > > I have been having some trouble with a module I am working on that requires > HTML::Template. > > I am trying to use the __DATA__ section of the module as a default template to > fall back on if one is not supplied to my constructor. > > Here is a simple script that illustrates the issue: > > [ken@darkstar DBWebForm]$ cat Foo.pm > #!/usr/bin/perl > use strict; > use warnings; > Foo->run(); > package Foo; > use HTML::Template; > sub run{ > my @html = <DATA>; > my $template = HTML::Template->new(arrayref => \@html, > 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> > [ken@darkstar DBWebForm]$ perl -MFoo > HTML::Template->new() : Syntax error in <TMPL_*> tag at > /fake/path/for/non/file/template : 5. at > /usr/lib/perl5/site_perl/5.8.0/HTML/Template.pm line 2288, <DATA> line 7. > Compilation failed in require, <DATA> line 7. > BEGIN failed--compilation aborted, <DATA> line 7. > > > Anyone ideas on what is going on? Any suggestions welcome. > > Thanks in advance, > -Ken FWIW, I don't get any errors when I run that (perl, v5.6.1). --Brad |