line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::Code::Block;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
13
|
use strict;
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
116
|
|
4
|
2
|
|
|
2
|
|
10
|
use vars qw[ $VERSION ];
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
85
|
|
5
|
2
|
|
|
2
|
|
10
|
use base qw[ JavaScript::Code::Element ];
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1061
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1306
|
use JavaScript::Code::Variable ();
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
38
|
|
8
|
2
|
|
|
2
|
|
981
|
use JavaScript::Code::Function ();
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
937
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors(qw[ elements ]);
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$VERSION = '0.08';
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
JavaScript::Code::Block - A JavaScript Block Element
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
A block element in javascript is a collection of javascript elements enclosed in brakets.
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Example:
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
{ // a block starts
|
25
|
|
|
|
|
|
|
var a = 42;
|
26
|
|
|
|
|
|
|
var b = "21 is just half the truth.";
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
{ // another block starts
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
// ...
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
} // another block ends
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} // a block ends
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#!/usr/bin/perl
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
use strict;
|
42
|
|
|
|
|
|
|
use warnings;
|
43
|
|
|
|
|
|
|
use JavaScript::Code::Block;
|
44
|
|
|
|
|
|
|
use JavaScript::Code::Variable;
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $block1 = JavaScript::Code::Block->new();
|
47
|
|
|
|
|
|
|
my $var1 = JavaScript::Code::Variable->new( name => 'a', value => "Var 1!" );
|
48
|
|
|
|
|
|
|
my $var2 = JavaScript::Code::Variable->new()->name('b')->value("Var 2!");
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $block2 = JavaScript::Code::Block->new();
|
51
|
|
|
|
|
|
|
my $var3 = JavaScript::Code::Variable->new()->name('c')->value("Var 3!");
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$block1->add( $var1 );
|
54
|
|
|
|
|
|
|
$block1->add( $var2 )->add( $block2->add( $var3 ) );
|
55
|
|
|
|
|
|
|
$block1->add( JavaScript::Code::Variable->new()->name('d')->value(42) );
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
print $block1->output;
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 METHODS
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 new
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub new {
|
66
|
1
|
|
|
1
|
1
|
23
|
my $this = shift;
|
67
|
1
|
|
33
|
|
|
8
|
my $class = ref($this) || $this;
|
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
15
|
my $self = $class->SUPER::new(@_);
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# cleanup the elements
|
72
|
1
|
|
|
|
|
353
|
my $array = delete $self->{elements};
|
73
|
1
|
|
|
|
|
4
|
$self->{elements} = [];
|
74
|
1
|
50
|
|
|
|
4
|
$self->add($array) if defined $array;
|
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
3
|
return $self;
|
77
|
|
|
|
|
|
|
}
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 $self->add( $element | \@elements )
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Adds one or more new element(s) to the block.
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub add {
|
86
|
2
|
|
|
2
|
1
|
2
|
my ( $self, $array ) = @_;
|
87
|
|
|
|
|
|
|
|
88
|
2
|
50
|
|
|
|
6
|
die 'Nothing to add.'
|
89
|
|
|
|
|
|
|
unless defined $array;
|
90
|
|
|
|
|
|
|
|
91
|
2
|
50
|
|
|
|
8
|
$array = [$array] unless ref $array eq 'ARRAY';
|
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
|
|
3
|
my @elements = ();
|
94
|
2
|
|
|
|
|
3
|
foreach my $element ( @{$array} ) {
|
|
2
|
|
|
|
|
4
|
|
95
|
|
|
|
|
|
|
|
96
|
2
|
50
|
33
|
|
|
50
|
die "Not a 'JavaScript::Code::Element'."
|
97
|
|
|
|
|
|
|
unless ref $element
|
98
|
|
|
|
|
|
|
and $element->isa('JavaScript::Code::Element');
|
99
|
|
|
|
|
|
|
|
100
|
2
|
50
|
|
|
|
10
|
die "Not able to a element of type 'JavaScript::Code'."
|
101
|
|
|
|
|
|
|
if $element->isa('JavaScript::Code');
|
102
|
|
|
|
|
|
|
|
103
|
2
|
|
|
|
|
48
|
push @elements, $element->clone->parent($self);
|
104
|
|
|
|
|
|
|
}
|
105
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
17
|
push @{ $self->{elements} }, @elements;
|
|
2
|
|
|
|
|
5
|
|
107
|
|
|
|
|
|
|
|
108
|
2
|
|
|
|
|
5
|
return $self;
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 $self->add_variable( %args | \%args )
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Creates a variable using the arguments and adds it to the the block.
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Returns a L object.
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub add_variable {
|
120
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $var = JavaScript::Code::Variable->new(@_);
|
123
|
0
|
|
|
|
|
|
$self->add($var);
|
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return $var;
|
126
|
|
|
|
|
|
|
}
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 $self->add_function( %args | \%args )
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Creates a function using the arguments and adds it to the the block.
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Returns a L object.
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub add_function {
|
137
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my $func = JavaScript::Code::Function->new(@_);
|
140
|
0
|
|
|
|
|
|
$self->add($func);
|
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
return $func;
|
143
|
|
|
|
|
|
|
}
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 $self->elements( )
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Returns a ref-array of all added elements.
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 $self->output( )
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Returns the javascript code for the block.
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub output {
|
158
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
159
|
0
|
|
0
|
|
|
|
my $scope = shift || 1;
|
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
my $indenting = $self->get_indenting($scope);
|
162
|
0
|
|
|
|
|
|
my $output = $indenting . "{\n";
|
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my $elements = $self->elements;
|
165
|
0
|
|
|
|
|
|
foreach my $element ( @{$elements} ) {
|
|
0
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
$output .= $element->output( $scope + 1 );
|
167
|
|
|
|
|
|
|
}
|
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
$output .= $indenting . "}\n";
|
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
return $output;
|
172
|
|
|
|
|
|
|
}
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 SEE ALSO
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 AUTHOR
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Sascha Kiefer, C
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 LICENSE
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under
|
185
|
|
|
|
|
|
|
the same terms as Perl itself.
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
1;
|