Bug in HTML::Template? What are you talking about? No offense, but something tells me that you are overlooking something on your side and you are thinking that it is a bug in that module (at the most i wager it's a feature that samtregar never intended HTML::Template to do). Abigail-II's solution is right on ... nobody says that you ever need use the <> operator to pass a package's DATA filehandle around (and it is filehandle by the way, not filehandler ... you aren't handling a file, you are getting a handle on the file). Here is some code to demonstrate:

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:

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>
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! ;)

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)

In reply to (jeffa) 3Re: How can read form __DATA__ via filehandler by jeffa
in thread How can read form __DATA__ via filehandler by filipe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.