[Petal] Patch Idea

Jonathan Vanasco petal-list at 2xlp.com
Wed Aug 16 20:08:26 BST 2006


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