Re: Patch Idea

Jonathan Vanasco <[email protected]> Wed, 16 Aug 2006 16:34:17 -0400
Newsgroups gmane.comp.lang.perl.modules.petal
Message-ID <[email protected]>
On Aug 16, 2006, at 4:06 PM, Corey wrote:

>
> A while back I asked whether it would be possible to get Petal to
> iterate ('petal:repeat') through hashes because I hated having
> to convert all my data structures in my classes, which are usually
> hashes, into arrays just so I could feed them to petal....  is this
> essentially what your provided code does?
>
> If so -- killer!  I think it would be especially useful.

sorry, but no.  it just has to do with the way perl treats hashes and  
named arguments, and how

a)
	$template->process( a=> 'z' );

my %Personalized= ( 'a' => 'z' );

b)
  	$template->process( %Personalized );

c)
	$template->process( \%Personalized );

d)
	$template->process( {'a' => 'z'}  );


on c, process gets ( $self , $ref__Personalized );
on d, process gets ( $self , $ref__toThatAnonHash );

on a & b , process gets ( $self , 'a' , 'z' );

if you're doing some sort of template class / plugin / or wrapper  
where Petal is an option, adding that just lets you do

	my $self= shift;
	my $args= shift;

and you can pass in args as an array ref,  without coercing it into a  
hash or exploding the array

there's no immediate performance difference, as petal processes the  
array ref and array the same way, with no memory or opcode gain

but, it means that you save doing
	process( @$args ) in your class, instead of just process( $args ),  
which is kind of confusing

you still don't need to convert hashes into arrays for petal-- just  
make an iterator class or something.  have petal print out a function  
to the iterator that loops through an array and pulls out the index  
you want.