[Petal] Modifiers and variables
William McKee
william at knowmad.com
Mon Aug 16 04:59:48 BST 2004
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;
return $a;
}
elsif($a =~ /^[0-9.]+$/) {
return $a;
}
else {
return $hash->fetch($a);
}
}
--
Knowmad Services Inc.
http://www.knowmad.com
More information about the Petal
mailing list