[Petal] [ANNOUNCE] Petal::CodePerl 0.04

Fergal Daly fergal at esatclear.ie
Mon Jul 14 15:48:50 BST 2003


Various updates, most importantly, modifiers can now be paritally or fully 
compiled. 

In the bin/ directory there a script called compile and you can do

bin/compile "false:this{long}[0]/expression"

and you will see what that gets compiled to, useful for playing with.

Modifiers:

Partially compiled will turn true:thing into

$Petal::Hash::MODIFIERS->{"true:"}->process_value($hash->{thing})

it means you need to write a process_value() method for your modifier which is 
very easy.

Fully compiled will give

do{
        my $value = (($hash)->{"thing"});
        defined($value) ?
        (ref($value) && (reftype($value) eq "ARRAY") ? scalar @$value : 1) :
        $value;
}

but you need to write an inline() method for your modifier which is a bit 
trickier because producing correct Perl code from within Perl is always a bit 
fiddly.

See the Petal::CodePerl man page for for examples of process_value and inline 
methods.

One minor problem you might encounter (spotted by Steve Purkis) - if you don't 
have perl 5.8.0 then you might need to upgrade your copy of Scalar::Util. 
Unfortunately the Makefile.PL for this module is incorrect and doesn't 
install it in the correct place, so you need to do

perl Makefile.PL INSTALLDIRS=perl

when you're installing it,

F



More information about the Petal mailing list