line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::MochiKit;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
91267
|
use strict;
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
84
|
|
4
|
2
|
|
|
2
|
|
21
|
use vars qw[ $VERSION $LOADJAVASCRIPT $DEBUG ];
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
183
|
|
5
|
2
|
|
|
2
|
|
13
|
use base qw[ JavaScript::MochiKit::Accessor ];
|
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
1413
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.04';
|
8
|
|
|
|
|
|
|
$LOADJAVASCRIPT = 1;
|
9
|
|
|
|
|
|
|
$DEBUG = 0;
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
1342
|
use JavaScript::MochiKit::Module;
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
22
|
|
12
|
|
|
|
|
|
|
my %JavaScriptModules = ();
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
JavaScript::MochiKit - JavaScript::MochiKit makes Perl suck less
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#!/usr/bin/perl
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use strict;
|
23
|
|
|
|
|
|
|
use warnings;
|
24
|
|
|
|
|
|
|
use JavaScript::MochiKit;
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
JavaScript::MochiKit::require('Base', 'Async');
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
print JavaScript::MochiKit::javascript_definitions;
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 FUNCTIONS
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 JavaScript::MochiKit::require( @classes )
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Loades the given MochiKit classes and also their
|
38
|
|
|
|
|
|
|
javascript-code (unless C<$JavaScript-Mochikit::LOADJAVASCRIPT> is 0).
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Returns 1 on success, dies on error.
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub require {
|
45
|
7
|
|
|
7
|
1
|
19
|
my (@classes) = @_;
|
46
|
|
|
|
|
|
|
|
47
|
7
|
|
|
|
|
10
|
my $this = __PACKAGE__;
|
48
|
7
|
50
|
|
|
|
20
|
die("$this\::require() takes at least one argument") if @classes < 1;
|
49
|
|
|
|
|
|
|
|
50
|
7
|
|
|
|
|
11
|
my $load_javascript = $LOADJAVASCRIPT;
|
51
|
7
|
100
|
|
|
|
31
|
if ( ref $classes[0] eq 'ARRAY' ) {
|
52
|
6
|
50
|
|
|
|
16
|
$load_javascript = $classes[1] if @classes > 1;
|
53
|
6
|
|
|
|
|
7
|
@classes = @{ $classes[0] };
|
|
6
|
|
|
|
|
16
|
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
7
|
|
|
|
|
14
|
foreach my $class (@classes) {
|
57
|
8
|
50
|
|
|
|
19
|
die("$this\::require() can only be run as a class method")
|
58
|
|
|
|
|
|
|
if ref $class;
|
59
|
|
|
|
|
|
|
|
60
|
8
|
|
|
|
|
9
|
my $module;
|
61
|
8
|
100
|
|
|
|
26
|
unless ( $module = $JavaScriptModules{ uc $class } ) {
|
62
|
3
|
|
|
|
|
35
|
$module = JavaScript::MochiKit::Module->new();
|
63
|
3
|
|
|
|
|
40
|
$module->name($class);
|
64
|
3
|
|
|
|
|
34
|
$JavaScriptModules{ uc $class } = $module;
|
65
|
3
|
50
|
|
|
|
9
|
print STDERR "Module '$class' just created.\n" if $DEBUG;
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
|
68
|
8
|
|
|
|
|
19
|
my $core_namespace = "$this\::$class";
|
69
|
8
|
|
|
|
|
13
|
my $pack_namespace = "$this\::JS::$class";
|
70
|
|
|
|
|
|
|
|
71
|
8
|
100
|
|
|
|
27
|
unless ( $module->required ) {
|
72
|
|
|
|
|
|
|
|
73
|
3
|
|
|
|
|
231
|
eval "CORE::require $core_namespace";
|
74
|
3
|
50
|
|
|
|
17
|
die $@ if $@;
|
75
|
|
|
|
|
|
|
|
76
|
3
|
50
|
|
|
|
8
|
print STDERR "Package '$core_namespace' just loaded.\n" if $DEBUG;
|
77
|
|
|
|
|
|
|
|
78
|
3
|
|
|
|
|
10
|
my $dependencies =
|
79
|
|
|
|
|
|
|
&_get_variable( $core_namespace, 'Dependencies', 'ARRAY' );
|
80
|
3
|
50
|
|
|
|
9
|
if ( defined $dependencies ) {
|
81
|
3
|
|
|
|
|
3
|
foreach my $dep ( @{$dependencies} ) {
|
|
3
|
|
|
|
|
8
|
|
82
|
1
|
50
|
|
|
|
5
|
&require( [$dep], $load_javascript )
|
83
|
|
|
|
|
|
|
unless &is_required($dep);
|
84
|
|
|
|
|
|
|
}
|
85
|
|
|
|
|
|
|
}
|
86
|
|
|
|
|
|
|
else {
|
87
|
0
|
0
|
|
|
|
0
|
print STDERR "No Dependencies found in '$core_namespace'.\n"
|
88
|
|
|
|
|
|
|
if $DEBUG;
|
89
|
|
|
|
|
|
|
}
|
90
|
|
|
|
|
|
|
|
91
|
3
|
|
|
|
|
14
|
$module->required(1);
|
92
|
|
|
|
|
|
|
}
|
93
|
|
|
|
|
|
|
|
94
|
8
|
100
|
66
|
|
|
80
|
if ( $load_javascript != 0 and not $module->javascript_loaded ) {
|
95
|
|
|
|
|
|
|
|
96
|
3
|
|
|
|
|
205
|
eval "CORE::require $pack_namespace";
|
97
|
3
|
50
|
|
|
|
17
|
die $@ if $@;
|
98
|
|
|
|
|
|
|
|
99
|
3
|
50
|
|
|
|
8
|
print STDERR "Package '$pack_namespace' just loaded.\n" if $DEBUG;
|
100
|
|
|
|
|
|
|
|
101
|
3
|
|
|
|
|
4
|
my $data;
|
102
|
|
|
|
|
|
|
{
|
103
|
2
|
|
|
2
|
|
882
|
no strict 'refs';
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
408
|
|
|
3
|
|
|
|
|
5
|
|
104
|
3
|
|
|
|
|
2
|
$data = *{"${pack_namespace}::DATA"};
|
|
3
|
|
|
|
|
16
|
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
{
|
107
|
3
|
|
|
|
|
6
|
local $/;
|
|
3
|
|
|
|
|
11
|
|
108
|
3
|
|
|
|
|
190
|
$module->javascript_definition(<$data>);
|
109
|
|
|
|
|
|
|
|
110
|
3
|
50
|
|
|
|
32
|
print STDERR "Javascript just loaded from '$pack_namespace'.\n"
|
111
|
|
|
|
|
|
|
if $DEBUG;
|
112
|
|
|
|
|
|
|
|
113
|
3
|
|
|
|
|
47
|
close $data;
|
114
|
|
|
|
|
|
|
}
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
}
|
117
|
|
|
|
|
|
|
|
118
|
7
|
|
|
|
|
56
|
return 1;
|
119
|
|
|
|
|
|
|
}
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _get_variable {
|
122
|
3
|
|
|
3
|
|
8
|
my ( $namespace, $variable, $type ) = @_;
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
{
|
125
|
2
|
|
|
2
|
|
12
|
no strict 'refs';
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
565
|
|
|
3
|
|
|
|
|
4
|
|
126
|
3
|
50
|
|
|
|
5
|
if ( my $glob = ${"$namespace\::"}{$variable} ) {
|
|
3
|
|
|
|
|
18
|
|
127
|
3
|
50
|
|
|
|
4
|
if ( my $ref = *{$glob}{$type} ) {
|
|
3
|
|
|
|
|
15
|
|
128
|
3
|
|
|
|
|
10
|
return $ref;
|
129
|
|
|
|
|
|
|
}
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
}
|
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
0
|
return undef;
|
134
|
|
|
|
|
|
|
}
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 JavaScript::MochiKit::require_all( )
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Loades all MochiKit classes and also their
|
139
|
|
|
|
|
|
|
javascript-code (unless C<$JavaScript-Mochikit::LOADJAVASCRIPT> is 0).
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Returns 1 on success, dies on error.
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub require_all {
|
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
0
|
1
|
0
|
my @classes = qw[
|
148
|
|
|
|
|
|
|
Core Base Iter Logging
|
149
|
|
|
|
|
|
|
DateTime Format Async DOM
|
150
|
|
|
|
|
|
|
LoggingPane Color Visual
|
151
|
|
|
|
|
|
|
];
|
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
0
|
&require(@classes);
|
154
|
|
|
|
|
|
|
}
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 JavaScript::MochiKit::is_required( $class )
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Returns 1 if class has already been loaded, 0 otherwise.
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub is_required {
|
163
|
1
|
|
|
1
|
1
|
3
|
my ($class) = @_;
|
164
|
|
|
|
|
|
|
|
165
|
1
|
|
|
|
|
8
|
return defined $JavaScriptModules{ uc $class };
|
166
|
|
|
|
|
|
|
}
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 JavaScript::MochiKit::javascript_definitions( @classes )
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Returns the Javascript code as one big string for all wanted
|
171
|
|
|
|
|
|
|
classes. Calls JavaScript::MochiKit::require( ) for all classes that are not loaded yet.
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Returns the Javascript code for all loaded classes if @classes is empty. Returns an empty
|
174
|
|
|
|
|
|
|
string if no class is loaded.
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
May die if a unloaded class does not exist.
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub javascript_definitions {
|
181
|
4
|
|
|
4
|
1
|
1540
|
my (@classes) = @_;
|
182
|
4
|
100
|
|
|
|
21
|
@classes = sort keys %JavaScriptModules if @classes < 1;
|
183
|
|
|
|
|
|
|
|
184
|
4
|
|
|
|
|
8
|
my $retval = '';
|
185
|
4
|
|
|
|
|
6
|
foreach my $class (@classes) {
|
186
|
6
|
|
|
|
|
20
|
&require( [$class], 1 ); # make sure javascript gets loaded
|
187
|
6
|
|
|
|
|
25
|
$retval .= $JavaScriptModules{ uc $class }->javascript_definition;
|
188
|
6
|
|
|
|
|
251
|
$retval .= "\n";
|
189
|
|
|
|
|
|
|
}
|
190
|
|
|
|
|
|
|
|
191
|
4
|
|
|
|
|
118
|
return $retval;
|
192
|
|
|
|
|
|
|
}
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 METHODS
|
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 GLOBAL VARIABLES
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 $JavaScript::Mochikit::DEBUG
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Enables debug-information-output to STDERR.
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Default 0
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 $JavaScript::Mochikit::LOADJAVASCRIPT
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
If value is 0, C will not load the javascript-code into memory.
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Useful if javascript-code is available as external files. (NOTE: C
|
211
|
|
|
|
|
|
|
will always load the javascript-code into memory.)
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Default 1
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 $JavaScript::Mochikit::VERSION
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Returns the current JavaScript-Mochikit version number.
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=cut
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 SEE ALSO
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
L, L
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
L, L, L
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 AUTHOR
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Sascha Kiefer, C
|
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head1 LICENSE
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under
|
236
|
|
|
|
|
|
|
the same terms as Perl itself.
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
1;
|