| 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::Case; | ||||||||||||
| 6 | |||||||||||||
| 7 | 3 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 3 | with 'Erlang::Parser::Node'; | |||||||||||
| 9 | |||||||||||||
| 10 | 3 | has 'of' => (is => 'rw', required => 1, isa => 'Erlang::Parser::Node'); | |||||||||||
| 11 | 3 | has 'alts' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node::Alt]'); | |||||||||||
| 12 | |||||||||||||
| 13 | 496 | ▶ | sub print { | ||||||||||
|
Subroutine
print: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 14 | 496 | my ($self, $fh, $depth) = @_; | |||||||||||
| 15 | 496 | ▶ | $depth ||= 0; | ||||||||||
|
Condition100%2/2
$depth ||= 0
MC/DC100%1/1
$depth ||= 0
$depth
Truth table100%2/2
A
A= $depth
| |||||||||||||
| 16 | |||||||||||||
| 17 | 496 | print $fh 'case '; | |||||||||||
| 18 | 496 | $self->of->print($fh, $depth); | |||||||||||
| 19 | 496 | print $fh " of\n"; | |||||||||||
| 20 | |||||||||||||
| 21 | 496 | $depth++; | |||||||||||
| 22 | |||||||||||||
| 23 | 496 | print $fh "\t" x $depth; | |||||||||||
| 24 | |||||||||||||
| 25 | 496 | my $first = 1; | |||||||||||
| 26 | 496 | foreach (@{$self->alts}) { | |||||||||||
| 27 | 1280 | ▶ | if ($first) { $first = 0 } else { print $fh ";\n", "\t" x $depth } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 1280 | $_->print($fh, $depth); | |||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | 496 | $depth--; | |||||||||||
| 32 | 496 | print $fh "\n", "\t" x $depth, "end"; | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 36 | |||||||||||||
| 37 | =head1 NAME | ||||||||||||
| 38 | |||||||||||||
| 39 | Erlang::Parser::Node::Case - a case expression | ||||||||||||
| 40 | |||||||||||||
| 41 | =head1 DESCRIPTION | ||||||||||||
| 42 | |||||||||||||
| 43 | An expression which tries several different pattern matches and guards. | ||||||||||||
| 44 | |||||||||||||
| 45 | =head2 Accessors | ||||||||||||
| 46 | |||||||||||||
| 47 | =over 4 | ||||||||||||
| 48 | |||||||||||||
| 49 | =item C<of> | ||||||||||||
| 50 | |||||||||||||
| 51 | An L<Erlang::Parser::Node> which is evaluated to be matched against C<alts>. | ||||||||||||
| 52 | |||||||||||||
| 53 | =item C<alts> | ||||||||||||
| 54 | |||||||||||||
| 55 | A list of L<Erlang::Parser::Node::Alt>s which are tried against C<of> in turn. | ||||||||||||
| 56 | |||||||||||||
| 57 | =back | ||||||||||||
| 58 | |||||||||||||
| 59 | =head2 Methods | ||||||||||||
| 60 | |||||||||||||
| 61 | =over 4 | ||||||||||||
| 62 | |||||||||||||
| 63 | =item C<print> | ||||||||||||
| 64 | |||||||||||||
| 65 | Pretty-prints the node to its filehandle argument. | ||||||||||||
| 66 | |||||||||||||
| 67 | =back | ||||||||||||
| 68 | |||||||||||||
| 69 | =head1 EXAMPLE | ||||||||||||
| 70 | |||||||||||||
| 71 | case ?MODULE:myfun() of | ||||||||||||
| 72 | {X, Y} -> | ||||||||||||
| 73 | io:format("I'm a tuple! ~p, ~p~n", [X, Y]); | ||||||||||||
| 74 | [X, Y] = Z -> | ||||||||||||
| 75 | io:format("I'm a list! ~p, ~p~n", Z) | ||||||||||||
| 76 | end | ||||||||||||
| 77 | |||||||||||||
| 78 | =cut | ||||||||||||
| 79 | |||||||||||||
| 80 | 3 | 1; | |||||||||||
| 81 | |||||||||||||
| 82 | # vim: set sw=4 ts=4: | ||||||||||||