| 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::Comprehension; | ||||||||||||
| 6 | |||||||||||||
| 7 | 3 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 3 | with 'Erlang::Parser::Node'; | |||||||||||
| 9 | |||||||||||||
| 10 | 3 | has 'binary' => (is => 'rw', default => 0, isa => 'Bool'); | |||||||||||
| 11 | 3 | has 'output' => (is => 'rw', required => 1, isa => 'Erlang::Parser::Node'); | |||||||||||
| 12 | 3 | has 'generators' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node]'); | |||||||||||
| 13 | |||||||||||||
| 14 | 54 | ▶ | sub print { | ||||||||||
|
Subroutine
print: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||
| 15 | 54 | my ($self, $fh, $depth) = @_; | |||||||||||
| 16 | 54 | ▶ | $depth ||= 0; | ||||||||||
|
Condition50%1/2
$depth ||= 0
MC/DC0%0/1
$depth ||= 0
$depth
Truth table50%1/2
A
A= $depth
| |||||||||||||
| 17 | |||||||||||||
| 18 | 54 | ▶ | print $fh $self->binary ? '<<' : '['; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 19 | 54 | $self->output->print($fh, $depth); | |||||||||||
| 20 | 54 | print $fh ' || '; | |||||||||||
| 21 | |||||||||||||
| 22 | 54 | my $first = 1; | |||||||||||
| 23 | 54 | foreach (@{$self->generators}) { | |||||||||||
| 24 | 66 | ▶ | if ($first) { $first = 0 } else { print $fh ', ' } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 25 | 66 | $_->print($fh, $depth); | |||||||||||
| 26 | } | ||||||||||||
| 27 | 54 | ▶ | print $fh $self->binary ? '>>' : ']'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 31 | |||||||||||||
| 32 | =head1 NAME | ||||||||||||
| 33 | |||||||||||||
| 34 | Erlang::Parser::Node::Comprehension - a list or binary comprehension | ||||||||||||
| 35 | |||||||||||||
| 36 | =head1 DESCRIPTION | ||||||||||||
| 37 | |||||||||||||
| 38 | Used to generate (binary) lists/strings by a combination of generators, guards | ||||||||||||
| 39 | and output expressions. | ||||||||||||
| 40 | |||||||||||||
| 41 | =head2 Accessors | ||||||||||||
| 42 | |||||||||||||
| 43 | =over 4 | ||||||||||||
| 44 | |||||||||||||
| 45 | =item C<binary> | ||||||||||||
| 46 | |||||||||||||
| 47 | True if this is a binary comprehension. | ||||||||||||
| 48 | |||||||||||||
| 49 | =item C<output> | ||||||||||||
| 50 | |||||||||||||
| 51 | The L<Erlang::Parser::Node> which forms the output elements based on | ||||||||||||
| 52 | C<generators>. | ||||||||||||
| 53 | |||||||||||||
| 54 | =item C<generators> | ||||||||||||
| 55 | |||||||||||||
| 56 | A mixture of generators (in the form C<<X <- Y>> or C<<X <= Y>>) and guards | ||||||||||||
| 57 | which create the terms used by C<output>. | ||||||||||||
| 58 | |||||||||||||
| 59 | =back | ||||||||||||
| 60 | |||||||||||||
| 61 | =head2 Methods | ||||||||||||
| 62 | |||||||||||||
| 63 | =over 4 | ||||||||||||
| 64 | |||||||||||||
| 65 | =item C<print> | ||||||||||||
| 66 | |||||||||||||
| 67 | Pretty-prints the node to its filehandle argument. | ||||||||||||
| 68 | |||||||||||||
| 69 | =back | ||||||||||||
| 70 | |||||||||||||
| 71 | =head1 EXAMPLE | ||||||||||||
| 72 | |||||||||||||
| 73 | [X + Y || X <- [1, 2, 3], Y <- [1, 2, 3], X + Y > 2] | ||||||||||||
| 74 | |||||||||||||
| 75 | =cut | ||||||||||||
| 76 | |||||||||||||
| 77 | 3 | 1; | |||||||||||
| 78 | |||||||||||||
| 79 | # vim: set sw=4 ts=4: | ||||||||||||