[Petal] Modifiers and variables

Fergal Daly fergal at esatclear.ie
Wed Aug 18 15:42:37 BST 2004


On Wed, Aug 18, 2004 at 09:34:20AM -0400, William McKee wrote:
> > package Shorten;
> 
> I've implemented this in Petal::Utils as substr: though not with the
> ability of cutting the string in half. This may prove a useful
> addition if you don't mind me borrowing it.

Be my guest.

> > Give it a spin,
> 
> Cool, but I have to agree with Jean-Michel that I'd prefer the args not
> be automatically parsed.

They're only automatically parsed if your modifier has a parsed_process()
method, otherwise they're delivered as a string as usual.

I think it's very common for a modifier to want to treat it's arguments as
TALES expressions, currently this is done with $hash->{$args} but that
limits you to a single argument.

It would be nice if Petal had a built in way to pass multiple arguments to
modifiers, Shorten being a perfect example, currently you have to do this as
something like

tools/shorten/process string len

and you have to make sure that tools/shorten has been correctly populated
with a Shorten object.

> However, I'm interested in your code that does
> the parsing of the tokens. In the following line, has $TOKEN_RE already
> been defined in Petal or is this coming from Petal::CodePerl?
> 
>     my @tokens = $argument =~ /($TOKEN_RE)/gsm;
> 
> Also, I've been under the misconception that s and m were mutually
> exclusive regex modifiers. Apparently this is not the case. What
> behavior are you seeking by setting in both of these?

It's not my code. All I did was move a chunk of process() into a subroutine
so that I could call it from elsewhere, I didn't try to figure it out at all.

F


More information about the Petal mailing list