[Jifty-commit] r2466 - in Template-Declare: lib/Template
lib/Template/Declare t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Jan 5 01:03:15 EST 2007
Author: jesse
Date: Fri Jan 5 01:03:14 2007
New Revision: 2466
Modified:
Template-Declare/ (props changed)
Template-Declare/lib/Template/Declare.pm
Template-Declare/lib/Template/Declare/Tags.pm
Template-Declare/t/roots.t
Log:
r46753 at pinglin: jesse | 2007-01-04 23:21:33 -0500
* more work on import. it now _parses
Modified: Template-Declare/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/lib/Template/Declare.pm (original)
+++ Template-Declare/lib/Template/Declare.pm Fri Jan 5 01:03:14 2007
@@ -1,13 +1,16 @@
use warnings;
use strict;
+use Carp;
package Template::Declare;
use base 'Class::Data::Inheritable';
__PACKAGE__->mk_classdata('roots');
+__PACKAGE__->mk_classdata('imported_paths');
__PACKAGE__->roots([]);
+__PACKAGE__->imported_paths({});
$Template::Declare::VERSION = "0.00_01";
@@ -58,6 +61,15 @@
}
+sub import { return undef if $_[0] eq 'Template::Declare';
+ my $pkg = caller(0);
+ warn "$pkg";
+ __PACKAGE__->imported_paths({$pkg}->{$_[1]} = $_[0]);
+
+ warn "$pkg: Importing ".$_[0] . " under ". $_[1];
+}
+
+
=head2 has_template
=cut
@@ -80,22 +92,24 @@
my $show_private = shift || 0;
foreach my $package ( reverse @{ Template::Declare->roots } ) {
- if ( my $coderef
- = $package->can( _template_name_to_sub($template_name) ) )
- {
+ if ( my $coderef = $package->_find_template_sub( _template_name_to_sub($template_name) ) ) {
return $coderef;
}
- elsif ( $show_private
- and $coderef
- = $package->can( _template_name_to_private_sub($template_name) ) )
- {
+ elsif ( $show_private and $coderef = $package->_find_template_sub( _template_name_to_private_sub($template_name) ) ) {
return $coderef;
}
}
return undef;
}
+
+sub _find_template_sub {
+ my $self = shift;
+ my $subname = shift;
+ return $self->can($subname);
+}
+
sub _template_name_to_sub {
return _subname( "_jifty_template_", shift);
Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/lib/Template/Declare/Tags.pm Fri Jan 5 01:03:14 2007
@@ -5,11 +5,16 @@
use Template::Declare;
use vars qw/@EXPORT @EXPORT_OK $PRIVATE $self/;
use base 'Exporter';
+use Carp;
@EXPORT =
- qw( with template private show get_current_attr attr outs outs_raw in_isolation $self
+ qw( with template private show get_current_attr attr outs outs_raw in_isolation $self under
Tr td ); # these two warns the user to use row/cell instead
+
+sub under ($) { return shift }
+
+
our $DEPTH = 0;
our %ATTRIBUTES = ();
our $BUFFER = '';
Modified: Template-Declare/t/roots.t
==============================================================================
--- Template-Declare/t/roots.t (original)
+++ Template-Declare/t/roots.t Fri Jan 5 01:03:14 2007
@@ -1,6 +1,14 @@
use warnings;
use strict;
+package Wifty::UI::something;
+use base qw/Template::Declare/;
+use Template::Declare::Tags;
+
+template 'imported' => sub {
+ div { outs('This is imported') };
+};
+
package Wifty::UI;
use base qw/Template::Declare/;
use Template::Declare::Tags;
@@ -20,8 +28,9 @@
};
};
-package Wifty::UI::something;
-use base 'Wifty::UI';
+
+import Wifty::UI::something under '/something';
+
package Baseclass::UI;
use base qw/Template::Declare/;
@@ -86,8 +95,8 @@
{
local $Template::Declare::Tags::BUFFER;
- my $simple = ( show('something/simple') );
- like( $simple, qr'This is child class content' );
+ my $simple = ( show('something/imported') );
+ like( $simple, qr'This is imported' );
ok_lint($simple);
}
More information about the Jifty-commit
mailing list