| 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::Def; | ||||||||||||
| 6 | |||||||||||||
| 7 | 4 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 4 | with 'Erlang::Parser::Node'; | |||||||||||
| 9 | |||||||||||||
| 10 | 4 | has 'def' => (is => 'rw', required => 1, isa => 'Str'); | |||||||||||
| 11 | 4 | has 'args' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node]'); | |||||||||||
| 12 | 4 | has 'whens' => (is => 'rw', required => 1, isa => 'Erlang::Parser::Node::WhenList'); | |||||||||||
| 13 | 4 | has 'stmts' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node]'); | |||||||||||
| 14 | |||||||||||||
| 15 | sub print { | ||||||||||||
| 16 | 3238 | ▶ | my ($self, $fh, $depth) = @_; | ||||||||||
|
Subroutine
print: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||
| 17 | 3238 | ▶ | $depth ||= 0; | ||||||||||
|
Condition50%1/2
$depth ||= 0
MC/DC0%0/1
$depth ||= 0
$depth
Truth table50%1/2
A
A= $depth
| |||||||||||||
| 18 | |||||||||||||
| 19 | 3238 | print $fh $self->def, '('; | |||||||||||
| 20 | |||||||||||||
| 21 | 3238 | my $first = 1; | |||||||||||
| 22 | 3238 | foreach (@{$self->args}) { | |||||||||||
| 23 | 4618 | ▶ | if ($first) { $first = 0 } else { print $fh ', ' } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | 4618 | $_->print($fh, $depth); | |||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | 3238 | $depth++; | |||||||||||
| 28 | |||||||||||||
| 29 | 3238 | print $fh ") "; | |||||||||||
| 30 | |||||||||||||
| 31 | 3238 | $self->whens->print($fh, $depth); | |||||||||||
| 32 | |||||||||||||
| 33 | 3238 | print $fh "->\n", "\t" x $depth; | |||||||||||
| 34 | 3238 | $first = 1; | |||||||||||
| 35 | 3238 | foreach (@{$self->stmts}) { | |||||||||||
| 36 | 5564 | ▶ | if ($first) { $first = 0 } else { print $fh ",\n", "\t" x $depth } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | 5564 | $_->print($fh, $depth); | |||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | 3238 | $depth--; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 44 | |||||||||||||
| 45 | =head1 NAME | ||||||||||||
| 46 | |||||||||||||
| 47 | Erlang::Parser::Node::Def - a match in a function definition | ||||||||||||
| 48 | |||||||||||||
| 49 | =head1 DESCRIPTION | ||||||||||||
| 50 | |||||||||||||
| 51 | Contains a single pattern match and guard expr/seq list, with the body of the | ||||||||||||
| 52 | function. | ||||||||||||
| 53 | |||||||||||||
| 54 | =head2 Accessors | ||||||||||||
| 55 | |||||||||||||
| 56 | =over 4 | ||||||||||||
| 57 | |||||||||||||
| 58 | =item C<def> | ||||||||||||
| 59 | |||||||||||||
| 60 | The name of the function. | ||||||||||||
| 61 | |||||||||||||
| 62 | =item C<args> | ||||||||||||
| 63 | |||||||||||||
| 64 | A list of L<Erlang::Parser::Node>s which constitute the argument patterns to be | ||||||||||||
| 65 | matched. | ||||||||||||
| 66 | |||||||||||||
| 67 | =item C<whens> | ||||||||||||
| 68 | |||||||||||||
| 69 | The L<Erlang::Parser::Node::WhenList> containing guard expressions/sequences. | ||||||||||||
| 70 | |||||||||||||
| 71 | =item C<stmts> | ||||||||||||
| 72 | |||||||||||||
| 73 | A list of L<Erlang::Parser::Node>s; the body for the function. | ||||||||||||
| 74 | |||||||||||||
| 75 | =back | ||||||||||||
| 76 | |||||||||||||
| 77 | =head2 Methods | ||||||||||||
| 78 | |||||||||||||
| 79 | =over 4 | ||||||||||||
| 80 | |||||||||||||
| 81 | =item C<print> | ||||||||||||
| 82 | |||||||||||||
| 83 | Pretty-prints the node to its filehandle argument. | ||||||||||||
| 84 | |||||||||||||
| 85 | =back | ||||||||||||
| 86 | |||||||||||||
| 87 | =head1 EXAMPLE | ||||||||||||
| 88 | |||||||||||||
| 89 | x(Y) -> | ||||||||||||
| 90 | Z = Y + Y, | ||||||||||||
| 91 | Z * 2 | ||||||||||||
| 92 | |||||||||||||
| 93 | =cut | ||||||||||||
| 94 | |||||||||||||
| 95 | 4 | 1; | |||||||||||
| 96 | |||||||||||||
| 97 | # vim: set sw=4 ts=4: | ||||||||||||