Hi Jim,

I think the best thing you can do is to move the Perl code out of the
template.

You can define a css_minify filter using a plugin like so (untested):

     package Template::Plugin::CSSMinify;
     use base 'Template::Plugin';

     sub new {
         my ($class, $context, $config) = @_;
         $context->define_filter(
             css_minify => \&css_minify,
         );
     }

     sub css_minify {
         my $text = shift;
         # your code here to munge $text
         return $text;
     }

     1;

Then you can keep your wrapper template nice and simple:

[%  SWITCH type;
         CASE 'css';
             USE CSSMinify;
             content | css_minify;
         END;

         # ... other types

     END
%]

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):

     use IPC::Run 'run';
     our $MINIFY = '/path/to/compact_css.pl';

     sub css_minify {
         my $input = shift;
        my $output;
         run [$MINIFY], \$input, \$output;
         return $output;
     }

HTH
A

_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to