[Jifty-commit] r3050 - in Template-Declare: t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Mar 23 21:56:02 EDT 2007


Author: clkao
Date: Fri Mar 23 21:56:01 2007
New Revision: 3050

Modified:
   Template-Declare/lib/Template/Declare.pm
   Template-Declare/t/importing.t

Log:
path_for method to do resolution for imported templates.

Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm	(original)
+++ Template-Declare/lib/Template/Declare.pm	Fri Mar 23 21:56:01 2007
@@ -15,6 +15,7 @@
 __PACKAGE__->mk_classdata('templates');
 __PACKAGE__->mk_classdata('private_templates');
 __PACKAGE__->mk_classdata('buffer_stack');
+__PACKAGE__->mk_classdata('imported_into');
 
 
 __PACKAGE__->roots([]);
@@ -236,6 +237,8 @@
     my $import_from_base = shift;
     my $prepend_path     = shift;
 
+    $import_from_base->imported_into($prepend_path);
+
     my @packages;
     {
         no strict 'refs';
@@ -262,6 +265,20 @@
 
 }
 
+=head2 path_for
+
+ Returns the path for the template name to be used for show, adjusted
+ with paths used in import_templates.
+
+=cut
+
+sub path_for {
+    my ($class, $template) = @_;
+    my $prepend = $class->imported_into;
+    $prepend = '' unless defined $prepend;
+    return $prepend . '/' . $template;
+}
+
 
 =head2 has_template PACKAGE TEMPLATE_NAME SHOW_PRIVATE
 

Modified: Template-Declare/t/importing.t
==============================================================================
--- Template-Declare/t/importing.t	(original)
+++ Template-Declare/t/importing.t	Fri Mar 23 21:56:01 2007
@@ -41,7 +41,7 @@
 use Template::Declare::Tags;
 Template::Declare->init( roots => ['Wifty::UI'] );
 
-use Test::More tests => 10;
+use Test::More tests => 12;
 require "t/utils.pl";
 
 ok( Wifty::UI::imported_pkg->has_template('imported') );
@@ -50,6 +50,9 @@
 ok( Template::Declare->has_template('imported_pkg/imported') );
 ok( Template::Declare->has_template('imported_subclass_pkg/imported'), "When you subclass and then import, the superclass's imports are there" );
 
+is( Wifty::UI::imported_subclass_pkg->path_for('imported'), '/imported_subclass_pkg/imported' );
+is( Wifty::UI->path_for('simple'), '/simple' );
+
 {
     my $simple = ( show('imported_pkg/imported') );
     like( $simple, qr'This is imported' );


More information about the Jifty-commit mailing list