Jmespath/GraphvizVisitor.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 45 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
visit
2.0
_visit
2.0
CRAP 2.0
1 package Jmespath::GraphvizVisitor;
2 use parent 'Jmespath::Visitor';
3 use strict;
4 use warnings;
5  
6 sub new {
7 my ($class) = @_;
8 my $self = $class->SUPER::new( $expected, $actual, $name );
9 @{$self->{_lines}} = [];
10 $self->{_count} = 1;
11 return $self;
12 }
13  
14 sub visit {
15 my $self = shift; my $node = shift; my $args = @_;
16 push 'digraph AST {' ,@{$self->{_lines}};
17 my $current = $node->{type} . $self->{_count};
18 $self->{_count} += 1;
19 $self->_visit($node, $current);
20 push '}', @{$self->{_lines}};
21 }
22  
23 # recursive function to iterate through all child nodes to produce
24 # relationship graph lines
25 sub _visit {
26 my ($self, $node, $current) = @_;
27 my $line = $current . ' [label="' . $node->{type} . '(' . $node->{value} . ')"]';
28 push $line, @{$self->{_lines}};
29 foreach my $child (@{$node->{children}}) {
30 my $child_name = $child->{type} . $self->{_count};
31 $self->{_count} += 1;
32 push ' ' . $current . ' -> ' $child_name, @{$self->{_lines}};
33 $self->_visit($child, $child_name);
34 }
35 }
36  
37 1;