File Coverage

lib/Async/Template/Document.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 4 50.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 0 2 0.0
total 33 39 84.6


line stmt bran cond sub pod time code
1             package Async::Template::Document;
2              
3             #! @file
4             #! @author: Serguei Okladnikov
5             #! @date 23.05.2013
6              
7             #! This source file have functions `process_enter()` and `process_leave()`.
8             #! Code parts of them taken from function `process()` of template toolkit
9             #! library and substantially enhanced, the asynchronous processing
10             #! is introduced by Serguei Okladnikov
11             #! Author of that original code parts is Andy Wardley
12              
13              
14 3     3   20 use strict;
  3         6  
  3         90  
15 3     3   24 use warnings;
  3         6  
  3         82  
16 3     3   13 use base 'Template::Document';
  3         5  
  3         201  
17 3     3   17 use Template::Constants;
  3         5  
  3         712  
18              
19              
20             #------------------------------------------------------------------------
21             # process($context)
22             #
23             # Process the document in a particular context. Checks for recursion,
24             # registers the document with the context via visit(), processes itself,
25             # and then unwinds with a large gin and tonic.
26             #------------------------------------------------------------------------
27              
28             sub process_enter {
29 11     11 0 27 my ($self, $context) = @_;
30 11         22 my $defblocks = $self->{ _DEFBLOCKS };
31              
32             # check we're not already visiting this template
33             return $context->throw(Template::Constants::ERROR_FILE,
34             "recursion into '$self->{ name }'")
35 11 50 33     28 if $self->{ _HOT } && ! $context->{ RECURSION }; ## RETURN ##
36              
37 11         37 $context->visit($self, $defblocks);
38              
39 11         82 $self->{ _HOT } = 1;
40 11         15 eval {
41 11         16 my $block = $self->{ _BLOCK };
42 11         311 &$block($context);
43             };
44             }
45              
46             sub process_leave {
47 10     10 0 19 my ($self, $context) = @_;
48              
49 10         16 $self->{ _HOT } = 0;
50              
51 10         25 $context->leave();
52              
53 10 50       80 die $context->catch($@)
54             if $@;
55            
56             }
57              
58              
59             1;