| 1 | package Text::Nunjucks::Nodes::Node; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Base class of every AST node (nodes.js class Node) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 20 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # upstream: class Node extends Obj. Every node answers ->typename (the oracle | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # AST type string), ->fields (arrayref of field names in nodes.js order), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # ->lineno, ->colno and one accessor per field. That is exactly the shape | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # t/corpus.t's ast_dump reads. A subclass sets its own typename (upstream sets | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # it fresh on every extend, it is never inherited) and overrides fields only | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # where the list changes; inherited fields keep their accessors through normal | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # inheritance, the way JS prototype chaining carries them. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 20 | has lineno => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 20 | has colno => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | sub typename { 'Node' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
typename: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | sub fields { [] } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Node construction is positional -- new nodes.Symbol(lineno, colno, value) -- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # so BUILDARGS turns the positional call into the hash Moo's constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # wants. The first two args are line/col; the rest map onto the fields in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # declared order. A field that was not passed stays undef, which encodes to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # JSON null: upstream's init does the same ("Fields should never be | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # undefined, but null. It makes testing easier to normalize values."). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 125374 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my ( $class, @args ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: not called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | return $class->_field_args(@args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 203226 | ▶ | sub _field_args { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_field_args: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my ( $class, $lineno, $colno, @vals ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_field_args: not called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $fields = $class->fields; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my %args = ( lineno => $lineno, colno => $colno ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | for my $i ( 0 .. $#$fields ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $args{ $fields->[$i] } = $vals[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | return \%args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # Named once so a subclass can redirect sibling-node construction (house | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # rule: reach for collaborators through the invocant, not a hardcoded name). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 171486 | ▶ | sub _node_class { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_node_class: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my ( $self, $name ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_node_class: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return 'Text::Nunjucks::Nodes::' . $name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 171470 | ▶ | sub find_all { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_all: called CC=5 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | my ( $self, $type, $results ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_all: not called CC=5 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $results ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$results ||= []
$results ||= []
MC/DC100%1/1
$results ||= []
$results
MC/DC0%0/1
$results ||= []
$results
Truth table100%2/2
A
A= $results
Truth table0%0/2
A
A= $results
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ( $self->isa( $self->_node_class('NodeList') ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | _traverse_and_check( $_, $type, $results ) for @{ $self->children }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | _traverse_and_check( $self->$_, $type, $results ) for @{ $self->fields }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | return $results; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 467 | ▶ | sub iter_fields { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iter_fields: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my ( $self, $func ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iter_fields: not called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $func->( $self->$_, $_ ) for @{ $self->fields }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # upstream module-level function traverseAndCheck; kept next to find_all, its | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # only caller, since the two are mutually recursive. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 248715 | ▶ | sub _traverse_and_check { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_traverse_and_check: called CC=5 SCAR=21.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my ( $obj, $type, $results ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_traverse_and_check: not called CC=5 SCAR=21.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | push @$results, $obj if blessed($obj) && $obj->isa($type); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
builtin::blessed($obj) and $obj->isa($type)
builtin::blessed($obj) and $obj->isa($type)
MC/DC100%2/2
builtin::blessed($obj) and $obj->isa($type)
builtin::blessed($obj)
$obj->isa($type)
MC/DC0%0/2
builtin::blessed($obj) and $obj->isa($type)
builtin::blessed($obj)
$obj->isa($type)
Truth table100%3/3
A and B
A= builtin::blessed($obj)B= $obj->isa($type)
Truth table0%0/3
A and B
A= builtin::blessed($obj)B= $obj->isa($type)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $obj->find_all( $type, $results ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
builtin::blessed($obj) and $obj->isa("Text::Nunjucks::Nodes::Node")
builtin::blessed($obj) and $obj->isa("Text::Nunjucks::Nodes::Node")
MC/DC50%1/2
builtin::blessed($obj) and $obj->isa("Text::Nunjucks::Nodes::Node")
builtin::blessed($obj)
$obj->isa("Text::Nunjucks::Nodes::Node")
MC/DC0%0/2
builtin::blessed($obj) and $obj->isa("Text::Nunjucks::Nodes::Node")
builtin::blessed($obj)
$obj->isa("Text::Nunjucks::Nodes::Node")
Truth table66%2/3
A and B
A= builtin::blessed($obj)B= $obj->isa("Text::Nunjucks::Nodes::Node")
Truth table0%0/3
A and B
A= builtin::blessed($obj)B= $obj->isa("Text::Nunjucks::Nodes::Node")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | if blessed($obj) && $obj->isa('Text::Nunjucks::Nodes::Node'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||