[Catalyst] Forward to view question
Matt S Trout
dbix-class at trout.me.uk
Mon May 11 16:58:33 GMT 2009
On Tue, May 05, 2009 at 10:54:17AM -0400, Dennis Daupert wrote:
> I've created a view that's intended to write a couple of files to the file
> system.
>
> The output filename needs to be dynamically set. I'm having a bit of a go
> figuring out how to do that.
>
> The TT configuration documentation speaks of an output subroutine:
>
> OUTPUT => \&output,
>
> Later on in the view base class...
>
> sub output {
> my $filename = shift;
> # do stuff
> }
>
> Here's my question:
> How do I get the $filename into sub output when I forward to the view?
Screw that.
sub write_file {
my ($self, $c, $filename) = @_;
my $data = $self->render($c, ...); # look at how process calls render
<write data>
}
then do:
$c->view('Foo')->write_file($c, $filename);
Having to pass $c along like that is a little bit annoying, but this approach
is -way- simpler.
Of course if you were feeling truly insane you could do
$self->template->{OUTPUT} = sub { <capture $filename here> };
$self->render(...);
but I don't really see that it would gain you anything.
*wonders if write_file should be a role that applies to any view that supplies
render* ...
--
Matt S Trout Catalyst and DBIx::Class consultancy with a clue
Technical Director and a commit bit: http://shadowcat.co.uk/catalyst/
Shadowcat Systems Limited
mst (@) shadowcat.co.uk http://shadowcat.co.uk/blog/matt-s-trout/
More information about the Catalyst
mailing list