<br><br><div class="gmail_quote">On Tue, May 5, 2009 at 7:24 PM, Tomas Doran <span dir="ltr"><<a href="mailto:bobtfish@bobtfish.net">bobtfish@bobtfish.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br></div>
Sorry for pointing out the obvious, but this is just perl:<br>
<br>
my $output = delete $c->res->{body};<br>
opem(FH, ">file") or die;<br>
print FH $output;<br>
close(FH);<br>
<br>
will do what you want...</blockquote><div><br>Hi Tom, <br><br>Thanks for your reply. <br><br>There are some things that aren't so obvious to me. Where would I place the code represented in your snippet? I can't just hang it out in the main body of package hde::View::TTprint, since $c isn't available there. $c and $outfile *are* available in sub process, once the format for the forward statement is corrrect. So I *could* go ahead and perform the write-to-file operation there, but that seems a bit muddled. It seems to me the clearest place to write-to-file would be in sub output, but nothing seems to be showing up there. <br>
<br>Even so, I did try writing from sub process, and it gave me an error, which leads me to Question 2. <br>I'm trying to follow Template Toolkit's documented API, which offers these configuration options, which I've used in my TTprint base class:<br>
<br>OUTPUT => \&output,<br>OUTPUT_PATH => [<br> hde->path_to( 'root', 'static', 'published' ),<br> ],<br><br>Supposedly, the processed template output will be written to the output file relative to OUTPUT_PATH. But I get the error: <br>
<pre><font size="4"><code class="error">Caught exception in hde::View::TTprint->process "Cannot open Test1.0.0/TOC.html for writing: No such file or directory"</code></font></pre>
<br>BTW, this path already exists: ~/cat_work/hde/root/static/published/Test1.0.0<br><br>Please feel free to point out any obvious bit I've botched.<br><br>/dennis<br><br>Code summary:<br><br>In controller:<br>my $path_and_file = "<font><font size="4"><code class="error">Test1.0.0</code></font></font>
/TOC.html";<br>$c->forward( $c->view('TTprint'), [ qq/$path_and_file/ ] );<br><br>In package hde::View::TTprint;<br>__PACKAGE__->config({<br> TEMPLATE_EXTENSION => '.tt2', <br> INCLUDE_PATH => [<br>
hde->path_to( 'root', 'src' ),<br> hde->path_to( 'root', 'lib' ),<br> hde->path_to( 'root', 'tt2' )<br> ],<br> PRE_PROCESS => 'config/main',<br>
WRAPPER => 'site/wrapper',<br> OUTPUT => \&output,<br> OUTPUT_PATH => [<br> hde->path_to( 'root', 'static', 'published' ),<br> ],<br> ERROR => 'error.tt2',<br>
TIMER => 0<br>});<br><br>my $outfile;<br><br>sub output {<br> my $output = shift;<br># Nothing shows up here<br>}<br><br>sub process {<br> my $self = shift;<br> my ($c, $outfile) = @_; # Not ignoring $c, so I can get debug stuff<br>
# and delete body<br><br> # $outfile = '<font><font size="4"><code class="error">Test1.0.0</code></font></font>
/TOC.html';<br><br> $c->log->debug("In sub process"); # does print<br> $c->log->debug("outfile: $outfile");<br><br> my $output = delete $c->res->{body};<br> open my $write_fh, '>', $outfile <br>
or die "Cannot open $outfile for writing: $!\n";<br> print $write_fh $output;<br> close $write_fh or warn "Cannot close $outfile: $!\n";<br><br> return $self->next::method(@_);<br>}<br></div></div>