[Petal] Patch Idea

Corey corey_s at qwest.net
Wed Aug 16 21:06:00 BST 2006


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.


On Wednesday 16 August 2006 12:08, Jonathan Vanasco wrote:
> This one line is useful to me... but I don't know if its appropriate  
> in Petal.  It would be neat if you thought it was.
> 
> sub process {
> 
> 	if (ref $_[0] eq 'Petal::Hash') { $hash = shift }
> 	elsif (ref $_[0] eq 'HASH')     { $hash = new Petal::Hash (%{shift 
> ()}) }
> +	elsif (ref $_[0] eq 'ARRAY')     { $hash = new Petal::Hash (@{shift 
> ()}) }
> 	else                            { $hash = new Petal::Hash  
> (@_)         }
> 
> 
> basically,  if you're wrapping Petal as a templating option for a  
> framwork, you don't have to deref the input into something that Petal  
> expects
> its of trivial use.  the difference is in a function below.  just  
> wanted to suggest it.
> 
> 
> sub process_petal {
> 	my  $self= shift;
> 	my 	$template_vars;
> 
> 	if 		( ref $_[0] eq 'HASH' ) {
> 		$template_vars= $_[0];
> 	}
> 	elsif 	( ref $_[0] eq 'REF' ) {
> 		$template_vars= $$template_vars;
> 		while ( ref $template_vars eq 'REF' ) {
> 			$template_vars= $$template_vars;
> 		}
> 	}
> 	else {
> 		if ( scalar @_ ) {
> 			$template_vars= \@_;
> 		}
> 	}
> 	return	$self->PetalObject->process( $template_vars );
> 	return	$self->PetalObject->process( @{$template_vars} );
> }
> 
> 


More information about the Petal mailing list