File Coverage

blib/lib/Erlang/Parser/Node/Alt.pm
Criterion Covered Total %
statement 19 19 100.0
branch 4 4 100.0
condition 1 2 50.0
subroutine 2 2 100.0
pod 1 1 100.0
total 27 28 96.4


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::Alt;
6              
7 3     3   10 use Moose;
  3         3  
  3         14  
8             with 'Erlang::Parser::Node';
9              
10             has 'catch' => (is => 'rw', required => 0, isa => 'Bool');
11             has 'class' => (is => 'rw', required => 0, isa => 'Maybe[Str]');
12             has 'expr' => (is => 'rw', required => 1, isa => 'Erlang::Parser::Node');
13             has 'whens' => (is => 'rw', required => 1, isa => 'Erlang::Parser::Node::WhenList');
14             has 'stmts' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node]');
15              
16             sub print {
17 1366     1366 1 1426 my ($self, $fh, $depth) = @_;
18 1366   50     2201 $depth ||= 0;
19              
20 1366 100       34142 print $fh $self->class, ':' if defined($self->class);
21 1366         31860 $self->expr->print($fh, $depth);
22 1366         1618 $depth++;
23 1366         1439 print $fh ' ';
24              
25 1366         32909 $self->whens->print($fh, $depth);
26            
27 1366         2485 print $fh "->\n", "\t" x $depth;
28              
29 1366         1334 my $first = 1;
30 1366         1108 foreach (@{$self->stmts}) {
  1366         32810  
31 1702 100       2448 if ($first) { $first = 0 } else { print $fh ",\n", "\t" x $depth }
  1366         1238  
  336         888  
32 1702         4634 $_->print($fh, $depth);
33             }
34              
35 1366         3030 $depth--;
36             }
37              
38             __PACKAGE__->meta->make_immutable;
39              
40             =head1 NAME
41              
42             Erlang::Parser::Node::Alt - an alternative in a case or try
43              
44             =head1 DESCRIPTION
45              
46             One alternative (the catch class (if any), pattern match, guards (if any) and
47             expressions) in a case or try statement.
48              
49             =head2 Accessors
50              
51             =over 4
52              
53             =item C<catch>
54              
55             True if this is a case in a catch clause. If so, it will also possess the
56             C<class> attribute.
57              
58             =item C<class>
59              
60             The class in the pattern match; the 'Z' in try X catch Y:Z -> ... end.
61              
62             =item C<expr>
63              
64             The L<Erlang::Parser::Node> pattern match expression.
65              
66             =item C<whens>
67              
68             A L<Erlang::Parser::Node::WhenList> of guard sequences/expressions, if any.
69              
70             =item C<stmts>
71              
72             A list of L<Erlang::Parser::Node>s; the body executed for this alternative.
73              
74             =back
75              
76             =head2 Methods
77              
78             =over 4
79              
80             =item C<print>
81              
82             Pretty-prints the node to its filehandle argument.
83              
84             =back
85              
86             =head1 EXAMPLE
87              
88             {X, Y} when is_bool(X) ->
89             Z = Y + Y,
90             Z * 2
91              
92             =cut
93              
94             1;
95              
96             # vim: set sw=4 ts=4: