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

Jifty commits jifty-commit at lists.jifty.org
Sun Feb 15 09:08:04 EST 2009


Author: gugod
Date: Sun Feb 15 09:08:02 2009
New Revision: 6341

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

Log:
 r9526 at yra:  gugod | 2008-12-26 11:26:49 +0800
 learn the wantarray trick from TD to make closures.


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	Sun Feb 15 09:08:02 2009
@@ -211,8 +211,22 @@
         } elsif(@attr > 1) {
             %ATTRIBUTES = (@attr);
         }
-        _tag($tag, $tagset, $block);
-    }
+
+        if ( defined wantarray and not wantarray ) {
+            my @__ = @_;
+            my $_self = $self;
+            my $sub = sub {
+                local $self = $_self;
+                local *__ANON__ = $tag;
+                _tag($tag, $tagset, @__);
+            };
+            bless $sub, 'Template::Declare::Tag';
+            return $sub;
+        }
+        else {
+            _tag($tag, $tagset, $block);
+        }
+    };
 }
 
 sub tag_parser_for {

Modified: Template-Declare/branches/markapl-syntax/t/closures.t
==============================================================================
--- Template-Declare/branches/markapl-syntax/t/closures.t	(original)
+++ Template-Declare/branches/markapl-syntax/t/closures.t	Sun Feb 15 09:08:02 2009
@@ -92,7 +92,7 @@
 for (qw(closure_1 closure_2 )) {
 Template::Declare->buffer->clear;
 my $simple = Template::Declare->show($_);
-#diag ($simple);
+# diag ($simple);
 like($simple, qr/<i>\s*<b>\s*Bolded\s*<\/b>\s*<\/i>/ms, "$_ matched");
 ok_lint($simple);
 }
@@ -119,7 +119,7 @@
 Template::Declare->buffer->clear;
 my $simple = Template::Declare->show('closure_6');
 ok($simple =~ /I decided to do\s*<i>\s*Something else\s*<\/i>/);
-#diag ($simple);
+# diag ($simple);
 ok_lint(Template::Declare->buffer->data());
 }
 


More information about the Jifty-commit mailing list