On Mon, Mar 1, 2010 at 9:18 PM, Jim Battle <[email protected]> wrote:

>        # save 'content' to tmp file
>        my $tmp = "lib/tmp.css";
>        open(FH, ">$tmp") or die "Couldn't open $!";
>        print FH $context->stash()->get('content');
>        close(FH);
>
>        # filter the tmp file, sending the output back to TT
>        open(FH, "perl lib/compact_css.pl $tmp |") or die "Couldn't open
> $!";
>        print PERLOUT <FH>;
>        close(FH);
>
>        # kill off the tmp file
>        unlink $tmp;
>
>
You could use one of the modules IPC::Open2 or IPC::Open3.  Alternately,
something like this ought to work:

[% RAWPERL %]
    my $pid = open my $pipe, '|-';
    defined $pid or die;
    if ($pid == 0) {
        open STDOUT, '>&PERLOUT';
        unless (exec 'perl', 'lib/compact_css.pl') {
            print STDERR "Exec failed: $!\n";
            exit;
        }
    }
    print $pipe $context->stash->get('content');
    close $pipe;
[% END %]

(Untested code.)


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

Reply via email to