[Jifty-commit] r6248 - in Template-Declare/trunk: . lib/Template t
Jifty commits
jifty-commit at lists.jifty.org
Thu Jan 15 23:41:40 EST 2009
Author: alexmv
Date: Thu Jan 15 23:41:40 2009
New Revision: 6248
Modified:
Template-Declare/trunk/ (props changed)
Template-Declare/trunk/META.yml
Template-Declare/trunk/Makefile.PL
Template-Declare/trunk/lib/Template/Declare.pm
Template-Declare/trunk/lib/Template/Declare/Buffer.pm
Template-Declare/trunk/lib/Template/Declare/Tags.pm
Template-Declare/trunk/t/private.t
Template-Declare/trunk/t/subclassing.t
Log:
r41023 at kohr-ah: chmrr | 2009-01-15 23:41:33 -0500
Move to using String::BufferStack for interop with other templating languages
Modified: Template-Declare/trunk/META.yml
==============================================================================
--- Template-Declare/trunk/META.yml (original)
+++ Template-Declare/trunk/META.yml Thu Jan 15 23:41:40 2009
@@ -21,7 +21,8 @@
Class::Accessor::Fast: 0
Class::Data::Inheritable: 0
Class::ISA: 0
+ String::BufferStack: 1.1
perl: 5.8.2
resources:
license: http://dev.perl.org/licenses/
-version: 0.31_01
+version: 0.35
Modified: Template-Declare/trunk/Makefile.PL
==============================================================================
--- Template-Declare/trunk/Makefile.PL (original)
+++ Template-Declare/trunk/Makefile.PL Thu Jan 15 23:41:40 2009
@@ -13,5 +13,6 @@
requires 'Class::Accessor::Fast';
requires 'Class::Data::Inheritable';
requires 'Class::ISA';
+requires 'String::BufferStack' => 1.10;
WriteAll;
Modified: Template-Declare/trunk/lib/Template/Declare.pm
==============================================================================
--- Template-Declare/trunk/lib/Template/Declare.pm (original)
+++ Template-Declare/trunk/lib/Template/Declare.pm Thu Jan 15 23:41:40 2009
@@ -6,8 +6,9 @@
package Template::Declare;
use Template::Declare::Buffer;
use Class::ISA;
+use String::BufferStack;
-our $VERSION = "0.31_01";
+our $VERSION = "0.35";
use base 'Class::Data::Inheritable';
__PACKAGE__->mk_classdata('roots');
@@ -16,7 +17,7 @@
__PACKAGE__->mk_classdata('alias_metadata');
__PACKAGE__->mk_classdata('templates');
__PACKAGE__->mk_classdata('private_templates');
-__PACKAGE__->mk_classdata('buffer_stack');
+__PACKAGE__->mk_classdata('buffer');
__PACKAGE__->mk_classdata('imported_into');
__PACKAGE__->mk_classdata('around_template');
@@ -26,10 +27,10 @@
__PACKAGE__->alias_metadata( {} );
__PACKAGE__->templates( {} );
__PACKAGE__->private_templates( {} );
-__PACKAGE__->buffer_stack( [] );
+__PACKAGE__->buffer( String::BufferStack->new );
__PACKAGE__->around_template( undef );
-__PACKAGE__->new_buffer_frame();
+*String::BufferStack::data = \&String::BufferStack::buffer;
use vars qw/$TEMPLATE_VARS/;
@@ -351,20 +352,11 @@
}
sub new_buffer_frame {
- my $buffer = Template::Declare::Buffer->new();
- unshift @{ __PACKAGE__->buffer_stack }, $buffer;
-
+ __PACKAGE__->buffer->push( private => 1 );
}
sub end_buffer_frame {
- shift @{ __PACKAGE__->buffer_stack };
-}
-
-sub buffer {
- my $res = __PACKAGE__->buffer_stack->[0];
- Carp::confess( __PACKAGE__ . "->buffer called with no buffer" )
- unless $res;
- return $res;
+ __PACKAGE__->buffer->pop;
}
=head2 show TEMPLATE_NAME
Modified: Template-Declare/trunk/lib/Template/Declare/Buffer.pm
==============================================================================
--- Template-Declare/trunk/lib/Template/Declare/Buffer.pm (original)
+++ Template-Declare/trunk/lib/Template/Declare/Buffer.pm Thu Jan 15 23:41:40 2009
@@ -2,33 +2,21 @@
use strict;
package Template::Declare::Buffer;
-use base 'Class::Accessor::Fast';
-__PACKAGE__->mk_accessors('data');
-
-sub append {
- no warnings 'uninitialized';
- # stringify first as it can be overloaded object
- # that changes our buffer
- my $append = "$_[1]";
- $_[0]->data( $_[0]->data . $append );
-};
-
-sub clear {
- my $self = shift;
- $self->data('');
-};
+sub new {
+ die "Template::Declare::Buffer is deprecated!";
+}
1;
__END__
=head1 NAME
-Template::Declare::Buffer - manage output buffer
+Template::Declare::Buffer - deprecated
=head1 DESCRIPTION
-We use this class to manage the output buffer used by L<Template::Declare>.
+This class is deprecated; buffers in Template::Declare are now managed by L<String::BufferStack>.
=head1 SEE ALSO
Modified: Template-Declare/trunk/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/trunk/lib/Template/Declare/Tags.pm (original)
+++ Template-Declare/trunk/lib/Template/Declare/Tags.pm Thu Jan 15 23:41:40 2009
@@ -418,19 +418,12 @@
C<outs> HTML-encodes its arguments and appends them to C<Template::Declare>'s output buffer.
-
-=cut
-
-#sub outs { outs_raw( map { _postprocess($_); } grep {defined} @_ ); }
-
=head2 outs_raw STUFF
C<outs_raw> appends its arguments to C<Template::Declare>'s output buffer without doing any HTML escaping.
=cut
-#sub outs_raw { Template::Declare->buffer->append( join( '', grep {defined} @_ )); return ''; }
-
sub outs { _outs( 0, @_ ); }
sub outs_raw { _outs( 1, @_ ); }
@@ -438,11 +431,9 @@
my $raw = shift;
my @phrases = (@_);
- my $return_data = (defined wantarray and not wantarray)? 1 : 0;
- Template::Declare->new_buffer_frame if $return_data;
+ Template::Declare->buffer->push( private => (defined wantarray and not wantarray) );
foreach my $item ( grep {defined} @phrases ) {
-
my $returned = ref($item) eq 'CODE'
? $item->()
: $raw
@@ -450,8 +441,7 @@
: _postprocess($item);
Template::Declare->buffer->append( $returned );
}
- return '' unless $return_data;
- return Template::Declare->end_buffer_frame->data;
+ return Template::Declare->buffer->pop;
}
=head2 get_current_attr
@@ -592,9 +582,9 @@
sub smart_tag_wrapper (&) {
my $coderef = shift;
- my $buf = "\n";
- Template::Declare->new_buffer_frame;
+ Template::Declare->buffer->append("\n");
+ Template::Declare->buffer->push;
my %attr = %ATTRIBUTES;
%ATTRIBUTES = (); # prevent leakage
@@ -603,18 +593,9 @@
map { ref($_) ? $_ : _postprocess($_) } #
$coderef->(%attr);
-
- if ( length( Template::Declare->buffer->data ) ) {
-
- # We concatenate to force scalarization when $last or
- # $Template::Declare->buffer is solely a Jifty::Web::Link
- $buf .= Template::Declare->buffer->data;
- } elsif ( length $last ) {
- $buf .= $last;
- }
-
- Template::Declare->end_buffer_frame;
- Template::Declare->buffer->append($buf);
+ my $has_content = Template::Declare->buffer->length;
+ Template::Declare->buffer->pop;
+ Template::Declare->buffer->append( "$last" ) if not $has_content and length $last;
return '';
}
@@ -636,13 +617,15 @@
$tag = $tagset->namespace . ":$tag"
if defined $tagset->namespace;
- my $buf = "\n" . ( " " x $TAG_NEST_DEPTH ) . "<$tag"
- . join( '',
- map { qq{ $_="} . ( $ATTRIBUTES{$_} || '' ) . qq{"} }
- sort keys %ATTRIBUTES );
-
- my $had_content = 0;
+ Template::Declare->buffer->append(
+ "\n"
+ . ( " " x $TAG_NEST_DEPTH ) . "<$tag"
+ . join( '',
+ map { qq{ $_="} . ( $ATTRIBUTES{$_} || '' ) . qq{"} }
+ sort keys %ATTRIBUTES )
+ );
+ my $attrs = "";
{
no warnings qw( uninitialized redefine once );
@@ -665,42 +648,30 @@
my $field = shift;
my $val = shift;
- $buf .= ' ' . $field . q{="} . _postprocess($val, 1) . q{"};
+ $attrs .= ' ' . $field . q{="} . _postprocess($val, 1) . q{"};
wantarray ? () : '';
};
local $TAG_NEST_DEPTH = $TAG_NEST_DEPTH + 1;
%ATTRIBUTES = ();
- Template::Declare->new_buffer_frame;
+ Template::Declare->buffer->push( private => 1 );
my $last = join '', map { ref($_) && $_->isa('Template::Declare::Tag') ? $_ : _postprocess($_) } $code->();
-
- if ( length( Template::Declare->buffer->data ) ) {
-
-# We concatenate to force scalarization when $last or $Template::Declare->buffer is solely a Jifty::Web::Link
- $buf .= '>' . Template::Declare->buffer->data;
- $had_content = 1;
- } elsif ( length $last ) {
- $buf .= '>' . $last;
- $had_content = 1;
- } else {
- $had_content = 0;
- }
-
- Template::Declare->end_buffer_frame;
-
+ Template::Declare->buffer->append("$last") if not Template::Declare->buffer->length and length $last;
}
+ my $content = Template::Declare->buffer->pop;
+ Template::Declare->buffer->append($attrs);
- if ($had_content) {
- $buf .= "\n" . ( " " x $TAG_NEST_DEPTH ) if ( $buf =~ /\>$/ );
- $buf .= "</$tag>";
+ if (length $content) {
+ Template::Declare->buffer->append(">$content");
+ Template::Declare->buffer->append("\n" . ( " " x $TAG_NEST_DEPTH )) if $content =~ /\</;
+ Template::Declare->buffer->append("</$tag>");
} elsif ( $tagset->can_combine_empty_tags($tag) ) {
- $buf .= " />";
+ Template::Declare->buffer->append(" />");
} else {
# Otherwise we supply a closing tag.
- $buf .= "></$tag>";
+ Template::Declare->buffer->append("></$tag>");
}
- Template::Declare->buffer->append($buf);
return ( ref($more_code) && $more_code->isa('CODE') )
? $more_code->()
: '';
@@ -732,7 +703,7 @@
# if we're inside a template, we should show private templates
if ( caller->isa('Template::Declare') ) {
- _show_template( $template, 1, \@_ );
+ _show_template( $template, 1, \@_ );
return Template::Declare->buffer->data;
} else {
show_page( $template, @_);
@@ -740,21 +711,20 @@
}
-
-
sub show_page {
- my $template = shift;
+ my $template = shift;
my $args = \@_;
- my $return_data = defined wantarray();
-
- # if we're inside a template, we should show private templates
- Template::Declare->new_buffer_frame if $return_data;
- _show_template( $template, 0, $args );
- %ELEMENT_ID_CACHE = (); # We're done. we can clear the cache
- return undef unless $return_data;
-
- return Template::Declare->end_buffer_frame->data;
+ if (defined wantarray) {
+ Template::Declare->buffer->push( private => 1 );
+ _show_template( $template, 0, $args );
+ %ELEMENT_ID_CACHE = ();
+ return Template::Declare->buffer->pop;
+ } else {
+ _show_template( $template, 0, $args );
+ %ELEMENT_ID_CACHE = ();
+ return undef;
+ }
}
sub _resolve_template_path {
@@ -796,9 +766,8 @@
my $template = shift;
my $inside_template = shift;
my $args = shift;
- local @TEMPLATE_STACK = @TEMPLATE_STACK;
$template = _resolve_template_path($template);
- push @TEMPLATE_STACK, $template;
+ local @TEMPLATE_STACK = (@TEMPLATE_STACK, $template);
my $callable =
( ref($template) && $template->isa('Template::Declare::Tag') )
@@ -940,11 +909,10 @@
my $self = shift;
if ( defined wantarray ) {
- Template::Declare->new_buffer_frame;
+ Template::Declare->buffer->push( private => 1 );
my $returned = $self->();
- return (Template::Declare->end_buffer_frame->data . $returned);
+ return Template::Declare->buffer->pop . $returned;
} else {
-
return $self->();
}
}
Modified: Template-Declare/trunk/t/private.t
==============================================================================
--- Template-Declare/trunk/t/private.t (original)
+++ Template-Declare/trunk/t/private.t Thu Jan 15 23:41:40 2009
@@ -84,7 +84,7 @@
{ $simple = ( Template::Declare->show('private-content') ); }
qr/could not be found.*private/,
"got warning";
- is($simple, undef);
+ is($simple, '');
}
Modified: Template-Declare/trunk/t/subclassing.t
==============================================================================
--- Template-Declare/trunk/t/subclassing.t (original)
+++ Template-Declare/trunk/t/subclassing.t Thu Jan 15 23:41:40 2009
@@ -78,8 +78,8 @@
{ $simple = ( show('does_not_exist') ); }
qr/could not be found.*private/,
"got warning";
- unlike( ($simple||'') , qr'This is my content' );
- is ($simple,undef);
+ unlike( $simple , qr'This is my content' );
+ is ($simple,'');
}
{
More information about the Jifty-commit
mailing list