1package Template::Alloy::Stream; 2 3=head1 NAME 4 5Template::Alloy::Stream - Stream role - allows for playing out the AST and printing straight to file handle 6 7=cut 8 9use strict; 10use warnings; 11use Template::Alloy; 12use Template::Alloy::Play; 13 14our $VERSION = $Template::Alloy::VERSION; 15 16sub new { die "This class is a role for use by packages such as Template::Alloy" } 17 18###----------------------------------------------------------------### 19 20sub stream_tree { 21 my ($self, $tree) = @_; 22 23 local $Template::Alloy::Play::DIRECTIVES->{'CLEAR'} = \&stream_CLEAR; 24 25 # node contains (0: DIRECTIVE, 26 # 1: start_index, 27 # 2: end_index, 28 # 3: parsed tag details, 29 # 4: sub tree for block types 30 # 5: continuation sub trees for sub continuation block types (elsif, else, etc) 31 # 6: flag to capture next directive 32 for my $node (@$tree) { 33 ### text nodes are just the bare text 34 if (! ref $node) { 35 print $node if defined $node; 36 next; 37 } 38 39 print $self->debug_node($node) if $self->{'_debug_dirs'} && ! $self->{'_debug_off'}; 40 41 my $out = ''; 42 $Template::Alloy::Play::DIRECTIVES->{$node->[0]}->($self, $node->[3], $node, \$out); 43 print $out; 44 } 45} 46 47sub stream_CLEAR { 48 my ($self, $undef, $node) = @_; 49 $self->throw('stream', 'Cannot use CLEAR directive when STREAM is being used', $node); 50} 51 52###----------------------------------------------------------------### 53 541; 55 56__END__ 57 58=head1 DESCRIPTION 59 60The Template::Alloy::Stream role works similar to the PLAY role, but instead 61of accumulating the data, it prints it as soon as it is available. 62 63All directives are supported except for the CLEAR directive which is meaningless. 64 65Most configuration items are supported - except for the TRIM directive which cannot 66be used because the output is not buffered into a variable that can be trimmed. 67 68The WRAPPER directive is still supported - but it essentially turns off STREAM as 69the content must be generated before playing the WRAPPER templates. 70 71=head1 ROLE METHODS 72 73=over 4 74 75=item C<stream_tree> 76 77Similar to play_tree from the Play role, but prints output to the screen 78as soon as it is ready. 79 80=back 81 82=head1 AUTHOR 83 84Paul Seamons <paul@seamons.com> 85 86=head1 LICENSE 87 88This module may be distributed under the same terms as Perl itself. 89 90=cut 91