line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::Code::Element;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict;
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
59
|
|
4
|
2
|
|
|
2
|
|
9
|
use vars qw[ $VERSION @RESERVEDWORDS ];
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
90
|
|
5
|
2
|
|
|
2
|
|
8
|
use base qw[ JavaScript::Code::Accessor Clone ];
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
926
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.08';
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
@RESERVEDWORDS = qw [
|
10
|
|
|
|
|
|
|
abstract boolean break byte
|
11
|
|
|
|
|
|
|
case catch char class const continue
|
12
|
|
|
|
|
|
|
default delete do double
|
13
|
|
|
|
|
|
|
else export extends
|
14
|
|
|
|
|
|
|
false final finally float for function
|
15
|
|
|
|
|
|
|
goto
|
16
|
|
|
|
|
|
|
if implements in instanceof int
|
17
|
|
|
|
|
|
|
long
|
18
|
|
|
|
|
|
|
native new null
|
19
|
|
|
|
|
|
|
package private protected public
|
20
|
|
|
|
|
|
|
return
|
21
|
|
|
|
|
|
|
short static super switch synchronized
|
22
|
|
|
|
|
|
|
this thow throws transient true try typeof
|
23
|
|
|
|
|
|
|
var void
|
24
|
|
|
|
|
|
|
while with
|
25
|
|
|
|
|
|
|
];
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use overload
|
28
|
0
|
|
|
0
|
|
0
|
'eq' => sub { 0 },
|
29
|
2
|
|
|
2
|
|
10078
|
'==' => sub { 0 };
|
|
2
|
|
|
0
|
|
2173
|
|
|
2
|
|
|
|
|
22
|
|
|
0
|
|
|
|
|
0
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw[ parent ]);
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 NAME
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
JavaScript::Code::Element - A JavaScript Element
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Base class for javascript elements like blocks, variables, functions and so on.
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 METHODS
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 new
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 $self->clone( )
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Clones the element.
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 $self->parent( )
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
The parent element.
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SEE ALSO
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
L
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 AUTHOR
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Sascha Kiefer, C
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 LICENSE
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under
|
68
|
|
|
|
|
|
|
the same terms as Perl itself.
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 $self->get_indenting( )
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub get_indenting {
|
77
|
4
|
|
|
4
|
1
|
6
|
my ( $self, $intend ) = @_;
|
78
|
|
|
|
|
|
|
|
79
|
4
|
50
|
|
|
|
14
|
return '' unless $intend > 1;
|
80
|
0
|
|
|
|
|
0
|
return ' ' x ( $intend - 1 );
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 $self->exists_in_parent( )
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub exists_in_parent {
|
88
|
10
|
|
|
10
|
1
|
40
|
my ( $self, $obj, $parent ) = @_;
|
89
|
|
|
|
|
|
|
|
90
|
10
|
100
|
|
|
|
16
|
unless ( defined $parent ) {
|
91
|
7
|
|
|
|
|
209
|
$parent = $self->parent;
|
92
|
7
|
100
|
|
|
|
43
|
return 0 unless defined $parent;
|
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
|
|
10
|
return $self->exists_in_parent( $obj, $parent );
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
|
97
|
3
|
50
|
|
|
|
27
|
if ( $parent->can('elements') ) {
|
98
|
3
|
|
|
|
|
4
|
foreach my $element ( @{ $parent->elements } ) {
|
|
3
|
|
|
|
|
8
|
|
99
|
|
|
|
|
|
|
last
|
100
|
5
|
100
|
|
|
|
62
|
if Scalar::Util::refaddr($element) ==
|
101
|
|
|
|
|
|
|
Scalar::Util::refaddr($self);
|
102
|
2
|
50
|
|
|
|
10
|
next unless $element->isa('JavaScript::Code::Variable');
|
103
|
2
|
50
|
|
|
|
8
|
return 1 if $obj eq $element;
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
}
|
107
|
|
|
|
|
|
|
|
108
|
3
|
|
|
|
|
13
|
return $parent->exists_in_parent($obj);
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
{ # I do not like this, but well ... :-)
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my %ReservedWords = map { ( $_, 1 ) } @RESERVEDWORDS;
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 $self->is_valid_name( )
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub is_valid_name {
|
120
|
4
|
|
|
4
|
1
|
7
|
my ( $self, $name, $built_in ) = @_;
|
121
|
|
|
|
|
|
|
|
122
|
4
|
50
|
33
|
|
|
20
|
return 0 if !$built_in and exists $ReservedWords{$name};
|
123
|
4
|
|
|
|
|
41
|
return $name =~ m{^[a-zA-Z][a-zA-Z0-9_]*$};
|
124
|
|
|
|
|
|
|
}
|
125
|
|
|
|
|
|
|
}
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1;
|
128
|
|
|
|
|
|
|
|