Any-Template

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Mon May  8 13:29:32 2006 - 1.015
    CPAN release 1.015.

Wed Apr 19 13:09:10 2006 - 1.015
    Modified Text::MicroMason unit test to pass loop_global_vars rather than global_vars

Mon Aug  1 11:42:57 2005 - 1.013
	- Remove orphaned IO::Scalar dependencies which weren't listed as prereqs
	Added some other non-core (as of 5.004) prereqs

Sun May  8 16:12:47 2005 - 1.012
	- Added missing prereqs for unit tests

lib/Any/Template.pm  view on Meta::CPAN

	
	#Preprocess data if required
	$data = $self->{backend}->preprocess($data); 

	#Type-based dispatch
	die("Hash or array refs not supported as sinks") if(ref $collector eq "HASH" || ref $collector eq "ARRAY");
	return $self->{backend}->process_to_string($data, $collector) if(ref $collector eq "SCALAR"); 
	return $self->{backend}->process_to_sub($data, $collector) if(ref $collector eq "CODE");   
	return $self->{backend}->process_to_filehandle($data, $collector) if(ref $collector eq "GLOB"); #Filehandle ref
	return $self->{backend}->process_to_filehandle($data, \$collector) if(ref \$collector eq "GLOB"); #Filehandle
	return $self->{backend}->process_to_file($data, $collector) if(not ref $collector); #Must come after check for glob
	return $self->{backend}->process_to_filehandle($data, $collector); #object - treat as a filehandle
}

#Log::Trace stubs
sub TRACE{}
sub DUMP{}

=head1 NAME

Any::Template - provide a consistent interface to a wide array of templating languages

lib/Any/Template.pm  view on Meta::CPAN


=item my $template = new Any::Template(\%options);

	See below for a list of options

=item $template->process($data_structure, $sink);

	$sink can be:
		- a scalar ref
		- a filename (string)
		- a filehandle (as a glob or glob ref) or an object offering a print method
		- a coderef (output will be passed in as the first argument)

=item $string = $template->process($data_structure);

A convenience form, if no second argument is passed to C<process()>, equivalent to:
	
	my $string;
	$template->process($data_structure, \$string);

except data is passed by value rather than by reference.

lib/Any/Template/Backend.pm  view on Meta::CPAN

=item $templating_engine = $o->native_object()

Returns the underlying native template object.  You SHOULD supply this method.
Although accessing the underlying object defeats the point of Any::Template,
a valid use is in refactoring code, where dependencies on a particular engine's API
can be eradicated in iterations.

=item $data = $o->preprocess($data)

You CAN supply a method to preprocess the data structure before it's handed off to one of the process methods listed below.
Typically you might use this to remove some values from the data structure (e.g. globrefs) that a template backend
might not be able to handle.
The default implementation returns $data unmodified.

=item $o->process_to_string($data, $scalar_ref)

You MUST supply this method.
Example implementations can be found in backend classes included with the distribution.

=item $o->process_to_filehandle($data, $fh)

lib/Any/Template/Backend/Text/MicroMason.pm  view on Meta::CPAN

=head1 NAME

Any::Template::Backend::Text::MicroMason - Any::Template backend for Text::MicroMason

=head1 SYNOPSIS

	use Any::Template;
	my $template = new Any::Template(
		Backend => 'Text::MicroMason',
		Options => {
			Attributes => {global_vars => 1},      #MicroMason %attribs
			Mixins => [qw(-HTMLTemplate -Filters)] #Specify mixins
		},
		File => 'page.tmpl'
	);	
	my $output = $template->process($data);

=head1 DESCRIPTION

Attributes may be passed to Text::MicroMason in the {Options}{Attributes} key.  
The {Options}{Mixins} key is used to pass mixins to Text::MicroMason.  

t/html_template.t  view on Meta::CPAN


#Log::Trace
import Log::Trace qw(print) if($opt_t);
deep_import Log::Trace qw(print) if($opt_T);

#Compilation
require Any::Template::Backend::HTML::Template;
ok($INC{'Any/Template/Backend/HTML/Template.pm'}, "Compiled Any::Template::Backend::HTML::Template version $Any::Template::Backend::HTML::Template::VERSION");

#Check options are passed through to underlying object
#greating is only available in the loop if global_vars is true
my $obj = new Any::Template::Backend::HTML::Template( {String=>'<TMPL_LOOP NAME=loop><TMPL_VAR greating> <TMPL_VAR place></TMPL_LOOP>',Options=>{global_vars=>1}} );
ok(ref $obj eq 'Any::Template::Backend::HTML::Template', "object created");
my $rv;
$obj->process_to_string({loop=>[{greating=>'Hello'}],place=>'world'}, \$rv);
ok($rv eq 'Hello world', "supplied option has expected effect");

t/text_micromason.t  view on Meta::CPAN

import Log::Trace qw(print) if($opt_t);
deep_import Log::Trace qw(print) if($opt_T);

#Compilation
require Any::Template::Backend::Text::MicroMason;
ok($INC{'Any/Template/Backend/Text/MicroMason.pm'}, "Compiled Any::Template::Backend::Text::MicroMason version $Any::Template::Backend::Text::MicroMason::VERSION");

#Check options are passed through to underlying object
#here we use emulation of HTML::Template (see the html_template.t for test explanation
my $obj = new Any::Template::Backend::Text::MicroMason( {String=>'<TMPL_LOOP
NAME=loop><TMPL_VAR greating> <TMPL_VAR place></TMPL_LOOP>',Options=>{Attributes=>{loop_global_vars=>1},Mixins=>[qw(-HTMLTemplate -Filters)]}} );
ok(ref $obj eq 'Any::Template::Backend::Text::MicroMason', "object created");
my $rv;
$obj->process_to_string({loop=>[{greating=>'Hello'}],place=>'world'}, \$rv);
ok($rv eq 'Hello world', "supplied option has expected effect");



( run in 0.848 second using v1.01-cache-2.11-cpan-49f99fa48dc )