line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::Code::Function;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
9
|
use strict;
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
90
|
|
4
|
2
|
|
|
2
|
|
9
|
use vars qw[ $VERSION ];
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
74
|
|
5
|
2
|
|
|
2
|
|
8
|
use base qw[ JavaScript::Code::Element ];
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
240
|
|
6
|
2
|
|
|
2
|
|
982
|
use JavaScript::Code::Function::Result ();
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
46
|
|
7
|
2
|
|
|
2
|
|
1316
|
use JavaScript::Code::Function::BuildIn ();
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1253
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw[ name parameters is_buildin ]);
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.08';
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
JavaScript::Code::Function - A JavaScript Function
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 METHODS
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 $self->name( $name )
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Sets or gets the function name.
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 $self->block( $block )
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Sets or gets the code block of the function.
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
I<$block> must be a L
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub block {
|
36
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
37
|
0
|
0
|
|
|
|
|
if (@_) {
|
38
|
0
|
|
|
|
|
|
my $args = $self->args(@_);
|
39
|
|
|
|
|
|
|
|
40
|
0
|
|
0
|
|
|
|
my $block = $args->{block} || shift;
|
41
|
0
|
0
|
0
|
|
|
|
die "Block must be a 'JavaScript::Code::Block'."
|
42
|
|
|
|
|
|
|
unless ref $block
|
43
|
|
|
|
|
|
|
and $block->isa('JavaScript::Code::Block');
|
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$self->{block} = $block->clone->parent($self);
|
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return $self;
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
else {
|
50
|
0
|
|
|
|
|
|
return $self->{block};
|
51
|
|
|
|
|
|
|
}
|
52
|
|
|
|
|
|
|
}
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 $self->is_buildin( )
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Returns whether or not the function is a build-in function
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut
|
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
0
|
1
|
|
sub is_buildin { return 0; }
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 $self->check_name( )
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub check_name {
|
67
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $name = $self->name;
|
70
|
0
|
0
|
|
|
|
|
die "A 'JavaScript::Code::Function' needs a name."
|
71
|
|
|
|
|
|
|
unless $name;
|
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
die "Not a valid 'JavaScript::Code::Function' name: '$name'"
|
74
|
|
|
|
|
|
|
unless $self->is_valid_name($name, $self->is_buildin );
|
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $name;
|
77
|
|
|
|
|
|
|
}
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 $self->call( )
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Calls the functions. Returns a L.
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub call {
|
86
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
87
|
|
|
|
|
|
|
|
88
|
0
|
|
0
|
|
|
|
my $params = $self->args(@_)->{parameters} || $_[0] || [];
|
89
|
0
|
|
|
|
|
|
my $name = $self->check_name;
|
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
$params = [$params] unless ref $params eq 'ARRAY';
|
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $result = '';
|
94
|
0
|
|
|
|
|
|
$result .= "$name ( ";
|
95
|
0
|
|
|
|
|
|
$result .= join(", ", @{$params});
|
|
0
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$result .= " )";
|
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return JavaScript::Code::Function::Result->new( value => $result );
|
99
|
|
|
|
|
|
|
}
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 $self->output( )
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub output {
|
106
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
107
|
0
|
|
0
|
|
|
|
my $scope = shift || 1;
|
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
die "Can not defined a build-in function."
|
110
|
|
|
|
|
|
|
if $self->is_buildin;
|
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $name = $self->check_name;
|
113
|
0
|
|
|
|
|
|
my $indenting = $self->get_indenting($scope);
|
114
|
0
|
|
|
|
|
|
my $output = '';
|
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$output .= $indenting;
|
117
|
0
|
|
|
|
|
|
$output .= "function $name ( ";
|
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
$self->parameters( [] ) unless defined $self->parameters;
|
120
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
$output .= join(
|
122
|
|
|
|
|
|
|
', ',
|
123
|
|
|
|
|
|
|
map {
|
124
|
0
|
|
|
|
|
|
die "Not a valid 'JavaScript::Code::Function' parameter name: '$_'"
|
125
|
|
|
|
|
|
|
unless $self->is_valid_name($_);
|
126
|
0
|
|
|
|
|
|
$_
|
127
|
0
|
|
|
|
|
|
} @{ $self->parameters }
|
128
|
|
|
|
|
|
|
);
|
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$output .= " )\n";
|
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
if ( defined(my $block = $self->block) ) {
|
133
|
0
|
|
|
|
|
|
$output .= $block->output($scope);
|
134
|
|
|
|
|
|
|
}
|
135
|
|
|
|
|
|
|
else {
|
136
|
0
|
|
|
|
|
|
$output .= $indenting;
|
137
|
0
|
|
|
|
|
|
$output .= "{\n";
|
138
|
0
|
|
|
|
|
|
$output .= $indenting;
|
139
|
0
|
|
|
|
|
|
$output .= "}\n";
|
140
|
|
|
|
|
|
|
}
|
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
return $output;
|
143
|
|
|
|
|
|
|
}
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 SEE ALSO
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
L
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 AUTHOR
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Sascha Kiefer, C
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 LICENSE
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under
|
156
|
|
|
|
|
|
|
the same terms as Perl itself.
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1;
|