[Catalyst] Forward to view question
Andrew Rodland
arodland at comcast.net
Tue May 5 17:59:10 GMT 2009
On Tuesday 05 May 2009 09:54:17 am 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?
>
>
This is kind of lazy lousy code because I hate trying to squeeze real code
into an email. Hopefully it demonstrates the technique. :)
package MyApp::View::TTtoFile;
use strict;
use base 'Catalyst::View::TT';
my $outfile;
sub output {
# do stuff to $outfile
}
sub process {
my $self = shift;
(undef, $outfile) = @_; # Ignoring $c
return $self->next::method(@_);
}
__PACKAGE__->config( ... etc. etc. ...);
And then in your app you can just
$c->forward('View::TTtoFile', '/var/ham/sandwich.txt');
Andrew
More information about the Catalyst
mailing list