[Jifty-commit] r7551 - in Template-Declare/branches/mixmaster: . t
Jifty commits
jifty-commit at lists.jifty.org
Thu Oct 15 01:10:10 EDT 2009
Author: theory
Date: Thu Oct 15 01:10:08 2009
New Revision: 7551
Modified:
Template-Declare/branches/mixmaster/Changes
Template-Declare/branches/mixmaster/lib/Template/Declare.pm
Template-Declare/branches/mixmaster/t/aliasing.t
Log:
Added `into` support to `alias`. Also updated `Changes`.
Modified: Template-Declare/branches/mixmaster/Changes
==============================================================================
--- Template-Declare/branches/mixmaster/Changes (original)
+++ Template-Declare/branches/mixmaster/Changes Thu Oct 15 01:10:08 2009
@@ -1,16 +1,17 @@
0.41
-* Documented aliasing and template importing (mixins).
-* Reworked all the documentation, neatening things, fixing bugs in the
- examples, and adding missing docs for various functions and methods.
+* Reworked all the documentation, neatening things, expanding the "USAGE"
+ section, fixing bugs in the examples, and adding missing docs for various
+ functions and methods.
* Added "dispatch_to" to replace "roots", which is now deprecated. Note that
"dispatch_to" resolves to template classes in the opposite order to "roots".
This won't be an issue if you only use a single temlate class.
* Converted the implementation of "alias" to be the same as that used for
- "import_templates".
-* Changed aliases imported from subclasses such that their invocants are the
- classes in which they are defined, rather than the subclass. This makes
- "alias" consistent with "import_templates".
-* Added "mix" and deprecated "alias" and "import_templates".
+ "import_templates", which is much more efficient.
+* Added the "into" parameter to "alias" and "import_templates".
+* Added the "setting" syntactical sugar keyword for use with "alias".
+* Renamed "import_templates" to "mix". The former is still around, but is
+ deprecated.
+* Added support for package variables with "mix".
* Deprecated the undocumented "aliases()" and "alias_metadata()" methods, as
they are no longer needed. They're now no-ops that issue warnings. To be
removed altogether in a future version.
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 Thu Oct 15 01:10:08 2009
@@ -768,7 +768,7 @@
list in order to restore the template classes the default configuration, ready
for the next request.
-=head2 Delegation and Mixins
+=head2 Aliasing and Mixins
@@ -919,16 +919,8 @@
sub mix {
my $mixin = shift;
- my ($into, $under);
- if ( eval { $_[0]->isa(__PACKAGE__) } ) {
- ($into, $under) = (shift, shift);
- } elsif ( eval { $_[1]->isa(__PACKAGE__) } ) {
- ($under, $into) = (shift, shift);
- } else {
- $into = caller(0);
- $under = shift;
- }
- $mixin->_import($into, $into, $under, @_);
+ my ($into, @args) = _into(@_);
+ $mixin->_import($into, $into, @args);
}
=head3 alias
@@ -941,7 +933,12 @@
=cut
-sub alias { shift->_import(scalar caller(0), undef, @_) }
+# XXX fix to accept `into` parameter.
+sub alias {
+ my $mixin = shift;
+ my ($into, @args) = _into(@_);
+ $mixin->_import($into, undef, @args);
+}
=head3 package_variable( VARIABLE )
@@ -1282,6 +1279,19 @@
*{ $class . '::' . $subname } = $coderef;
}
+sub _into {
+ my ($into, $under);
+ if ( eval { $_[0]->isa(__PACKAGE__) } ) {
+ ($into, $under) = (shift, shift);
+ } elsif ( eval { $_[1]->isa(__PACKAGE__) } ) {
+ ($under, $into) = (shift, shift);
+ } else {
+ $into = caller(1);
+ $under = shift;
+ }
+ return $into, $under, @_;
+}
+
sub _import {
return undef if $_[0] eq __PACKAGE__;
my ($mixin, $into, $invocant, $prefix, $vars) = @_;
Modified: Template-Declare/branches/mixmaster/t/aliasing.t
==============================================================================
--- Template-Declare/branches/mixmaster/t/aliasing.t (original)
+++ Template-Declare/branches/mixmaster/t/aliasing.t Thu Oct 15 01:10:08 2009
@@ -8,7 +8,7 @@
template 'aliased' => sub {
my $self = shift;
- div { outs_raw "Invocant: '$self'" };
+ div { outs_raw "Invocant: '$self'" };
div { 'Variable ', $self->package_variable('VARIABLE') };
};
@@ -27,7 +27,7 @@
html {
head {};
body { show 'private-content'; };
- }
+ }
};
@@ -38,16 +38,23 @@
};
};
-alias Wifty::UI::aliased_pkg under '/aliased_pkg', { VARIABLE => 'SET' } ;
+alias Wifty::UI::aliased_pkg under '/aliased_pkg', setting { VARIABLE => 'SET' } ;
alias Wifty::UI::aliased_pkg under '/aliased_pkg2';
alias Wifty::UI::aliased_subclass_pkg under '/aliased_subclass_pkg';
##############################################################################
package main;
use Template::Declare::Tags;
+
+# Alias from outside the class.
+alias Wifty::UI::aliased_pkg into Wifty::UI, under '/aliased_pkg3';
+# And reverse.
+alias Wifty::UI::aliased_pkg under '/aliased_pkg4', into Wifty::UI
+
+# Fire it up.
Template::Declare->init( dispatch_to => ['Wifty::UI'] );
-use Test::More tests => 19;
+use Test::More tests => 29;
require "t/utils.pl";
ok( Wifty::UI::aliased_pkg->has_template('aliased'), 'Aliased package should have template' );
@@ -56,7 +63,6 @@
ok( Template::Declare->has_template('aliased_pkg/aliased'), 'TD should find alias' );
-
ok( Template::Declare->has_template('aliased_subclass_pkg/aliased'),
'Alias should be visible in a subclass, too' );
@@ -73,7 +79,27 @@
{
# Try the second alias with no variable.
ok my $simple = ( show('aliased_pkg2/aliased') ), 'Should get output from second alias';
- like( $simple, qr'Invocant', 'Its output should be right' );
+ 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::aliased_pkg'},
+ '$self is correct in template block' );
+ ok_lint($simple);
+}
+
+{
+ # Try the third alias using `into`.
+ ok my $simple = ( show('aliased_pkg3/aliased') ), 'Should get output from third alias';
+ 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::aliased_pkg'},
+ '$self is correct in template block' );
+ ok_lint($simple);
+}
+
+{
+ # Try the fourth with `into` and `under` reversed.
+ ok my $simple = ( show('aliased_pkg4/aliased') ), 'Should get output from fourth alias';
+ 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::aliased_pkg'},
'$self is correct in template block' );
More information about the Jifty-commit
mailing list