Thanks Josh for the help (nice name by the way ;),

For anyone else having this problem here is what I did:

    my $template = Template->new({
        EVAL_PERL => 1,
    });

    my $template_params = {
        device              => $params->{device},
        interface           => $params->{interface},
        priveleged        => sub{
$self->{connection}->_begin_priveleged($params->{enable_password}); },
    };

    my $command_output;
    $template->process(\$command, $template_params, \$command_output)
                   || die $template->error();

On Thu, Jul 30, 2009 at 7:56 PM, Josh Rosenbaum <[email protected]> wrote:

> Josh803316 wrote:
>
>> I'm trying to execute some perl code inside my brackets with the eval_perl
>> filter.
>> [% $self->{$transport}->begin_privileged($params->{enable_password}); |
>> perl %]
>>
>> I get the following error message:
>>
>> file error - parse error - input text line 1: unexpected token (>)
>>
>> I assume this is because of the -> arrow method calls.  Do I have to
>> escape those somehow?  What is the proper syntax to use inside the perl
>> block
>>
>
> You need to use a string if you are going to use a filter. Like this:
> [% '$self->{$transport}->begin_privileged($params->{enable_password});' |
> perl %]
>
> or:
> [% PERL %]
> code.
> [% END %]
>
> However, I don't think this is doing what you think it is going to do. The
> perl is just being eval'd here and you probably won't have access to all
> those variables. You might be better off passing a sub in via the vars hash
> passed to the TT process method. The sub can do the necessary work you need
> then.
>
> -- Josh
>
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to