16 Aug 05:59
Modifiers and variables
Hey Jean-Michel et al,
I'm working on adding several new modifiers to Petal::Utils and have
come across an interesting proposal which I wanted to float with the
list.
When processing arguments passed to a modifier, there is not yet a
standard way of reading these values (at least to my knowledge). Warren
S. submitted a couple of modifiers which included a subroutine that he
devised which fetches the arguments in the following way:
1 - if the argument is a number (decimals are OK) or contains single
quotes, return the argument itself (i.e., plaintext)
2 - otherwise use the argument as the key to the hash and return that
value
I like this as it makes it really easy to pass in plain text without
having to use the string: modifier. However, I'm not sure whether this
is considered TAL compliant. What are your thoughts? I've included the
subroutine at the end.
Thanks,
William
sub _fetch {
my ($hash, $a) = @_;
return undef unless defined($a);
if($a =~ /\'/) {
$a =~ s/\'//g;
(Continue reading)
> > Last year when I was hacking Petal, I changed the modifier code so that it
> > examined the modifier at runtime to see if it was new style or old style.
> > For an old style modifier it just passed in the whole string to the process()
> > method as usual. If it was new style, it parsed the string a set of function
> > arguments and passed them to the new_process method.
>
> So you've been down this road too.
Yeah, the objective of Petal-CodePerl was to precompile the expressions and
so I needed to find a way to do this for modifiers too. Since you can't
precompile something that's going to do it's own parsing, I made a slightly
modified modifier that let Petal do all the parsing.
> > just changing that last line to
> >
> > if ($module->can("new_process")
>
> Ahh, so this is how you differentiate between new style and old style
> modifiers.
Yeah,it's totally compatible.
> > {
RSS Feed