File Coverage

blib/lib/Erlang/Parser/Node/WhenList.pm
Criterion Covered Total %
statement 31 31 100.0
branch 8 8 100.0
condition 1 2 50.0
subroutine 4 4 100.0
pod 1 1 100.0
total 45 46 97.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::WhenList;
6              
7 3     3   11 use Moose;
  3         4  
  3         18  
8             with 'Erlang::Parser::Node';
9              
10             has 'groups' => (is => 'rw', default => sub {[]}, isa => 'ArrayRef[ArrayRef[Erlang::Parser::Node]]');
11             has 'exprs' => (is => 'rw', default => sub {[]}, isa => 'ArrayRef[Erlang::Parser::Node]');
12              
13             sub _append {
14 766     766   910 my ($self, $expr) = @_;
15 766         717 push @{$self->exprs}, $expr;
  766         19520  
16 766         1278 $self;
17             }
18              
19             sub _group () {
20 4912     4912   5466 my $self = shift;
21 4912 100       3893 push @{$self->groups}, $self->exprs if @{$self->exprs};
  598         14757  
  4912         133755  
22 4912         116066 $self->exprs([]);
23 4912         13067 $self;
24             }
25              
26             sub print {
27 4870     4870 1 5091 my ($self, $fh, $depth) = @_;
28 4870   50     7483 $depth ||= 0;
29              
30 4870 100       3360 if (@{$self->groups}) {
  4870         115499  
31 556         761 print $fh 'when ';
32 556         521 my $first = 1;
33 556         501 foreach (@{$self->groups}) {
  556         13442  
34 598 100       848 if ($first) { $first = 0 } else { print $fh '; ' }
  556         558  
  42         61  
35              
36 598         631 my $infirst = 1;
37 598         948 foreach (@$_) {
38 766 100       922 if ($infirst) { $infirst = 0 } else { print $fh ', ' }
  598         536  
  168         161  
39 766         1801 $_->print($fh, $depth);
40             }
41             }
42 556         1128 print $fh ' ';
43             }
44             }
45              
46             __PACKAGE__->meta->make_immutable;
47              
48             =head1 NAME
49              
50             Erlang::Parser::Node::WhenList - a guard sequence
51              
52             =head1 DESCRIPTION
53              
54             Used to restrict the circumstances under which a pattern match will match;
55             comprised of guards separated by semi-colons, each which is comprised of
56             several guard expressions separated by commas. The guard sequence as a whole
57             passes if all guard expressions in any guard pass.
58              
59             =head2 Accessors
60              
61             =over 4
62              
63             =item C<groups>
64              
65             A list of a list of L<Erlang::Parser::Node>s; each individual list of nodes is
66             a guard (and each node a guard expression).
67              
68             =item C<exprs>
69              
70             Used only during construction of the guard sequence; should be empty after
71             parsing is complete.
72              
73             =back
74              
75             =head2 Methods
76              
77             =over 4
78              
79             =item C<print>
80              
81             Pretty-prints the node to its filehandle argument.
82              
83             =back
84              
85             =head1 EXAMPLE
86              
87             when is_bool(X), is_bool(Y); X < Y
88              
89             =cut
90              
91             1;
92              
93             # vim: set sw=4 ts=4: