line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::Code::Array;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
12
|
use strict;
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
80
|
|
4
|
2
|
|
|
2
|
|
12
|
use vars qw[ $VERSION ];
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
83
|
|
5
|
2
|
|
|
2
|
|
11
|
use base qw[ JavaScript::Code::Type ];
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1831
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw[ elements size ]);
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$VERSION = '0.08';
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
JavaScript::Code::Array - A JavaScript Array Type
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#!/usr/bin/perl
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use strict;
|
20
|
|
|
|
|
|
|
use warnings;
|
21
|
|
|
|
|
|
|
use JavaScript::Code::Array;
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $array = JavaScript::Code::Array->new( elements => [] );
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 new( ... )
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new {
|
32
|
0
|
|
|
0
|
1
|
|
my $this = shift;
|
33
|
0
|
|
0
|
|
|
|
my $class = ref($this) || $this;
|
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_);
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# cleanup the elements
|
38
|
0
|
|
0
|
|
|
|
my $array = delete $self->{elements} || [];
|
39
|
0
|
0
|
|
|
|
|
push @{$array}, @{ delete $self->{value} || [] };
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$self->elements( [] );
|
41
|
0
|
0
|
|
|
|
|
$self->push_back($array) if defined $array;
|
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return $self;
|
44
|
|
|
|
|
|
|
}
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 $self->push_back( $value | \@values )
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Add one or more element(s) to the end of array.
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub push_back {
|
53
|
0
|
|
|
0
|
1
|
|
my ( $self, $array ) = @_;
|
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
die 'Nothing to add.'
|
56
|
|
|
|
|
|
|
unless defined $array;
|
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
$array = [$array] unless ref $array eq 'ARRAY';
|
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $elements = $self->elements;
|
61
|
0
|
|
|
|
|
|
foreach my $value ( @{$array} ) {
|
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
$value = JavaScript::Code::Type->build( value => $value )
|
64
|
|
|
|
|
|
|
unless ref $value;
|
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
0
|
|
|
|
die "'$value' is not a 'JavaScript::Code::Value'."
|
67
|
|
|
|
|
|
|
unless ref $value
|
68
|
|
|
|
|
|
|
and $value->isa('JavaScript::Code::Value');
|
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
foreach my $t (qw[ JavaScript::Code::Array JavaScript::Code::Hash ]) {
|
71
|
0
|
0
|
|
|
|
|
die "Can not add '$t'." if $value->isa($t);
|
72
|
|
|
|
|
|
|
}
|
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
push @{$elements}, $value;
|
|
0
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$self->elements($elements);
|
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return $self;
|
80
|
|
|
|
|
|
|
}
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 $self->at( $index, < $value > )
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Gets or sets the value on the given index.
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Dies if the index is out of range.
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub at {
|
91
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
92
|
0
|
|
0
|
|
|
|
my $ndx = shift || 0;
|
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
|
die "Out of range."
|
95
|
|
|
|
|
|
|
if $ndx >= $self->length;
|
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
if (@_) {
|
98
|
0
|
|
|
|
|
|
my $value = shift;
|
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
0
|
|
|
|
die "'$value' is not a 'JavaScript::Code::Value'."
|
101
|
|
|
|
|
|
|
unless ref $value
|
102
|
|
|
|
|
|
|
and $value->isa('JavaScript::Code::Value');
|
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$self->elements->[$ndx] = $value;
|
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
return $self;
|
107
|
|
|
|
|
|
|
}
|
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return $self->elements->[$ndx];
|
110
|
|
|
|
|
|
|
}
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 $self->length( )
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns the number of elements stored in the array.
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub length {
|
119
|
0
|
|
|
0
|
1
|
|
my ($self) = @_;
|
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return scalar @{ $self->elements };
|
|
0
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
}
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 $self->type( )
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub type {
|
129
|
0
|
|
|
0
|
1
|
|
return "Array";
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 $self->output( )
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub output {
|
137
|
0
|
|
|
0
|
1
|
|
my ($self) = @_;
|
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my $output = 'new Array(';
|
140
|
0
|
0
|
|
|
|
|
unless ( $self->length ) {
|
141
|
0
|
|
0
|
|
|
|
my $size = $self->size || 0;
|
142
|
0
|
0
|
|
|
|
|
$output .= $size if $size;
|
143
|
|
|
|
|
|
|
}
|
144
|
|
|
|
|
|
|
else {
|
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my $values = '';
|
147
|
0
|
|
|
|
|
|
foreach my $value ( @{ $self->elements } ) {
|
|
0
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
0
|
0
|
|
|
|
|
$values .= ', ' if $values;
|
150
|
0
|
|
|
|
|
|
$values .= "$value";
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
$output .= $values;
|
154
|
|
|
|
|
|
|
}
|
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
$output .= ')';
|
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return $output;
|
159
|
|
|
|
|
|
|
}
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SEE ALSO
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 AUTHOR
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Sascha Kiefer, C
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 LICENSE
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under
|
172
|
|
|
|
|
|
|
the same terms as Perl itself.
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1;
|