File Coverage

blib/lib/Erlang/Parser/Node/Receive.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::Receive;
6              
7 3     3   14 use Moose;
  3         3  
  3         15  
8             with 'Erlang::Parser::Node';
9              
10             has 'alts' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node::Alt]');
11             has 'aft' => (is => 'rw', required => 0, isa => 'Maybe[Erlang::Parser::Node::ReceiveAfter]');
12              
13             sub print {
14 8     8 1 16 my ($self, $fh, $depth) = @_;
15 8   50     21 $depth ||= 0;
16              
17 8         15 print $fh "receive\n";
18              
19 8         11 $depth++;
20              
21 8         17 print $fh "\t" x $depth;
22              
23 8         16 my $first = 1;
24 8         16 foreach (@{$self->alts}) {
  8         209  
25 30 100       47 if ($first) { $first = 0 } else { print $fh ";\n", "\t" x $depth }
  8         13  
  22         42  
26 30         85 $_->print($fh ,$depth);
27             }
28              
29 8         14 $depth--;
30 8         19 print $fh "\n", "\t" x $depth;
31            
32 8 100       216 $self->aft->print($fh, $depth) if defined $self->aft;
33            
34 8         41 print $fh "\n", "\t" x $depth, "end";
35             }
36              
37             __PACKAGE__->meta->make_immutable;
38              
39             =head1 NAME
40              
41             Erlang::Parser::Node::Receive - a receive statement
42              
43             =head1 DESCRIPTION
44              
45             Receives a message from the mailbox which matches any pattern (and guard);
46             optionally with a timeout.
47              
48             =head2 Accessors
49              
50             =over 4
51              
52             =item C<alts>
53              
54             A list of L<Erlang::Parser::Node::Alt>s which are matched against the process
55             mailbox.
56              
57             =item C<aft>
58              
59             An optional L<Erlang::Parser::Node::ReceiveAfter>.
60              
61             =back
62              
63             =head2 Methods
64              
65             =over 4
66              
67             =item C<print>
68              
69             Pretty-prints the node to its filehandle argument.
70              
71             =back
72              
73             =head1 EXAMPLE
74              
75             receive
76             {X, Y} when is_bool(X) ->
77             X;
78             {X, Y, Z} ->
79             Y + Z;
80             _ ->
81             io:format("wth~n", [])
82             after
83             10000 ->
84             {error, timeout}
85             end
86              
87             =cut
88              
89             1;
90              
91             # vim: set sw=4 ts=4: