blib/lib/Text/Nunjucks/Context/Gone.pm

filter: Statementstmt 85.1% 23 / 27 Branchbran 25.0% 1 / 4 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 3 totaltotal 77.0% 37 / 48 CC 4 SCAR 5.0
CC
4
Cov
79%
AUTOLOAD
2.8
AUTOLOAD
2.8
instance
2.0
CRAP 1.7
« blib/lib/Text/Nunjucks/Runtime/SafeString.pm ↑ Summary blib/lib/Text/Nunjucks/Nodes/NodeList.pm »
1 package Text::Nunjucks::Context::Gone;
2 # ABSTRACT: Stands in for the Context of a render that is over (ADR 0021)
3  
4 15 our $VERSION = '0.001';
5  
6 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Text::Nunjucks::Lib::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # A port addition with no upstream counterpart (ADR 0021). No compiled sub
11 # keeps the Context of its render alive (Runtime _render_scope); when a
12 # Context is freed, it leaves this object in every `$context` variable the
13 # code of its render can still see (Context DEMOLISH). Code that runs after
14 # that -- a macro the application kept, a continuation that is called a second
15 # time -- and reads nothing outside itself works as before: it calls no method
16 # here, or only one of the writes below. The first read -- a lookup, an
17 # include or import, a block call -- dies here with an error that says what
18 # happened, instead of Perl's "Can't call method ... on an undefined value".
19 #
20 # One process-wide object without state, like Text::Nunjucks::Runtime::None.
21  
22 15 my $INSTANCE;
23 778 ▶sub instance { $INSTANCE //= bless \( my $x ), __PACKAGE__ }
Subroutine instance: called CC=2 SCAR=6.9
Pod undocumented
Condition100%2/2
$INSTANCE //= bless(\my $x, __PACKAGE__)
l!l
7726
MC/DC100%1/1
$INSTANCE //= bless(\my $x, __PACKAGE__)
$INSTANCE
Truth table100%2/2
A
A= $INSTANCE
Aresult
11
00
24  
25 4 ▶sub _error_class { 'Text::Nunjucks::Lib::Error' }
Subroutine _error_class: called CC=1 SCAR=0.0
26  
27 # The Context methods that only write. The compiled code reports each macro,
28 # call block and extension body it makes (Context _made_closure), and a macro
29 # defined inside a macro body is written into the Context, as upstream's
30 # compileMacro does (`context.addExport` and `context.setVariable`: the body's
31 # frame has no parent). A write into a Context that is gone is one nobody can
32 # read: everything that reads a Context -- lookup, get_variables,
33 # get_exported, get_block, get_super -- goes through the object, and dies
34 # below. So a kept macro that defines a nested macro and reads nothing outside
35 # itself works, as it does upstream.
36 #
37 # _keep_alive is the same kind of write: a kept macro whose body imports a
38 # library asks the Context to keep the library's (Context _keep_alive). The
39 # library's Context is held by the Template _get_exported call for as long as
40 # the rest of the macro body runs inside that call, so the macro renders as it
41 # does upstream; a macro of the library that runs later than that -- after an
42 # async filter deferred -- finds the library's Context gone and dies at its
43 # first read.
44 5 ▶sub _made_closure { return }
Subroutine _made_closure: called CC=1 SCAR=0.0
45 5 ▶sub add_export { return }
Subroutine add_export: called CC=1 SCAR=0.0
Pod undocumented
46 12 ▶sub set_variable { return }
Subroutine set_variable: called CC=1 SCAR=0.0
Pod undocumented
47 7 ▶sub _keep_alive { return }
Subroutine _keep_alive: called CC=1 SCAR=0.0
48  
49 15 our $AUTOLOAD;
50  
51 4 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=2 SCAR=10.3
52 0 ▶ my ($self) = @_;
Subroutine AUTOLOAD: not called CC=2 SCAR=10.3
53 0 my $method = $AUTOLOAD =~ s/.*:://r;
54 0 ▶ return if $method eq 'DESTROY';
Branch: 2 branches
BranchTrueFalseTotal
if $method eq "DESTROY" 0 4 4
if $method eq "DESTROY" 0 0 0
55 0 die $self->_error_class->new(
56 'template code ran after its render had ended: its Context is gone (' . $method . ')' );
57 }
58  
59 15 1;
60  
61 __END__
« blib/lib/Text/Nunjucks/Runtime/SafeString.pm ↑ Summary blib/lib/Text/Nunjucks/Nodes/NodeList.pm »