[Jifty-commit] r7550 - in Template-Declare/branches/mixmaster: t

Jifty commits jifty-commit at lists.jifty.org
Wed Oct 14 20:30:47 EDT 2009


Author: theory
Date: Wed Oct 14 20:30:46 2009
New Revision: 7550

Modified:
   Template-Declare/branches/mixmaster/lib/Template/Declare.pm
   Template-Declare/branches/mixmaster/t/importing.t
   Template-Declare/branches/mixmaster/t/mixing.t

Log:
Straightend out relations between mixins and delegations.

* Restored `alias` as a first-class method. It is responsible for delegation.
* Changed `mix` so that the invocant to its templtes is always the class into which it was mixed. This is more like mixing in.
* Restored `import_templates` to its previous behavior of using the class into which the templates were imported as the invocant.

In short:

`mix` is the new name for `import_templates` and is responsible for mixins.
`alias` is restored and is responsible for delegation.
`import_templates` is no longer incompatible with previous versions, but is still deprecated.

With this change, I'm pretty happy with things. I'll finish the documentation
next week. But feel free to merge in the meantime.



Modified: Template-Declare/branches/mixmaster/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/branches/mixmaster/lib/Template/Declare.pm	(original)
+++ Template-Declare/branches/mixmaster/lib/Template/Declare.pm	Wed Oct 14 20:30:46 2009
@@ -768,7 +768,11 @@
 list in order to restore the template classes the default configuration, ready
 for the next request.
 
-=head2 Mixins
+=head2 Delegation and Mixins
+
+
+
+=head2 Tag Sets
 
 
 
@@ -924,9 +928,21 @@
         $into  = caller(0);
         $under = shift;
     }
-    $mixin->_import($into, $under, @_);
+    $mixin->_import($into, $into, $under, @_);
 }
 
+=head3 alias
+
+    alias Some::Clever:Templates under '/delegate';
+    alias Some::Other::Templates  under '/delegate', { name => 'Larry' };
+
+Delegates template calls to templates in another template class.
+XXX More to come.
+
+=cut
+
+sub alias { shift->_import(scalar caller(0), undef, @_) }
+
 =head3 package_variable( VARIABLE )
 
   $td->package_variable( $varname => $value );
@@ -1113,21 +1129,6 @@
 
 =head2 Old, deprecated or just better to avoid
 
-=head3 alias
-
-    alias Some::Clever::Mixin under '/mixin';
-    alias Some::Other::Mixin  under '/mymix', { name => 'Larry' };
-
-Like C<mix()>, but without support for the C<into> keyword. That is, it mixes
-templates into the calling template class.
-
-B<Deprecated> in favor of L</mix>. Will be supported for a long time, but
-new code should use C<mix()>.
-
-=cut
-
-sub alias { shift->_import(scalar caller(0), @_) }
-
 =head3 import_templates
 
     import_templates MyApp::Templates under '/something';
@@ -1141,7 +1142,10 @@
 
 =cut
 
-sub import_templates { shift->_import(scalar caller(0), @_) }
+sub import_templates {
+    my $caller = scalar caller(0);
+    shift->_import($caller, $caller, @_);
+}
 
 =head3 new_buffer_frame
 
@@ -1280,7 +1284,8 @@
 
 sub _import {
     return undef if $_[0] eq __PACKAGE__;
-    my ($mixin, $into, $prefix, $vars) = @_;
+    my ($mixin, $into, $invocant, $prefix, $vars) = @_;
+
 
     $prefix =~ s|/+/|/|g;
     $prefix =~ s|/$||;
@@ -1293,13 +1298,13 @@
         for my $tname (  __PACKAGE__->_templates_for($from) ) {
             $into->register_template(
                 "$prefix/$tname",
-                _import_code( $tname, $from, $mixin, $vars )
+                _import_code( $tname, $from, $invocant || $mixin, $vars )
             );
         }
         for my $tname (  __PACKAGE__->_private_templates_for($from) ) {
             $into->register_private_template(
                 "$prefix/$tname",
-                _import_code( $tname, $from, $mixin, $vars )
+                _import_code( $tname, $from, $invocant || $mixin, $vars )
             );
         }
     }

Modified: Template-Declare/branches/mixmaster/t/importing.t
==============================================================================
--- Template-Declare/branches/mixmaster/t/importing.t	(original)
+++ Template-Declare/branches/mixmaster/t/importing.t	Wed Oct 14 20:30:46 2009
@@ -93,7 +93,7 @@
 {
     ok my $simple = ( show('imported_pkg/imported') ), 'Should get output for imported template';
     like( $simple, qr'Invocant:', 'Its output should be correct' );
-    like( $simple, qr{'Wifty::UI::imported_pkg'}, '$self is correct in template block' );
+    like( $simple, qr{'Wifty::UI'}, '$self is correct in template block' );
     ok_lint($simple);
 }
 {
@@ -106,7 +106,7 @@
     );
     like(
         $simple,
-        qr{'Wifty::UI::imported_subclass_pkg'},
+        qr{'Wifty::UI'},
         '$self is correct in template block'
     );
     ok_lint($simple);

Modified: Template-Declare/branches/mixmaster/t/mixing.t
==============================================================================
--- Template-Declare/branches/mixmaster/t/mixing.t	(original)
+++ Template-Declare/branches/mixmaster/t/mixing.t	Wed Oct 14 20:30:46 2009
@@ -71,7 +71,7 @@
     ok my $simple = ( show('mixed_pkg/mixed') ), 'Should get output from mix template';
     like( $simple, qr'Invocant:', 'Its output should be right' );
     like( $simple, qr'Variable SET' , "The variable was set");
-    like( $simple, qr{'Wifty::UI::mixed_pkg'},
+    like( $simple, qr{'Wifty::UI'},
         '$self is correct in template block' );
     ok_lint($simple);
 }
@@ -81,7 +81,7 @@
     ok my $simple = ( show('mixed_pkg2/mixed') ), 'Should get output from second mix';
     like( $simple, qr'Invocant:', 'Its output should be right' );
     unlike( $simple, qr'Varialble SET' , 'But the variable should not be set');
-    like( $simple, qr{'Wifty::UI::mixed_pkg'},
+    like( $simple, qr{'Wifty::UI'},
         '$self is correct in template block' );
     ok_lint($simple);
 }
@@ -91,7 +91,7 @@
     ok my $simple = ( show('mixed_pkg3/mixed') ), 'Should get output from third mix';
     like( $simple, qr'Invocant:', 'Its output should be right' );
     unlike( $simple, qr'Varialble SET' , 'But the variable should not be set');
-    like( $simple, qr{'Wifty::UI::mixed_pkg'},
+    like( $simple, qr{'Wifty::UI'},
         '$self is correct in template block' );
     ok_lint($simple);
 }
@@ -101,7 +101,7 @@
     ok my $simple = ( show('mixed_pkg4/mixed') ), 'Should get output from fourth mix';
     like( $simple, qr'Invocant:', 'Its output should be right' );
     unlike( $simple, qr'Varialble SET' , 'But the variable should not be set');
-    like( $simple, qr{'Wifty::UI::mixed_pkg'},
+    like( $simple, qr{'Wifty::UI'},
         '$self is correct in template block' );
     ok_lint($simple);
 }
@@ -116,7 +116,7 @@
     );
     like(
         $simple,
-        qr{'Wifty::UI::mixed_subclass_pkg'},
+        qr{'Wifty::UI'},
         '$self is correct in template block'
     );
     ok_lint($simple);


More information about the Jifty-commit mailing list