Template-EmbeddedPerl

 view release on metacpan or  search on metacpan

README.mkdn  view on Meta::CPAN

Can't locate object method "input" at /path/to/templates/hello.yat line 4.

    3:     <%= label('first_name') %>
    4:     <%= input('first_name') %>
    5:     <%= errors('last_name') %>

# ENVIRONMENT VARIABLES

The module respects the following environment variables: 

- `DEBUG_TEMPLATE_EMBEDDED_PERL`

    Set this to a true value to print the compiled template code to the console. Useful
    when trying to debug difficult compilation issues, especially given this is early
    access code and you might run into bugs.

# REPORTING BUGS & GETTING HELP

If you find a bug, please report it on the GitHub issue tracker at
[https://github.com/jjn1056/Template-EmbeddedPerl/issues](https://github.com/jjn1056/Template-EmbeddedPerl/issues).  The bug tracker is
the easiest way to get help with this module from me but I'm also on irc.perl.org

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

  $self->inject_helpers;
  return $self;
}

sub inject_helpers {
  my ($self) = @_;
  my %helpers = $self->get_helpers;
  foreach my $helper(keys %helpers) {
    if($self->{sandbox_ns}->can($helper)) {
      warn "Skipping injection of helper '$helper'; already exists in namespace $self->{sandbox_ns}" 
        if $ENV{DEBUG_TEMPLATE_EMBEDDED_PERL};
      next;
    }
    eval qq[
      package @{[ $self->{sandbox_ns} ]};
      sub $helper { \$self->get_helpers('$helper')->(\$self, \@_) }
    ]; die $@ if $@;
  }
}

sub get_helpers {

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

      my $escaped_newline_start = $content =~ s/^\\\n//mg;
      my $escaped_newline_end = $content =~ s/\\\n$//mg;

      $content =~ s/^\\\\/\\/mg;   
      $compiled .= "@{[$escaped_newline_start ? qq[\n]:'' ]} \$_O .= \"" . quotemeta($content) . "\";@{[$escaped_newline_end ? qq[\n]:'' ]}";
    }
  }

  $compiled = $self->compiled($compiled);

  warn "Compiled: $compiled\n" if $ENV{DEBUG_TEMPLATE_EMBEDDED_PERL};

  my $code = eval $compiled; if($@) {
    die generate_error_message($@, $template, $source);
  }

  return $code;
}

sub compiled {
  my ($self, $compiled) = @_;

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

  3:     <%= label('first_name') %>
  4:     <%= input('first_name') %>
  5:     <%= errors('last_name') %>

=head1 ENVIRONMENT VARIABLES

The module respects the following environment variables: 

=over 4

=item * C<DEBUG_TEMPLATE_EMBEDDED_PERL>

Set this to a true value to print the compiled template code to the console. Useful
when trying to debug difficult compilation issues, especially given this is early
access code and you might run into bugs.

=back

=head1 REPORTING BUGS & GETTING HELP

If you find a bug, please report it on the GitHub issue tracker at

lib/Template/EmbeddedPerl/Utils.pm  view on Meta::CPAN

    $escaped =~ s/`/\\`/g;   # Escape backticks
    $escaped =~ s/\$/\\\$/g; # Escape dollar signs
    $escaped =~ s/'/\\'/g;   # Escape single quotes

    return $escaped;
}

sub generate_error_message {
  my ($msg, $template, $source) = @_;

  warn "RAW MESSAGE: [$msg]" if $ENV{DEBUG_TEMPLATE_EMBEDDED_PERL};

  $source = $source ? "$source" : 'unknown';

  my @files;
  push @files, [$1, $2, $3, $msg] while $msg =~ /^(.+?) at\s+(.+?)\s+line\s+(\d+)/gm;

  my $text = '';
  foreach my $file (@files) {
    my ($msg, $file, $line, $extra) = @$file; 
    if($file !~ m/eval/) {



( run in 0.468 second using v1.01-cache-2.11-cpan-71847e10f99 )