Basset

 view release on metacpan or  search on metacpan

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

sub template {
	my $self = shift;

	my $tpl = $self->_template(@_);
	my $root = $self->document_root;

	if (defined $tpl && defined $root && $tpl =~ m!^/! && $tpl !~ m!^$root!) {
		my $full_path_to_tpl = $root . $tpl;
		$full_path_to_tpl =~ s!//+!/!g;
		return $full_path_to_tpl;
	}
	else {
		return $tpl;
	};

}

=pod

=item preprocessed_template

This stores the value of the template after it's been run through the preprocessor. You probably don't
want to touch this unless you B<really> know what you're doing.

Still, it's sometimes useful to look at for debugging purposes, if your template isn't displaying properly.
Be warned - it's a bitch to read.

=cut

__PACKAGE__->add_attr('preprocessed_template');

#This is the template we're currently operating on. Internal attribute. Don't touch it.

__PACKAGE__->add_attr('_current_template');

#internal method. All templates evaluate in their own distinct package. This is it.
#This value is set by gen_package

__PACKAGE__->add_attr('package');

#internal method. As a template evaluates, its output gets tacked onto a scalar. This is it.
#This value is set by gen_file

__PACKAGE__->add_attr('file');

__PACKAGE__->add_attr('_preprocessed_inserted_file_cache');

=pod

=item caching

Boolean flag. 1/0.

templates are obviously not executable code. Nothing can be done with them, they're nonsensical. So, before they can
be used, they must be preprocessed into something useful. That preprocessing step is reasonably fast, but it's still
effectively overhead. You don't care about the transformations happening, you just want it to work!

Besides most templates are modified very rarely - it's normally the same thing being re-displayed. So constantly re-preprocessing
it is inefficient. So, you may turn on caching.

If caching is on, during preprocessing the template looks in your cache_dir. If it finds a preprocessed version that is
current, it grabs that version and returns it. No more additional processing. If it finds a preprocessed version that is
out of date (i.e., the actual template was modified after the cached version was created) then it looks to the new
template and re-caches it. If no cached value is found, then one is cached for future use.

=cut

__PACKAGE__->add_attr('caching');

=pod

=item cache_dir

This is your cache directory, used if caching is on.

 $template->cache_dir('/path/to/my/cache/dir/');

=cut

__PACKAGE__->add_attr('cache_dir');

=pod

=item compress_whitespace

Boolean flag. 1/0.

Sometimes whitespace in your template doesn't matter. an HTML file, for example. So, you can compress it. That way
you're sending less data to a web browser, for instance.

compress_whitespace turns runs of spaces or tabs into a single space, and runs of newlines into a single newline.

=cut

__PACKAGE__->add_attr('compress_whitespace');

sub init {
	return shift->SUPER::init(
		{
			'open_return_tag'			=> '<%',
			'close_return_tag'			=> '%>',
			'open_eval_tag'				=> '%%',
			'close_eval_tag'			=> "\n",
			'big_open_eval_tag'			=> '<code>',
			'big_close_eval_tag'		=> "</code>",
			'open_comment_tag'			=> '<#',
			'close_comment_tag'			=> '#>',
			'open_include_tag'			=> '<&',
			'close_include_tag'			=> '&>',
			'open_cached_include_tag'	=> '<&+',
			'close_cached_include_tag'	=> '+&>',
			'open_debug_tag'			=> '<debug>',
			'close_debug_tag'			=> '</debug>',
			'cache_all_inserts'			=> 0,
			
			'caching'					=> 1,
			'compress_whitespace'		=> 1,
			'allows_debugging'			=> 1,
			
			'_full_file_path_cache'	=> {},
			'_preprocessed_inserted_file_cache' => {},
		},
		@_



( run in 1.650 second using v1.01-cache-2.11-cpan-aadc1410aed )