HTML::Template has a documented print_to option for the output() method that streams exactly like you're describing. And, HTML::Template is poorly named - I use it for a lot more than just HTML. If I was outputting XML, I would use and have used H::T.
| [reply] |
| [reply] |
package My::Associated::DBH::Wrapper;
# Called as:
# my $thingy = My::Associated::DBH::Wrapper->new(
# sth => $sth,
# param_name => 'Foo',
# );
sub new {
my $class = shift;
my %args = @_;
bless \%args, $class;
}
sub param {
my $self = shift;
my ($param) = @_;
return unless $param eq $self->{param_name};
my @values = $self->{sth}->fetchrow_array;
return unless @values;
return $values[0];
}
Then, when you build your template, you can go ahead and do this:
my $template = HTML::Template->new(
filename => 'my_template.tmpl',
associate => [ $thingy, $query ],
);
| [reply] [d/l] [select] |
I don't like Mason much either, but that's definitely an interesting interview approach you've applied there ;-)
The ability to stream output is very handy indeed, since it allows the important bits of a page to display even if a component breaks along the way. Well, depending on how you've got error handling set up, but you get the idea. There are plenty of little things like that which make Mason a good deal more pleasant to use. Then again, can't you do the same thing from regular CGI by setting $| to a true value? After all, your application is just sending to STDOUT.
| [reply] [d/l] |
Yes, you can do that with a regular CGI when generting output directly. The key problem, though, is that most templating languages are infeasible to stream. They just don't have the semantics for it.
"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.
| [reply] |
| [reply] |
Some example code to illustrate your point would be welcome. | [reply] |