in reply to Re: Re: How can read form __DATA__ via filehandler
in thread How can read form __DATA__ via filehandler
We call a package's (Foo) subroutine which returns an object to us (Bar). Bar contains one 'attribute' whose value is a reference to Foo's DATA filehandle. Back inside main we instantiate a new HTML::Template and pass Bar's 'filehandle' it to (which is really a reference to Foo's). We then pass it a param for it to substitute and then we print the output. Here goes:
Finally note, i tend to use DATA only for tests and example scripts - i avoid it when it comes to writing real production code. Use seperate files instead. I guess if you have each page associated with one and only one module it would make sense ... but i tend to associate multiple pages with each module (add, edit, view, delete, list all, etc.) ... Inline::Files? Nah! ;)use strict; use warnings; use HTML::Template; my $bar = Foo::do_it(); my $tmpl = HTML::Template->new(filehandle => $bar->{filehandle}); $tmpl->param(baz => 'Hello GLOB!'); print $tmpl->output(); package Bar; sub new { my $class = shift; return bless {@_}, $class; } package Foo; sub do_it { my $bar = Bar->new(filehandle => \*DATA); return $bar; } __DATA__ <html> <body> <h1><tmpl_var baz></h1> </body> </html>
Best of luck to you and please let us know how your progress goes. :)
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|