X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=urisagit%2FTemplate-Simple.git;a=blobdiff_plain;f=lib%2FTemplate%2FSimple.pm;h=10970d19f62471c00c8a3ce59229168c0f01a1bf;hp=15d3daeec93e6ff05072786b804d93e09cc85911;hb=544b9c25915917ee9a3adc016851b59ab1088de4;hpb=52705b1cdbecabbdf8efe04f45e31dde27dbc823 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 ) ;