From: Uri Guttman Date: Thu, 22 Oct 2009 19:41:26 +0000 (-0400) Subject: fixed bug in compiler where it lost $+[0] during recursion X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=544b9c25915917ee9a3adc016851b59ab1088de4;p=urisagit%2FTemplate-Simple.git fixed bug in compiler where it lost $+[0] during recursion also cleaned up finding the template in render() --- diff --git a/lib/Template/Simple.pm b/lib/Template/Simple.pm index 15d3dae..10970d1 100644 --- a/lib/Template/Simple.pm +++ b/lib/Template/Simple.pm @@ -161,26 +161,29 @@ CODE while( my( $parsed_name, $parsed_body ) = $template =~ m{$self->{chunk_re}} ) { + my $chunk_left_index = $-[0] ; + my $chunk_right_index = $+[0] ; + # get the pre-match text and compile its scalars and text. append to the code $code .= $self->_compile_scalars( - substr( $template, 0, $-[0] ), $indent ) ; + substr( $template, 0, $chunk_left_index ), $indent ) ; -# print "OFF: $-[0] $+[0]\n" ; -# print "PRE: [", substr( $template, 0, $-[0] ), "]\n\n" ; # print "CHUNK: [$1] BODY [$2]\n\n" ; -# print "TRUNC: [", substr( $template, 0, $+[0] ), "]\n\n" ; -# print "LEFT: [$template]\n\n" ; +# print "TRUNC: [", substr( $template, 0, $chunk_right_index ), "]\n\n" ; +# print "PRE: [", substr( $template, 0, $chunk_left_index ), "]\n\n" ; + +# chop off the pre-match and the chunk + + substr( $template, 0, $chunk_right_index, '' ) ; + +# print "REMAIN: [$template]\n\n" ; # compile the nested chunk and append to the code $code .= $self->_compile_chunk( $parsed_name, $parsed_body, $indent ) ; - -# chop off the pre-match and the chunk - - substr( $template, 0, $+[0], '' ) ; } # compile trailing text for scalars and append to the code @@ -275,13 +278,12 @@ sub render { return $compiled->($data) ; } -# not compiled so get this template by name - - $tmpl_ref ||= eval{ $self->_get_template($template_name) } ; - -# we couldn't find this template name so assume it is the template text +# not compiled so try to get this template by name or +# assume the template name are is the actual template - $tmpl_ref ||= \$template_name ; + $tmpl_ref = + eval{ $self->_get_template($template_name) } || + \$template_name ; } my $rendered = $self->_render_includes( $tmpl_ref ) ;