[Jifty-commit] r7480 - in Template-Declare/trunk: lib/Template

Jifty commits jifty-commit at lists.jifty.org
Fri Sep 4 00:00:48 EDT 2009


Author: theory
Date: Fri Sep  4 00:00:47 2009
New Revision: 7480

Added:
   Template-Declare/trunk/t/import-regression.t
Modified:
   Template-Declare/trunk/lib/Template/Declare.pm

Log:
Fixed regression in `import_templates` where it could go into a weird infinite
loop.



Modified: Template-Declare/trunk/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/trunk/lib/Template/Declare.pm	(original)
+++ Template-Declare/trunk/lib/Template/Declare.pm	Fri Sep  4 00:00:47 2009
@@ -489,7 +489,6 @@
     my $code          = shift;
     push @{ __PACKAGE__->templates()->{$class} }, $template_name;
     _register_template( $class, _template_name_to_sub($template_name), $code )
-
 }
 
 =head2 register_private_template( TEMPLATE_NAME, CODEREF )
@@ -596,20 +595,28 @@
         Class::ISA::self_and_super_path( $import_from_base );
 
     foreach my $import_from (@packages) {
-        foreach my $template_name ( @{ __PACKAGE__->templates()->{$import_from} } ) {
+        foreach my $template_name (  __PACKAGE__->_templates_for($import_from) ) {
             my $code = $import_from->_find_template_sub( _template_name_to_sub($template_name));
             $import_into->register_template( $prepend_path . "/" . $template_name, $code );
         }
-        foreach my $template_name ( @{ __PACKAGE__->private_templates()->{$import_from} } ) {
+        foreach my $template_name (  __PACKAGE__->_private_templates_for($import_from) ) {
             my $code = $import_from->_find_template_sub( _template_name_to_private_sub($template_name) );
             $import_into->register_private_template( $prepend_path . "/" . $template_name, $code );
         }
     }
+}
 
+sub _templates_for {
+    my $tmpl = shift->templates->{+shift} or return;
+    return wantarray ? @{ $tmpl } : $tmpl;
 }
 
-sub _has_template {
+sub _private_templates_for {
+    my $tmpl = shift->private_templates->{+shift} or return;
+    return wantarray ? @{ $tmpl } : $tmpl;
+}
 
+sub _has_template {
     # Otherwise find only in specific package
     my $pkg           = shift;
     my $template_name = shift;

Added: Template-Declare/trunk/t/import-regression.t
==============================================================================
--- (empty file)
+++ Template-Declare/trunk/t/import-regression.t	Fri Sep  4 00:00:47 2009
@@ -0,0 +1,34 @@
+use warnings;
+use strict;
+
+package Wifty::UI;
+use base qw/Template::Declare/;
+use Template::Declare::Tags;
+
+template 'test' => sub {
+    my $self = shift;
+    outs 'wowza';
+};
+
+import_templates Wifty::UI under '/here';
+
+package Wifty::UI::Woot;
+use base 'Wifty::UI';
+
+package main;
+#use Test::More tests => 19;
+use Test::More 'no_plan';
+use Template::Declare::Tags;
+Template::Declare->init( roots => ['Wifty::UI'] );
+
+ok +Wifty::UI->has_template('here/test'),
+    'Template should be under new path';
+ok +Wifty::UI->has_template('test'), 'Original template name should be visible';
+
+ok +Wifty::UI::Woot->has_template('here/test'),
+    'Moved template should be visible from subclass';
+ok +Wifty::UI::Woot->has_template('test'),
+    'Original template name should be visible from subclass';
+
+ok my $out = Template::Declare->show('here/test'), 'Should get output';
+is $out, 'wowza', 'Output should be correct';


More information about the Jifty-commit mailing list