File Coverage

blib/lib/Erlang/Parser/Node/List.pm
Criterion Covered Total %
statement 17 17 100.0
branch 4 4 100.0
condition 2 2 100.0
subroutine 2 2 100.0
pod 1 1 100.0
total 26 26 100.0


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::List;
6              
7 3     3   10 use Moose;
  3         4  
  3         20  
8             with 'Erlang::Parser::Node';
9              
10             has 'elems' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node]');
11             has 'cdr' => (is => 'rw', required => 1, isa => 'Maybe[Erlang::Parser::Node]');
12              
13             sub print {
14 3360     3360 1 3423 my ($self, $fh, $depth) = @_;
15 3360   100     5564 $depth ||= 0;
16              
17 3360         3178 print $fh '[';
18 3360         2560 my $first = 1;
19 3360         2585 foreach (@{$self->elems}) {
  3360         79000  
20 4570 100       5526 if ($first) { $first = 0 } else { print $fh ', ' }
  2504         2020  
  2066         2251  
21 4570         9689 $_->print($fh, $depth);
22             }
23              
24 3360 100       76956 if (defined $self->cdr) {
25 888         1085 print $fh '|';
26 888         19391 $self->cdr->print($fh, $depth);
27             }
28              
29 3360         7352 print $fh ']';
30             }
31              
32             __PACKAGE__->meta->make_immutable;
33              
34             =head1 NAME
35              
36             Erlang::Parser::Node::List - a list of values
37              
38             =head1 DESCRIPTION
39              
40             A lisp-style cdr list.
41              
42             =head2 Accessors
43              
44             =over 4
45              
46             =item C<elems>
47              
48             A list of L<Erlang::Parser::Node>s which comprise the list.
49              
50             =item C<cdr>
51              
52             An optional L<Erlang::Parser::Node> which forms the tail of the list. This
53             should be another list (usually).
54              
55             =back
56              
57             =head2 Methods
58              
59             =over 4
60              
61             =item C<print>
62              
63             Pretty-prints the node to its filehandle argument.
64              
65             =back
66              
67             =head1 EXAMPLE
68              
69             [7, 8, 9|[]]
70              
71             =cut
72              
73             1;
74              
75             # vim: set sw=4 ts=4: