Modifiers and variables

William McKee <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.petal
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.