Burak Gürsoy avatar Burak Gürsoy committed d323465

move command parsing into it's own method

Comments (0)

Files changed (1)

lib/Text/Template/Simple/Base/Parser.pm

    my $uthandler = $self->[USER_THANDLER];
 
    my $h = {
-      raw     => sub { ";$faker .= q~$_[0]~;" },
-      capture => sub { ";$faker .= sub {" . $_[0] . "}->();"; },
-      code    => sub { $_[0] . ';' },
+      raw          => sub { ";$faker .= q~$_[0]~;" },
+      capture      => sub { ";$faker .= sub {" . $_[0] . "}->();"; },
+      capture_anon => sub {        " .= sub {" . $_[0] . "}->();"; },
+      code         => sub { $_[0] . ';' },
    };
 
    # little hack to convert delims into escaped delims for static inclusion
       elsif ( T_CAPTURE == $id ) {
          $code .= $faker;
          $code .= $resume ? $self->_resume($str, RESUME_NOSTART)
-                :           " .= sub { $str }->();";
+                :           $h->{capture_anon}->( $str );
       }
 
       elsif ( T_DYNAMIC == $id || T_STATIC == $id ) {
       }
 
       elsif ( T_COMMAND == $id ) {
-         my($head, $raw_block) = split /;/, $str, 2;
-         my @buf = split RE_PIPE_SPLIT, '|' . trim($head);
-         shift(@buf);
-         my %com = map { trim $_ } @buf;
-
-         if ( $com{FILTER} ) {
-            # embed into the template & NEEDS_OBJECT++ ???
-            local $self->[FILENAME] = '<ANON BLOCK>';
-            $self->_call_filters(
-               \$raw_block,
-               split RE_FILTER_SPLIT, $com{FILTER}
-            );
-         }
-
-         $code .= $h->{raw}->($raw_block);
+         $code .= $h->{raw}->( $self->_parse_command( $str ) );
       }
 
       else {
    return $self->_wrapper( $code, $cache_id, $faker, $map_keys, $h );
 }
 
+sub _parse_command {
+   my $self = shift;
+   my $str  = shift;
+   my($head, $raw_block) = split /;/, $str, 2;
+   my @buf  = split RE_PIPE_SPLIT, '|' . trim($head);
+   shift(@buf);
+   my %com  = map { trim $_ } @buf;
+
+   if ( $com{FILTER} ) {
+      # embed into the template & NEEDS_OBJECT++ ???
+      local $self->[FILENAME] = '<ANON BLOCK>';
+      $self->_call_filters( \$raw_block, split RE_FILTER_SPLIT, $com{FILTER} );
+   }
+
+   return $raw_block;
+}
+
 sub _chomp {
    # remove the unnecessary white space
    my $self = shift;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.