[Jifty-commit] r6182 - in Template-Declare/branches/markapl-syntax: lib/Template/Declare

Jifty commits jifty-commit at lists.jifty.org
Wed Dec 24 22:21:06 EST 2008


Author: gugod
Date: Wed Dec 24 22:21:03 2008
New Revision: 6182

Modified:
   Template-Declare/branches/markapl-syntax/   (props changed)
   Template-Declare/branches/markapl-syntax/lib/Template/Declare/TagCompiler.pm
   Template-Declare/branches/markapl-syntax/lib/Template/Declare/Tags.pm

Log:
 r9510 at yra:  gugod | 2008-12-25 10:33:08 +0800
 Merge no-semi change from Markapl.
 


Modified: Template-Declare/branches/markapl-syntax/lib/Template/Declare/TagCompiler.pm
==============================================================================
--- Template-Declare/branches/markapl-syntax/lib/Template/Declare/TagCompiler.pm	(original)
+++ Template-Declare/branches/markapl-syntax/lib/Template/Declare/TagCompiler.pm	Wed Dec 24 22:21:03 2008
@@ -3,6 +3,7 @@
 use strict;
 use warnings;
 use Devel::Declare ();
+use B::Hooks::EndOfScope;
 
 our $VERSION = 0.02;
 
@@ -74,6 +75,15 @@
     }
 }
 
+sub inject_scope {
+    on_scope_end {
+        my $linestr = Devel::Declare::get_linestr;
+        my $offset = Devel::Declare::get_linestr_offset;
+        substr($linestr, $offset, 0) = ';';
+        Devel::Declare::set_linestr($linestr);
+    };
+}
+
 my %alt = (
     'cell'      => 'td',
     'row'       => 'tr',
@@ -86,6 +96,41 @@
     'html_tr'   => 'tr',
 );
 
+sub _tag {
+    my ($tag) = @_;
+
+    return sub {
+        my $block = pop;
+        my @attr = @_;
+
+        my $attr = "";
+
+        if (@attr == 1) {
+            my $css = $attr[0];
+            while ($css =~ /([\#\.])(\w+)/g) {
+                if ($1 eq '#') {
+                    $attr .= qq{ id="$2"};
+                } else {
+                    $attr .= qq{ class="$2"};
+                }
+            }
+        } else {
+            while(my ($k, $v) = splice(@attr, 0, 2)) {
+                $attr .= " $k=\"$v\"";
+            }
+        }
+
+        my $buf = "<${tag}${attr}>";
+        Template::Declare->new_buffer_frame;
+        Template::Declare->buffer->append( $block->() )
+                if defined $block && ref($block) eq 'CODE';
+        $buf .= Template::Declare->end_buffer_frame->data || "";
+        $buf .= "</$tag>";
+        Template::Declare->buffer->append( $buf );
+        return '';
+    }
+}
+
 sub tag_parser_for {
     my ($tag) = @_;
     $tag = $alt{$tag} if defined($alt{$tag});
@@ -103,6 +148,8 @@
         my $name = strip_name;
         my $proto = strip_proto;
 
+        inject_if_block("{ no strict; BEGIN { Template::Declare::TagCompiler::inject_scope }; };");
+
         if (defined($proto)) {
             inject_before_block("$proto, sub");
         }
@@ -110,47 +157,7 @@
             inject_before_block("sub");
         }
 
-        shadow(
-            sub {
-                my $block = pop;
-                my @attr = @_;
-
-                my $attr = "";
-
-                if (@attr == 1) {
-                    my $css = $attr[0];
-                    while ($css =~ /([\#\.])(\w+)/g) {
-                        if ($1 eq '#') {
-                            $attr .= qq{ id="$2"};
-                        } else {
-                            $attr .= qq{ class="$2"};
-                        }
-                    }
-                } else {
-                    my ($k, $v) = (shift @attr, shift @attr);
-                    while ($k && $v) {
-                        $attr .= " $k=\"$v\"";
-                        ($k, $v) = (shift @attr, shift @attr);
-                    }
-                }
-
-                my $buf = "<${tag}${attr}>";
-
-                Template::Declare->new_buffer_frame;
-
-                Template::Declare->buffer->append( $block->() )
-                    if defined $block && ref($block) eq 'CODE';
-
-                $buf .= Template::Declare->end_buffer_frame->data || "";
-
-                $buf .= "</$tag>";
-
-                Template::Declare->buffer->append( $buf );
-
-                return '';
-            }
-        );
-
+        shadow(_tag($tag));
     }
 }
 

Modified: Template-Declare/branches/markapl-syntax/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/branches/markapl-syntax/lib/Template/Declare/Tags.pm	(original)
+++ Template-Declare/branches/markapl-syntax/lib/Template/Declare/Tags.pm	Wed Dec 24 22:21:03 2008
@@ -77,7 +77,6 @@
                 $tag = $alternative;
             }
             
-            print STDERR "Will install $tag\n";
             $code_str .= qq{sub $tag (&);};
             $config->{$tag} = {
                 const => Template::Declare::TagCompiler::tag_parser_for($tag)


More information about the Jifty-commit mailing list