| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package JSORB::Client::Compiler::Javascript; |
|
2
|
4
|
|
|
4
|
|
39428
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Try::Tiny; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'JSORB::Client::Compiler'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub compile_root_namespace { |
|
12
|
|
|
|
|
|
|
my ($self, $root) = @_; |
|
13
|
|
|
|
|
|
|
$self->perform_unit_of_work(sub { |
|
14
|
|
|
|
|
|
|
my $name = $root->name; |
|
15
|
|
|
|
|
|
|
$self->print_to_buffer( "if (${name} == undefined) var ${name} = function () {};" ); |
|
16
|
|
|
|
|
|
|
$self->compile_namespace( $root ); |
|
17
|
|
|
|
|
|
|
}); |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub compile_namespace { |
|
21
|
|
|
|
|
|
|
my ($self, $ns) = @_; |
|
22
|
|
|
|
|
|
|
$self->perform_unit_of_work(sub { |
|
23
|
|
|
|
|
|
|
foreach my $element ( @{ $ns->elements } ) { |
|
24
|
|
|
|
|
|
|
if ($element->isa('JSORB::Interface')) { |
|
25
|
|
|
|
|
|
|
$self->compile_interface( $element ); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
else { |
|
28
|
|
|
|
|
|
|
my $name = join '.' => @{ $element->fully_qualified_name }; |
|
29
|
|
|
|
|
|
|
$self->print_to_buffer( "if (${name} == undefined) ${name} = function () {};" ); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$self->compile_namespace( $element ); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
}); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub compile_interface { |
|
38
|
|
|
|
|
|
|
my ($self, $i) = @_; |
|
39
|
|
|
|
|
|
|
$self->perform_unit_of_work(sub { |
|
40
|
|
|
|
|
|
|
my @name = @{ $i->fully_qualified_name }; |
|
41
|
|
|
|
|
|
|
my $name = join '.' => @name; |
|
42
|
|
|
|
|
|
|
my $path = join '/' => map { lc } @name; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$self->print_to_buffer( |
|
45
|
|
|
|
|
|
|
"${name} = function (url) {", |
|
46
|
|
|
|
|
|
|
" this._JSORB_CLIENT = new JSORB.Client ({", |
|
47
|
|
|
|
|
|
|
" base_url : url,", |
|
48
|
|
|
|
|
|
|
" base_namespace : '/${path}/'", |
|
49
|
|
|
|
|
|
|
" });", |
|
50
|
|
|
|
|
|
|
"}", |
|
51
|
|
|
|
|
|
|
); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
foreach my $proc ( @{ $i->procedures } ) { |
|
54
|
|
|
|
|
|
|
$self->compile_procedure( $proc ); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
}); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub compile_procedure { |
|
60
|
|
|
|
|
|
|
my ($self, $p) = @_; |
|
61
|
|
|
|
|
|
|
$self->perform_unit_of_work(sub { |
|
62
|
|
|
|
|
|
|
($p->has_spec) |
|
63
|
|
|
|
|
|
|
|| confess "Currently we only support compiling procedures with specs"; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my @name = @{ $p->fully_qualified_name }; |
|
66
|
|
|
|
|
|
|
my $local_name = pop @name; |
|
67
|
|
|
|
|
|
|
my $i_name = join '.' => @name; |
|
68
|
|
|
|
|
|
|
my @params = map { "arg${_}" } 1 .. grep { !/Unit/ } @{ $p->parameter_spec }; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $passed_param_list = @params ? ('[ ' . (join ", " => @params) . ' ]') : '[]'; |
|
71
|
|
|
|
|
|
|
my $full_param_list = join ", " => @params, 'callback'; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$self->print_to_buffer( |
|
75
|
|
|
|
|
|
|
"${i_name}.prototype.${local_name} = function (${full_param_list}) {", |
|
76
|
|
|
|
|
|
|
" this._JSORB_CLIENT.call(", |
|
77
|
|
|
|
|
|
|
" { method : '${local_name}', params : ${passed_param_list} },", |
|
78
|
|
|
|
|
|
|
" callback", |
|
79
|
|
|
|
|
|
|
" )", |
|
80
|
|
|
|
|
|
|
"}", |
|
81
|
|
|
|
|
|
|
); |
|
82
|
|
|
|
|
|
|
}); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
no Moose; 1; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=pod |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 NAME |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
JSORB::Client::Compiler::Javascript - A JSORB Javascript client compiler |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
use JSORB::Client::Compiler::Javascript; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $c = JSORB::Client::Compiler::Javascript->new; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# compile to a string |
|
105
|
|
|
|
|
|
|
my $js_string = $c->compile( namespace => $namespace ); |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# compile to a file |
|
108
|
|
|
|
|
|
|
$c->compile( |
|
109
|
|
|
|
|
|
|
namespace => $namespace, |
|
110
|
|
|
|
|
|
|
to => [ qw[ webroot js MyLib.js ] ] |
|
111
|
|
|
|
|
|
|
); |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
TODO |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 BUGS |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
All complex software has bugs lurking in it, and this module is no |
|
120
|
|
|
|
|
|
|
exception. If you find a bug please either email me, or add the bug |
|
121
|
|
|
|
|
|
|
to cpan-RT. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 AUTHOR |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Stevan Little E<lt>stevan.little@iinteractive.comE<gt> |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Copyright 2008-2010 Infinity Interactive, Inc. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L<http://www.iinteractive.com> |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
134
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |