[Petal] Help with Custom Modifiers

jhiver@mkdoc.com jhiver@mkdoc.com
Sat, 5 Oct 2002 12:40:27 +0100


> $Petal::Hash::MODIFIERS->{'uc_first:'} = sub {
> my $class = shift;
> my $hash  = shift;
> my $string = $hash->FETCH (@_);
>
> return unless($string);
> return "\u$string";
> };

You are using a deprecated API... the changes have been updated in the
Petal::Hash pod page.

> my $string = $hash->FETCH (@_);

This should be: my $string = $hash->fetch (@_);
Otherwise you are going to XML encode values twice.

> 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"

This is stange. You'd have to send your source files to the list so I can
tell what's wrong with them.

> "Can't locate object method "FETCH" via package "listing_type" (perhaps
> you forgot to load "listing_type"?)"

Ovisously this is all foobar, it's probably something silly... I need the
source :-)

> 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:

It has been enabled. In fact most of modifiers have been reimplemented as
coderefs. Take a look at the Petal::Hash source.

> 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?

I don't know :-(

> 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...

Okay, will do.
Cheers,