| 1 | package Farly::ASA::Generator; | ||||||||||
| 2 | |||||||||||
| 3 | 9 | ▶ | use 5.008008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 9 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 9 | ▶ | use Scalar::Util qw(blessed); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 9 | ▶ | use Log::Any qw($log); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 9 | our $VERSION = '0.26'; | |||||||||
| 11 | |||||||||||
| 12 | 6 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 13 | 6 | my ($class) = @_; | |||||||||
| 14 | |||||||||||
| 15 | 6 | my $self = { | |||||||||
| 16 | CONTAINER => Farly::Object::List->new(), # result | ||||||||||
| 17 | }; | ||||||||||
| 18 | 6 | bless $self, $class; | |||||||||
| 19 | |||||||||||
| 20 | 6 | $log->info("$self new"); | |||||||||
| 21 | 6 | $log->info( "$self CONTAINER is " . $self->container() ); | |||||||||
| 22 | |||||||||||
| 23 | 6 | return $self; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 338 | ▶ | sub container { | ||||||||
|
Subroutine
container: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 27 | 338 | return $_[0]->{CONTAINER}; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 326 | ▶ | sub visit { | ||||||||
|
Subroutine
visit: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 31 | 326 | my ( $self, $node ) = @_; | |||||||||
| 32 | # $node isa reference to the root of the AST | ||||||||||
| 33 | |||||||||||
| 34 | # the Farly translator parses one firewall object at a time | ||||||||||
| 35 | 326 | my $object = Farly::Object->new(); | |||||||||
| 36 | |||||||||||
| 37 | # the AST root node is the 'ENTRY' | ||||||||||
| 38 | 326 | $object->set( 'ENTRY', Farly::Value::String->new( ref($node) ) ); | |||||||||
| 39 | |||||||||||
| 40 | 326 | $log->debug( "ENTRY = " . ref($node) ); | |||||||||
| 41 | |||||||||||
| 42 | # set s of explored vertices | ||||||||||
| 43 | 326 | my %seen; | |||||||||
| 44 | |||||||||||
| 45 | #stack is all neighbors of s | ||||||||||
| 46 | my @stack; | ||||||||||
| 47 | 326 | push @stack, $node; | |||||||||
| 48 | |||||||||||
| 49 | 326 | my $key; | |||||||||
| 50 | |||||||||||
| 51 | 326 | ▶ | while (@stack) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | 1980 | my $node = pop @stack; | |||||||||
| 54 | |||||||||||
| 55 | 1980 | ▶ | next if ( $seen{$node}++ ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | |||||||||||
| 57 | 1980 | $log->debug( "ast node class = " . ref($node) ); | |||||||||
| 58 | |||||||||||
| 59 | # continue exploring the AST | ||||||||||
| 60 | 1980 | foreach my $key ( keys %$node ) { | |||||||||
| 61 | |||||||||||
| 62 | 3298 | my $next = $node->{$key}; | |||||||||
| 63 | |||||||||||
| 64 | 3298 | ▶ | if ( $key eq '__VALUE__' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | |||||||||||
| 66 | #then $next isa token | ||||||||||
| 67 | 1644 | $object->set( ref($node), $next ); | |||||||||
| 68 | 1644 | $log->debug( "set " . ref($node) . " = " . ref($next). " " . $next->as_string ); | |||||||||
| 69 | } | ||||||||||
| 70 | else { | ||||||||||
| 71 | 1654 | push @stack, $next; | |||||||||
| 72 | } | ||||||||||
| 73 | } | ||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 326 | $self->container->add($object); | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 9 | 1; | |||||||||
| 80 | __END__ | ||||||||||