File Coverage

blib/lib/Language/MinCaml/Node.pm
Criterion Covered Total %
statement 19 20 95.0
branch 2 2 100.0
condition 2 2 100.0
subroutine 5 6 83.3
pod 1 2 50.0
total 29 32 90.6


line stmt bran cond sub pod time code
1             package Language::MinCaml::Node;
2 6     6   2059 use strict;
  6         13  
  6         256  
3 6     6   36 use base qw(Class::Accessor::Fast Exporter);
  6         12  
  6         2970  
4              
5             __PACKAGE__->mk_accessors(qw(kind children));
6              
7             our @EXPORT = qw(Node_Unit Node_Bool Node_Int Node_Float Node_Tuple
8             Node_Array Node_Var Node_Not Node_Neg Node_Add Node_Sub
9             Node_FNeg Node_FAdd Node_FSub Node_FMul Node_FDiv
10             Node_Eq Node_LE Node_If Node_Let Node_LetRec Node_App
11             Node_LetTuple Node_Get Node_Put);
12              
13             for my $routine_name (@EXPORT){
14             my $kind = $routine_name;
15             $kind =~ s/^Node_//;
16 0     0   0 my $routine = sub { __PACKAGE__->new($kind, @_); };
17 6     6   6856 no strict 'refs';
  6         13  
  6         1421  
18             *{$routine_name} = $routine;
19             }
20              
21             sub new {
22 5     5 1 41 my($class, $kind, @children) = @_;
23 5         30 return bless { kind => $kind, children => \@children }, $class;
24             }
25              
26             sub to_str {
27 4     4 0 20 my($self, $depth) = @_;
28 4   100     15 $depth ||= 0;
29 4         12 my $content = "\t" x $depth . "$self->{kind}\n";
30              
31 4         5 for my $child (@{$self->{children}}) {
  4         9  
32 6 100       17 if (ref($child) eq __PACKAGE__) {
33 1         5 $content .= $child->to_str($depth + 1);
34             }
35             }
36              
37 4         20 $content;
38             }
39              
40             1;