[Petal] Help with Custom Modifiers
William McKee
william@knowmad.com
Fri, 4 Oct 2002 21:19:25 -0400
Last month there was some discussion about creating custom modifiers in an
inline method (as suggested by Bruno in msg from JMH titled "[Petal] Re:
improvement on the _code_with_line_numbers() method and how to writte my
own modifiers?" sent on Fri, 6 Sep 2002 15:11:35).
Ok, I'm ready to try this idea in order to create a modifier that will
uppercase the first letter of a variable. I tried the following code:
$Petal::Hash::MODIFIERS->{'uc_first:'} = sub {
my $class = shift;
my $hash = shift;
my $string = $hash->FETCH (@_);
return unless($string);
return "\u$string";
};
and received the following errors (these two seem to flip-flop back and
forth each time I reload the page; btw, listing_type is the variable I'm
passing to the modifier):
"cannot import Petal::Hash::Types::UC_First for modifier uc_first: at
/usr/local/share/perl/5.6.1/Petal/Hash.pm line 263"
"Can't locate object method "FETCH" via package "listing_type" (perhaps
you forgot to load "listing_type"?)"
Has this technique has not yet been enabled or am I missing something in
my implementation? BTW, I tried to create a separate file and discovered
that Petal wants to find my custom modifier library within the
Petal::Hash::Types namespace and thus returning the same messages as
above. My modifier package contains the following code:
package Knowmad::Petal::UC_First;
use strict;
use warnings;
sub process {
my $class = shift;
my $hash = shift;
my $string = $hash->FETCH(@_);
return unless($string);
return "\u$string";
}
1;
When I set the BASE_DIR, DISK_CACHE, etc, I call the following:
$Petal::Hash::MODIFIERS->{'uc_first:'} = 'Knowmad::Petal::UC_First';
Help! What am I missing here?
While we're on the subject of modifiers, what do ya'll think about adding
a synonym for false? I mistakenly tried to use not: today (I told you I
was rusty!). That doesn't seem too unreasonable of a synonym...
Thanks,
William
--
Lead Developer
Knowmad Services Inc. || Internet Applications & Database Integration
http://www.knowmad.com