[Jifty-commit] r3069 - in Template-Declare: lib/Template/Declare t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Tue Mar 27 23:21:19 EDT 2007
Author: jesse
Date: Tue Mar 27 23:21:18 2007
New Revision: 3069
Modified:
Template-Declare/ (props changed)
Template-Declare/lib/Template/Declare/Tags.pm
Template-Declare/t/trivial.t
Log:
r54254 at pinglin: jesse | 2007-03-27 20:18:21 -0700
* Getting closer to supporting closures of tags.
Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/lib/Template/Declare/Tags.pm Tue Mar 27 23:21:18 2007
@@ -117,7 +117,7 @@
Template::Declare->new_buffer_frame;
foreach my $item ( grep {defined} @phrases ) {
- Template::Declare->buffer->append( ref($item) eq 'CODE' ? $item->() : ($raw ? $item: _escape_utf8($item)) );
+ Template::Declare->buffer->append( (ref($item) && $item->isa('Template::Declare::Tag')) ? $item->() : ($raw ? $item: _escape_utf8($item)) );
}
$buf = Template::Declare->buffer->data;
@@ -191,11 +191,13 @@
# Scalar context - return a coderef that represents ourselves.
my @__ = @_;
my $_self = $self;
- sub {
+ my $sub =sub {
local $self = $_self;
local *__ANON__ = $tag;
_tag(@__);
};
+ bless $sub, 'Template::Declare::Tag';
+ return $sub;
} else {
_tag(@_);
}
@@ -342,7 +344,7 @@
%ATTRIBUTES = ();
Template::Declare->new_buffer_frame;
my $last = join '', map {
- ref($_) eq 'CODE' ? $_->() : ( ref($_) ? $_ : _escape_utf8($_) )
+ (ref($_) && $_->isa('Template::Declare::Tag')) ? $_->() : ( ref($_) ? $_ : _escape_utf8($_) )
} $code->();
if ( length(Template::Declare->buffer->data) ) {
@@ -496,4 +498,22 @@
=cut
+package Template::Declare::Tag;
+use overload
+ '""' => \&as_string;
+
+sub as_string {
+ my $self = shift;
+ return $self unless ( wantarray);
+ my $buf;
+ Template::Declare->new_buffer_frame;
+ $self->();
+ $buf .= Template::Declare->buffer->data;
+ Template::Declare->end_buffer_frame;
+
+ return $buf;
+
+}
+
+
1;
Modified: Template-Declare/t/trivial.t
==============================================================================
--- Template-Declare/t/trivial.t (original)
+++ Template-Declare/t/trivial.t Tue Mar 27 23:21:18 2007
@@ -146,21 +146,21 @@
{
Template::Declare->buffer->clear;
my $simple =(show('simple'));
-ok($simple =~ 'This is my content');
+ok($simple =~ 'This is my content', "show fucntion returned context ");
#diag ($simple);
ok_lint($simple);
}
{
Template::Declare->buffer->clear;
my $simple =Template::Declare->show('simple');
-ok($simple =~ 'This is my content');
+ok($simple =~ 'This is my content', "T::D->show returns a string");
#diag ($simple);
ok_lint($simple);
}
{
Template::Declare->buffer->clear;
Template::Declare->show('simple');
-ok(Template::Declare->buffer->data() =~ 'This is my content');
+ok(Template::Declare->buffer->data() =~ 'This is my content', "show simple filled the buffer");
#diag ($simple);
ok_lint(Template::Declare->buffer->data());
}
More information about the Jifty-commit
mailing list