Text::Template::Simple::Compiler::Safe - Safe compiler


Text-Template-Simple documentation Contained in the Text-Template-Simple distribution.

Index


Code Index:

NAME

Top

Text::Template::Simple::Compiler::Safe - Safe compiler

SYNOPSIS

Top

Private module.

DESCRIPTION

Top

This document describes version 0.83 of Text::Template::Simple::Compiler::Safe released on 9 February 2011.

Safe template compiler.

METHODS

Top

compile STRING

AUTHOR

Top

Burak Gursoy <burak@cpan.org>.

COPYRIGHT

Top

LICENSE

Top

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.1 or, at your option, any later version of Perl 5 you may have available.


Text-Template-Simple documentation Contained in the Text-Template-Simple distribution.

package Text::Template::Simple::Compiler::Safe;
# Safe compiler. Totally experimental
use strict;
use warnings;
use vars qw($VERSION);
use Text::Template::Simple::Dummy;

$VERSION = '0.83';

sub compile { shift; return __PACKAGE__->_object->reval(shift) }

sub _object {
   my $class = shift;
   if ( $class->can('object') ) {
      my $safe = $class->object;
      if ( $safe && ref $safe ) {
         return $safe if eval { $safe->isa('Safe'); 'Safe-is-OK' };
      }
      my $end = $@ ? q{: }.$@ : q{.};
      warn 'Safe object failed. Falling back to default' . $end . "\n";
   }
   require Safe;
   my $safe = Safe->new('Text::Template::Simple::Dummy');
   $safe->permit( $class->_permit );
   return $safe;
}

sub _permit {
   my $class = shift;
   return $class->permit if $class->can('permit');
   return qw( :default require caller );
}

1;

__END__