| 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 | 4 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 4 | with 'Erlang::Parser::Node'; | |||||||||||
| 9 | |||||||||||||
| 10 | 4870 | ▶ | has 'groups' => (is => 'rw', default => sub {[]}, isa => 'ArrayRef[ArrayRef[Erlang::Parser::Node]]'); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 4870 | ▶ | has 'exprs' => (is => 'rw', default => sub {[]}, isa => 'ArrayRef[Erlang::Parser::Node]'); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | sub _append { | ||||||||||||
| 14 | 766 | ▶ | my ($self, $expr) = @_; | ||||||||||
|
Subroutine
_append: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 766 | push @{$self->exprs}, $expr; | |||||||||||
| 16 | 766 | $self; | |||||||||||
| 17 | } | ||||||||||||
| 18 | |||||||||||||
| 19 | sub _group () { | ||||||||||||
| 20 | 4912 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_group: called CC=2 SCAR=6.9
| |||||||||||||
| 21 | 4912 | ▶ | push @{$self->groups}, $self->exprs if @{$self->exprs}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | 4912 | $self->exprs([]); | |||||||||||
| 23 | 4912 | $self; | |||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | sub print { | ||||||||||||
| 27 | 4870 | ▶ | my ($self, $fh, $depth) = @_; | ||||||||||
|
Subroutine
print: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||
| 28 | 4870 | ▶ | $depth ||= 0; | ||||||||||
|
Condition50%1/2
$depth ||= 0
MC/DC0%0/1
$depth ||= 0
$depth
Truth table50%1/2
A
A= $depth
| |||||||||||||
| 29 | |||||||||||||
| 30 | 4870 | ▶ | if (@{$self->groups}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 556 | print $fh 'when '; | |||||||||||
| 32 | 556 | my $first = 1; | |||||||||||
| 33 | 556 | foreach (@{$self->groups}) { | |||||||||||
| 34 | 598 | ▶ | if ($first) { $first = 0 } else { print $fh '; ' } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | |||||||||||||
| 36 | 598 | my $infirst = 1; | |||||||||||
| 37 | 598 | foreach (@$_) { | |||||||||||
| 38 | 766 | ▶ | if ($infirst) { $infirst = 0 } else { print $fh ', ' } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | 766 | $_->print($fh, $depth); | |||||||||||
| 40 | } | ||||||||||||
| 41 | } | ||||||||||||
| 42 | 556 | print $fh ' '; | |||||||||||
| 43 | } | ||||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | 4 | __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 | 4 | 1; | |||||||||||
| 92 | |||||||||||||
| 93 | # vim: set sw=4 ts=4: | ||||||||||||