File Coverage

blib/lib/Mason/Plugin/Defer/Request.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 31 31 100.0


line stmt bran cond sub pod time code
1             package Mason::Plugin::Defer::Request;
2             $Mason::Plugin::Defer::Request::VERSION = '2.24';
3 20     20   13289 use Mason::PluginRole;
  20         59  
  20         166  
4              
5             has 'defers' => ( is => 'rw', init_arg => undef, default => sub { [] } );
6              
7             before 'flush_buffer' => sub {
8             my $self = shift;
9             $self->_apply_defers_to_request_buffer();
10             };
11              
12 20     20   103604 method defer ($code) {
  2     2   3  
  2         3  
  2         3  
13 2         43 my $marker = $self->interp->_construct_distinct_string();
14 2         3 push( @{ $self->{defers} }, { marker => $marker, code => $code } );
  2         11  
15 2         8 return $marker;
16             }
17              
18 20     20   7345 method _apply_defers_to_request_buffer () {
  127     127   208  
  127         181  
19 127 100       226 if ( my @defers = @{ $self->{defers} } ) {
  127         745  
20 1         2 my $request_buffer = ${ $self->_request_buffer };
  1         7  
21 1         3 foreach my $defer (@defers) {
22 2         4 my $subst = $defer->{marker};
23 2         5 my $repl = $defer->{code}->();
24 2         42 $request_buffer =~ s/\Q$subst\E/$repl/;
25             }
26 1         2 ${ $self->_request_buffer } = $request_buffer;
  1         4  
27             }
28             }
29              
30             1;