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   12 use Moose;
  3         4  
  3         20  
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 1412 my ($self, $fh, $depth) = @_;
18 1366   50     2190 $depth ||= 0;
19              
20 1366 100       31568 print $fh $self->class, ':' if defined($self->class);
21 1366         30250 $self->expr->print($fh, $depth);
22 1366         1322 $depth++;
23 1366         1450 print $fh ' ';
24              
25 1366         30895 $self->whens->print($fh, $depth);
26            
27 1366         2523 print $fh "->\n", "\t" x $depth;
28              
29 1366         1071 my $first = 1;
30 1366         1241 foreach (@{$self->stmts}) {
  1366         31294  
31 1702 100       2505 if ($first) { $first = 0 } else { print $fh ",\n", "\t" x $depth }
  1366         1327  
  336         545  
32 1702         4253 $_->print($fh, $depth);
33             }
34              
35 1366         3070 $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: