blib/lib/Text/Nunjucks/Parser.pm

filter: Statementstmt 83.3% 20 / 24 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 4 totaltotal 72.5% 29 / 40 CC 3 SCAR 4.7
CC
3
Cov
79%
parse
2.5
parse
2.5
BEGIN
1.0
CRAP 1.6
« blib/lib/Text/Nunjucks/Nodes/NodeList.pm ↑ Summary blib/lib/Text/Nunjucks/Runtime/None.pm »
1 package Text::Nunjucks::Parser;
2 # ABSTRACT: 1:1 port of Nunjucks src/parser.js -- the recursive-descent parser
3  
4 19 our $VERSION = '0.001';
5  
6 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use Text::Nunjucks::Lexer;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use Text::Nunjucks::Parser::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # 1:1 port of upstream src/parser.js. parser.js holds one `class Parser extends
12 # Obj` and a `module.exports = { parse, Parser }`. This file mirrors that shape
13 # the way Lexer.pm mirrors lexer.js: the module-level exports live here on
14 # Text::Nunjucks::Parser (parse(), and parser_class() for the exported Parser
15 # class that jinja-compat reaches through `this.parser.Parser`), while the
16 # Parser class itself is the Moo class Text::Nunjucks::Parser::Parser in its own
17 # file (ADR 0002, ADR 0020) -- just as lexer's Tokenizer is
18 # Text::Nunjucks::Lexer::Tokenizer. Keeping them in separate packages resolves
19 # the one name clash parser.js has in a single Perl namespace: the instance
20 # method Parser.prototype.parse() and the module function
21 # module.exports.parse() are both named `parse`.
22 #
23 # lexer/nodes/lib are used through their real interfaces (lexer.TOKEN_X ->
24 # Text::Nunjucks::Lexer->TOKEN_X, new nodes.X -> $self->node('X')->new,
25 # lib.indexOf -> Text::Nunjucks::Lib->index_of), never re-derived. `throw new
26 # Error` becomes a thrown Text::Nunjucks::Lib::Error and `new lib.TemplateError`
27 # a Text::Nunjucks::Lib::TemplateError, the same mappings the lexer uses.
28  
29 #### module.exports.parse -- parse(src, extensions, opts)
30  
31 9618 ▶sub parse {
Subroutine parse: called CC=2 SCAR=9.2
Pod undocumented
32 0 ▶ my ( $self, $src, $extensions, $opts ) = @_;
Subroutine parse: not called CC=2 SCAR=9.2
Pod undocumented
33 0 my $p = $self->parser_class->new( $self->lexer->lex( $src, $opts ) );
34 # JS: if (extensions !== undefined) p.extensions = extensions;
35 0 ▶ $p->extensions($extensions) if defined $extensions;
Branch: 2 branches
BranchTrueFalseTotal
if defined $extensions 9453 165 9618
if defined $extensions 0 0 0
36 0 return $p->parse_as_root;
37 }
38  
39 # Collaborators named once, reached through the invocant (house rule).
40 9618 ▶sub lexer { 'Text::Nunjucks::Lexer' }
Subroutine lexer: called CC=1 SCAR=0.0
Pod undocumented
41 9618 ▶sub parser_class { 'Text::Nunjucks::Parser::Parser' }
Subroutine parser_class: called CC=1 SCAR=0.0
Pod undocumented
42  
43 19 1;
44  
45 __END__
« blib/lib/Text/Nunjucks/Nodes/NodeList.pm ↑ Summary blib/lib/Text/Nunjucks/Runtime/None.pm »