line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::Code::Condition;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
10
|
use strict;
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
11
|
use vars qw[ $VERSION ];
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
85
|
|
5
|
2
|
|
|
2
|
|
10
|
use base qw[ JavaScript::Code::Element ];
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1039
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors(qw[ ifs ]);
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$VERSION = '0.08';
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
JavaScript::Code::Condition - A JavaScript Condition
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 METHODS
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 new
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 $self->add_if( %args | \%args )
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Adds a new if statement.
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
I<%args> must contain the following keys:
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
- expression: a L object
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
- block: a L object
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub add_if {
|
32
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $args = $_[0];
|
35
|
0
|
0
|
|
|
|
|
$args = [ $self->args(@_) ]
|
36
|
|
|
|
|
|
|
unless ref $args eq 'ARRAY';
|
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
foreach my $c ( @{$args} ) {
|
|
0
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $expr = $c->{expression};
|
41
|
0
|
0
|
0
|
|
|
|
die "Expression must be a 'JavaScript::Code::Expression::Boolean'."
|
42
|
|
|
|
|
|
|
unless ref $expr
|
43
|
|
|
|
|
|
|
and $expr->isa('JavaScript::Code::Expression::Boolean');
|
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $block = $c->{block};
|
46
|
0
|
0
|
0
|
|
|
|
die "Block must be a 'JavaScript::Code::Block'."
|
47
|
|
|
|
|
|
|
unless ref $block
|
48
|
|
|
|
|
|
|
and $block->isa('JavaScript::Code::Block');
|
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $cond = {
|
51
|
|
|
|
|
|
|
expression => $expr,
|
52
|
|
|
|
|
|
|
block => $block->clone->parent($self),
|
53
|
|
|
|
|
|
|
};
|
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
$self->{ifs} = []
|
56
|
|
|
|
|
|
|
unless defined $self->{ifs};
|
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
push @{ $self->{ifs} }, $cond;
|
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
}
|
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $self;
|
62
|
|
|
|
|
|
|
}
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 $self->else( $block )
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Sets the else statement.
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
I<$block> must be a L
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub else {
|
73
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
74
|
0
|
0
|
|
|
|
|
if (@_) {
|
75
|
0
|
|
|
|
|
|
my $args = $self->args(@_);
|
76
|
|
|
|
|
|
|
|
77
|
0
|
|
0
|
|
|
|
my $block = $args->{block} || shift;
|
78
|
0
|
0
|
0
|
|
|
|
die "Block must be a 'JavaScript::Code::Block'."
|
79
|
|
|
|
|
|
|
unless ref $block
|
80
|
|
|
|
|
|
|
and $block->isa('JavaScript::Code::Block');
|
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$self->{else} = $block->clone->parent($self);
|
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return $self;
|
85
|
|
|
|
|
|
|
}
|
86
|
|
|
|
|
|
|
else {
|
87
|
0
|
|
|
|
|
|
return $self->{else};
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
}
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 $self->output( )
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub output {
|
96
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
97
|
0
|
|
0
|
|
|
|
my $scope = shift || 1;
|
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
die "At least one if-statement is needed."
|
100
|
|
|
|
|
|
|
unless defined $self->ifs;
|
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $indenting = $self->get_indenting($scope);
|
103
|
0
|
|
|
|
|
|
my $output = '';
|
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $max = @{ $self->ifs };
|
|
0
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
for ( my $i = 0 ; $i < $max ; ++$i ) {
|
107
|
0
|
|
|
|
|
|
$output .= $indenting;
|
108
|
0
|
0
|
|
|
|
|
$output .= "else " if $i;
|
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $c = $self->ifs->[$i];
|
111
|
0
|
|
|
|
|
|
$output .= "if ( " . $c->{expression}->output($scope) . " )\n";
|
112
|
0
|
|
|
|
|
|
$output .= $c->{block}->output($scope);
|
113
|
|
|
|
|
|
|
}
|
114
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
if ( defined $self->else ) {
|
116
|
0
|
|
|
|
|
|
$output .= $indenting;
|
117
|
0
|
|
|
|
|
|
$output .= "else\n";
|
118
|
0
|
|
|
|
|
|
$output .= $self->else->output;
|
119
|
|
|
|
|
|
|
}
|
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return $output;
|
122
|
|
|
|
|
|
|
}
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SEE ALSO
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 AUTHOR
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Sascha Kiefer, C
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 LICENSE
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under
|
135
|
|
|
|
|
|
|
the same terms as Perl itself.
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1;
|