File Coverage

blib/lib/Erlang/Parser/Node/If.pm
Criterion Covered Total %
statement 17 17 100.0
branch 2 2 100.0
condition 1 2 50.0
subroutine 2 2 100.0
pod 1 1 100.0
total 23 24 95.8


line stmt bran cond sub pod time code
1             # Copyright 2011-2012 Yuki Izumi. ( anneli AT cpan DOT org )
2             # This is free software; you can redistribute it and/or modify it under the
3             # same terms as Perl itself.
4              
5             package Erlang::Parser::Node::If;
6              
7 3     3   11 use Moose;
  3         5  
  3         16  
8             with 'Erlang::Parser::Node';
9              
10             has 'cases' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node::IfExpr]');
11              
12             sub print {
13 4     4 1 12 my ($self, $fh, $depth) = @_;
14 4   50     11 $depth ||= 0;
15              
16 4         8 print $fh "if\n";
17              
18 4         4 $depth++;
19 4         10 print $fh "\t" x $depth;
20 4         5 my $first = 1;
21 4         7 foreach (@{$self->cases}) {
  4         99  
22 8 100       16 if ($first) { $first = 0 } else { print $fh ";\n", "\t" x $depth }
  4         8  
  4         9  
23 8         30 $_->print($fh, $depth);
24             }
25              
26 4         6 $depth--;
27 4         19 print $fh "\n", "\t" x $depth, "end";
28             }
29              
30             __PACKAGE__->meta->make_immutable;
31              
32             =head1 NAME
33              
34             Erlang::Parser::Node::If - an 'if' statement
35              
36             =head1 DESCRIPTION
37              
38             A list of guards and statement blocks to execute if one is true.
39              
40             =head2 Accessors
41              
42             =over 4
43              
44             =item C<cases>
45              
46             A list of L<Erlang::Parser::Node::IfExpr>s.
47              
48             =back
49              
50             =head2 Methods
51              
52             =over 4
53              
54             =item C<print>
55              
56             Pretty-prints the node to its filehandle argument.
57              
58             =back
59              
60             =head1 EXAMPLE
61              
62             if
63             X>Y ->
64             true;
65             true ->
66             false
67             end
68              
69             =cut
70              
71             1;
72              
73             # vim: set sw=4 ts=4: