custom vmethods

Dave Howorth <dhoworth-fDajt2Yx3S8pY9vWkoisglpr/1R2p/[email protected]> Wed, 24 Feb 2016 12:44:43 +0000
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <[email protected]>
I'm trying to define a custom vmethod but not succeeding.

I tried using the way described in the manual and also by calling 
define_vmethod. Both ways appear to have set up methods in the 
Template::Stash::SCALAR_OPS hashref but neither of them appears to work, 
even with a very simple body. Any clues to what I'm doing wrong 
gratefully received!

In the perl:

use Template::Stash;
$Template::Stash::SCALAR_OPS->{uniprot_is_obsolete} =
     sub {
         return 42;
     };

sub forty_two { return 42; }
Template::Stash->define_vmethod('scalar', 'forty_two', &forty_two);

warn join ' ', keys %$Template::Stash::SCALAR_OPS, "\n";


In the template:

'*' ;
representative.defined ;
'*' ;
representative.forty_two ;
'*' ;
representative.uniprot_is_obsolete ;
'*' ;

On the page produced:

*1***

In the error log:

ucfirst list chunk remove collapse hash forty_two split lcfirst search 
squote size defined item repeat upper dquote length trim html 
uniprot_is_obsolete match lower xml substr replace

Cheers, Dave