On 3/2/2010 4:18 AM, Jim Battle wrote:
> On 3/2/2010 1:15 AM, Andy Wardley wrote:
>   >  Hi Jim,
>   >
>   >  I think the best thing you can do is to move the Perl code out of the
> ...
>   >  You might also want to have a look at IPC::Run. It takes all the pain
>   >  out of running external programs and capturing the output. Something
>   >  like this should do it (also untested):
>
> Thanks for the input, Sean and Andy!  You've solved my problem and I've
> learned a thing or two.

> Then I switched to run3 -- so much nicer!  Here is my final code, just
> in case someone searches the mail list archives with a similar problem.
>
> [%- SWITCH type -%]
>
>       [%- CASE 'text' -%]
>
>           [% content %]
>
>       [%- CASE 'css' -%]
>
>           [%- PERL -%]
>           # split context string into lines.
>           # can't use split() because the \n must remain at EOL.
>           my @inlines = $context->stash()->get('content') =~ m/^(.*)$/gsm;
>
>           my @outlines;
>           use IPC::Run3 qw(run3);
>           run3 ['perl', 'lib/compact_css.pl'], \...@inlines, \...@outlines;
>           print PERLOUT @outlines;
>           [%- END -%]
>
>       [%- CASE -%]
>
>           [% content WRAPPER html_wrapper.tt %]
>
> [%- END -%]

FWIW, rather than spawning a separate process to compress your CSS, it 
seems to me it would be smarter to move the compression code out of 
compact_css.pl into a module, so you can use it within the current process.

BTW, m/^(.*)$/gsm does not split the string into lines.  It matches and 
returns the entire string in a single match.  You could try split /^/m 
instead, but you don't actually need to split into lines before passing 
to run3 anyway.

Ronald

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to