Code/Expression/Op.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 46 CC 4 SCAR 17.6
CC
4
Cov
0%
output
12.0
new
6.0
children
2.0
CRAP 5.8
1 package JavaScript::Code::Expression::Op;
2
3 use strict;
4 use vars qw[ $VERSION ];
5 use JavaScript::Code::Expression::Op::Term;
6
7 $VERSION = '0.08';
8
9 =head1 NAME
10
11 JavaScript::Code::Expression::Node - Represents a Node in JavaScript Expression
12
13 =head1 METHODS
14
15 =head2 new
16
17 =cut
18
19 sub new {
20 my $obj = shift;
21 my $class = ref $obj || $obj;
22
23 die("'$class' is a binary operator and must take exactly 2 operands.")
24 unless @_ == 2;
25
26 return bless [@_], $class;
27 }
28
29 =head2 children
30
31 =cut
32
33 sub children { return @{ shift() } }
34
35 =head2 unary
36
37 =cut
38
39 sub unary { return 0; }
40
41 =head2 output
42
43 =cut
44
45 sub output {
46 my ( $self, $precedence ) = @_;
47 $precedence = 0 if not defined $precedence;
48 my $output = join $self->op,
49 map { $_->output( $self->precedence ) } $self->children;
50
51 $output = "($output)" if $precedence > $self->precedence;
52
53 return $output;
54 }
55
56 =head1 SEE ALSO
57
58 L<JavaScript::Code>
59
60 =head1 AUTHOR
61
62 Sascha Kiefer, C<esskar@cpan.org>
63
64 =head1 LICENSE
65
66 This library is free software, you can redistribute it and/or modify it under
67 the same terms as Perl itself.
68
69 =cut
70
71 1;