File Coverage

blib/lib/CORBA/XS/StubPerlVisitor.pm
Criterion Covered Total %
statement 18 292 6.1
branch 0 52 0.0
condition 0 12 0.0
subroutine 6 11 54.5
pod 0 5 0.0
total 24 372 6.4


line stmt bran cond sub pod time code
1            
2             #
3             # Interface Definition Language (OMG IDL CORBA v3.0)
4             #
5            
6             package CORBA::XS::StubPerlVisitor;
7            
8 1     1   6 use strict;
  1         1  
  1         29  
9 1     1   5 use warnings;
  1         2  
  1         47  
10            
11             our $VERSION = '0.62';
12            
13 1     1   965 use CORBA::Perl::CdrVisitor;
  1         8923  
  1         41  
14 1     1   10 use base qw(CORBA::Perl::CdrVisitor);
  1         3  
  1         93  
15            
16 1     1   6 use File::Basename;
  1         2  
  1         64  
17 1     1   4 use POSIX qw(ctime);
  1         2  
  1         6  
18            
19             # needs $node->{pl_name} $node->{pl_package} (PerlNameVisitor)
20            
21             sub new {
22 0     0 0   my $proto = shift;
23 0   0       my $class = ref($proto) || $proto;
24 0           my $self = {};
25 0           bless $self, $class;
26 0           my($parser, $pkg_prefix) = @_;
27 0           $self->{parser} = $parser;
28 0           $self->{parser}->YYData->{modules} = [];
29 0           $self->{srcname} = $parser->YYData->{srcname};
30 0           $self->{srcname_size} = $parser->YYData->{srcname_size};
31 0           $self->{srcname_mtime} = $parser->YYData->{srcname_mtime};
32 0           $self->{symbtab} = $parser->YYData->{symbtab};
33 0           $self->{client} = 1;
34 0           $self->{use} = {};
35 0 0         if ($pkg_prefix) {
36 0           $self->{pkg_prefix} = $pkg_prefix;
37 0           $self->{pkg_prefix} =~ s/\//::/g;
38 0           $self->{pkg_prefix} .= '::';
39             }
40             else {
41 0           $self->{pkg_prefix} = q{};
42             }
43 0           my $filename = basename($self->{srcname}, '.idl') . '.pm';
44 0           $self->open_stream($filename);
45 0           $self->{done_hash} = {};
46 0           $self->{has_methods} = 0;
47 0           $self->{pkg_modif} = 0;
48 0           $self->{stringify} = 1;
49 0           $self->{id} = 0;
50 0           $self->{num_key} = 'num_pl_stub';
51 0           return $self;
52             }
53            
54             #
55             # 3.5 OMG IDL Specification
56             #
57            
58             sub visitSpecification {
59 0     0 0   my $self = shift;
60 0           my($node) = @_;
61 0           my $filename = basename($self->{srcname}, '.idl');
62 0           my $FH = $self->{out};
63 0           $self->{pkg_modif} = 0;
64 0           print $FH "# ex: set ro:\n";
65 0           print $FH "# This file was generated (by ",$0,"). DO NOT modify it.\n";
66 0           print $FH "# From file : ",$self->{srcname},", ",$self->{srcname_size}," octets, ",POSIX::ctime($self->{srcname_mtime});
67 0           print $FH "\n";
68 0           print $FH "use strict;\n";
69 0           print $FH "\n";
70 0           print $FH "# Preloaded methods go here.\n";
71 0           print $FH "\n";
72 0           print $FH "package main;\n";
73 0           print $FH "\n";
74 0           print $FH "use CORBA::Perl::CORBA;\n";
75 0           print $FH "use Carp;\n";
76 0           print $FH "\n";
77 0 0         if (exists $node->{list_import}) {
78 0           foreach (@{$node->{list_import}}) {
  0            
79 0           $_->visit($self);
80             }
81             }
82 0           foreach (@{$node->{list_decl}}) {
  0            
83 0           $self->_get_defn($_)->visit($self);
84 0 0         if ($self->{pkg_modif}) {
85 0           $self->{pkg_modif} = 0;
86 0           print $FH "package main;\n";
87 0           print $FH "\n";
88             }
89             }
90 0 0         if ($self->{has_methods}) {
91 0           print $FH "package ",$filename,";\n";
92 0           print $FH "\n";
93 0           print $FH "use strict;\n";
94 0           print $FH "use warnings;\n";
95 0           print $FH "\n";
96 0           print $FH "require DynaLoader;\n";
97 0           print $FH "\n";
98 0           print $FH "our \@ISA = qw(DynaLoader);\n";
99 0           print $FH "\n";
100 0           print $FH "our \$VERSION = '0.01';\n";
101 0           print $FH "\n";
102 0           print $FH "bootstrap ",$filename," \$VERSION;\n";
103 0           print $FH "\n";
104             }
105 0           print $FH "1;\n";
106 0           print $FH "\n";
107 0           print $FH "# end of file : ",$self->{filename},"\n";
108 0           print $FH "\n";
109 0           print $FH "# Local variables:\n";
110 0           print $FH "# buffer-read-only: t\n";
111 0           print $FH "# End:\n";
112 0           close $FH;
113             }
114            
115             #
116             # 3.7 Module Declaration (inherited)
117             #
118            
119             #
120             # 3.8 Interface Declaration
121             #
122            
123             sub visitRegularInterface {
124 0     0 0   my $self = shift;
125 0           my($node) = @_;
126 0 0         if ($self->{srcname} eq $node->{filename}) {
127 0           my $version;
128 0           my $FH = $self->{out};
129 0           $self->{pkg_modif} = 0;
130 0           print $FH "#\n";
131 0           print $FH "# begin of interface ",$node->{pl_package},"\n";
132 0           print $FH "#\n";
133 0           print $FH "\n";
134 0           print $FH "package ",$node->{pl_package},";\n";
135 0           print $FH "\n";
136 0           print $FH "use CORBA::Perl::CORBA;\n";
137 0           print $FH "use Carp;\n";
138 0           print $FH "\n";
139 0           foreach (@{$node->{list_decl}}) {
  0            
140 0           my $defn = $self->_get_defn($_);
141 0 0 0       if ( $defn->isa('Operation')
142             or $defn->isa('Attributes') ) {
143 0           next;
144             }
145 0           $defn->visit($self);
146 0 0         if ($self->{pkg_modif}) {
147 0           $self->{pkg_modif} = 0;
148 0           print $FH "package ",$defn->{pl_package},";\n";
149 0           print $FH "\n";
150             }
151             }
152 0           print $FH "\n";
153 0 0         if (keys %{$node->{hash_attribute_operation}}) {
  0            
154 0           $self->{itf} = $node->{pl_name};
155 0           $self->{repos_id} = $node->{repos_id};
156 0           print $FH "###### methodes\n";
157 0           print $FH "\n";
158 0           print $FH "# constructor\n";
159 0           print $FH "sub new {\n";
160 0           print $FH "\tmy \$proto = shift;\n";
161 0           print $FH "\tmy \$class = ref(\$proto) || \$proto;\n";
162 0           print $FH "\tmy \$self = {};\n";
163 0           print $FH "\tbless \$self, \$class;\n";
164 0           print $FH "\tmy \$this = shift;\n";
165 0           print $FH "\t\$self->{_this} = \$this || 0;\n";
166 0           print $FH "\treturn \$self;\n";
167 0           print $FH "}\n";
168 0           print $FH "\n";
169 0           foreach (values %{$node->{hash_attribute_operation}}) {
  0            
170 0           $self->_get_defn($_)->visit($self);
171             }
172 0           print $FH "\n";
173             }
174 0           print $FH "#\n";
175 0           print $FH "# end of interface ",$node->{pl_package},"\n";
176 0           print $FH "#\n";
177 0           print $FH "\n";
178 0           $self->{pkg_modif} = 1;
179             }
180             else {
181 0           $self->_insert_use($node->{filename});
182             }
183             }
184            
185             sub visitAbstractInterface {
186 0     0 0   my $self = shift;
187 0           my($node) = @_;
188 0 0         if ($self->{srcname} eq $node->{filename}) {
189 0           my $version;
190 0           my $FH = $self->{out};
191 0           print $FH "#\n";
192 0           print $FH "# begin of abstract interface ",$node->{pl_package},"\n";
193 0           print $FH "#\n";
194 0           print $FH "\n";
195 0           print $FH "package ",$node->{pl_package},";\n";
196 0           print $FH "\n";
197 0           print $FH "use CORBA::Perl::CORBA;\n";
198 0           print $FH "use Carp;\n";
199 0           print $FH "\n";
200 0           foreach (@{$node->{list_decl}}) {
  0            
201 0           my $defn = $self->_get_defn($_);
202 0 0 0       if ( $defn->isa('Operation')
203             or $defn->isa('Attributes') ) {
204 0           next;
205             }
206 0           $defn->visit($self);
207             }
208 0           print $FH "\n";
209 0           print $FH "#\n";
210 0           print $FH "# end of abstract interface ",$node->{pl_package},"\n";
211 0           print $FH "#\n";
212 0           print $FH "\n";
213 0           $self->{pkg_modif} = 1;
214             }
215             else {
216 0           $self->_insert_use($node->{filename});
217             }
218             }
219            
220             #
221             # 3.9 Value Declaration (inherited)
222             #
223            
224             #
225             # 3.10 Constant Declaration (inherited)
226             #
227            
228             #
229             # 3.11 Type Declaration (inherited)
230             #
231            
232             #
233             # 3.12 Exception Declaration (inherited)
234             #
235            
236             #
237             # 3.13 Operation Declaration
238             #
239            
240             sub visitOperation {
241 0     0 0   my $self = shift;
242 0           my($node) = @_;
243 0           $self->{has_methods} = 1;
244 0           my $FH = $self->{out};
245 0           print $FH "# ",$self->{itf},"::",$node->{pl_name},"\n";
246 0           print $FH "sub ",$node->{pl_name}," {\n";
247 0           print $FH "\tmy \$self = shift;\n";
248 0           print $FH "\tmy \$_this = 0;\n";
249 0           print $FH "\t\$_this = \$self->{_this} if (ref \$self and \$self->isa('",$node->{pl_package},"'));\n";
250 0           foreach (@{$node->{list_param}}) { # paramater
  0            
251 0 0         if ($_->{attr} eq 'in') {
252 0           print $FH "\tmy \$",$_->{pl_name}," = shift;\n";
253 0           print $FH "\tcroak \"undefined parameter '",$_->{pl_name},"' in '",$node->{pl_name},"'.\\n\"\n";
254 0           print $FH "\t\t\tunless (defined \$",$_->{pl_name},");\n";
255             }
256 0 0         if ($_->{attr} eq 'inout') {
257 0           print $FH "\tmy \$r_",$_->{pl_name}," = shift;\n";
258 0           print $FH "\tcroak \"undefined parameter '",$_->{pl_name},"' in '",$node->{pl_name},"'.\\n\"\n";
259 0           print $FH "\t\t\tunless (defined \$r_",$_->{pl_name},");\n";
260             }
261             }
262 0           print $FH "\n";
263 0           print $FH "\tmy \$_is = q{};\n";
264 0           foreach (@{$node->{list_param}}) { # paramater
  0            
265 0           my $type = $self->_get_defn($_->{type});
266 0 0         if ($_->{attr} eq 'in') {
    0          
267 0           print $FH "\t",$type->{pl_package},"::",$type->{pl_name},"__marshal";
268 0           print $FH "(\\\$_is,\$",$_->{pl_name},");\n";
269             }
270             elsif ($_->{attr} eq 'inout') {
271 0           print $FH "\t",$type->{pl_package},"::",$type->{pl_name},"__marshal";
272 0           print $FH "(\\\$_is,\${\$r_",$_->{pl_name},"});\n";
273             }
274             }
275 0 0         print $FH "\tmy \$_os = '';\n"
276             unless (exists $node->{modifier});
277 0           print $FH "\n";
278 0 0         if (exists $node->{modifier}) { # oneway
279 0           print $FH "\t",$node->{pl_package},"::cdr_",$node->{pl_name},"(\$_this,\$_is);\n";
280             }
281             else {
282 0           print $FH "\tmy \$_ret = ",$node->{pl_package},"::cdr_",$node->{pl_name},"(\$_this,\$_is,\$_os);\n";
283 0           print $FH "\tif (\$_ret <= 0) {\n";
284 0           print $FH "\t\tthrow CORBA::Perl::CORBA::SystemException(\n";
285 0           print $FH "\t\t\t\t_repos_id => 'IDL:CORBA/NO_MEMORY:1.0',\n";
286 0           print $FH "\t\t\t\tminor => 3,\n";
287 0           print $FH "\t\t\t\tcompleted => CORBA::Perl::CORBA::COMPLETED_MAYBE\n";
288 0           print $FH "\t\t);\n";
289 0           print $FH "\t}\n";
290 0           print $FH "\tmy \$_offset = 0;\n";
291 0           print $FH "\tmy \$_endian = 1;\n";
292 0           print $FH "\tmy \$_status = CORBA::Perl::CORBA::exception_type__demarshal(\\\$_os,\\\$_offset,\$_endian);\n";
293 0           print $FH "\tif (\$_status eq CORBA::Perl::CORBA::NO_EXCEPTION) {\n";
294 0           my $nb = 0;
295 0           my $type = $self->_get_defn($node->{type});
296 0 0         unless ($type->isa('VoidType')) {
297 0           print $FH "\t\tmy \$_return = ";
298 0           print $FH $type->{pl_package},"::",$type->{pl_name};
299 0           print $FH "__demarshal(\\\$_os,\\\$_offset,\$_endian);\n";
300 0           $nb ++;
301             }
302 0           foreach (@{$node->{list_param}}) { # paramater
  0            
303 0           $type = $self->_get_defn($_->{type});
304 0 0 0       if ( $_->{attr} eq 'inout'
305             or $_->{attr} eq 'out' ) {
306 0           print $FH "\t\tmy \$",$_->{pl_name}," = ";
307 0           print $FH $type->{pl_package},"::",$type->{pl_name};
308 0           print $FH "__demarshal(\\\$_os,\\\$_offset,\$_endian);\n";
309 0 0         $nb ++ if ($_->{attr} eq 'out');
310             }
311             }
312 0           foreach (@{$node->{list_param}}) { # paramater
  0            
313 0 0         if ($_->{attr} eq 'inout') {
314 0           print $FH "\t\t\${\$r_",$_->{pl_name},"} = \$",$_->{pl_name},";\n";
315             }
316             }
317 0           print $FH "\t\treturn";
318 0 0         print $FH " " if ($nb > 0);
319 0 0         print $FH "(" if ($nb > 1);
320 0           my $first = 1;
321 0           $type = $self->_get_defn($node->{type});
322 0 0         unless ($type->isa('VoidType')) {
323 0           print $FH "\$_return";
324 0           $first = 0;
325             }
326 0           foreach (@{$node->{list_param}}) { # paramater
  0            
327 0 0         if ($_->{attr} eq 'out') {
328 0 0         print $FH ", " unless ($first);
329 0           print $FH "\$",$_->{pl_name};
330 0           $first = 0;
331             }
332             }
333 0 0         print $FH ")" if ($nb > 1);
334 0           print $FH ";\n";
335 0           print $FH "\t}\n";
336 0           print $FH "\telsif (\$_status eq CORBA::Perl::CORBA::USER_EXCEPTION) {\n";
337 0           print $FH "\t\tmy \$_exception_id = CORBA::Perl::CORBA::string__demarshal(\\\$_os,\\\$_offset,\$_endian);\n";
338 0           print $FH "\t\tif (0) {\n";
339 0           foreach (@{$node->{list_raise}}) {
  0            
340 0           my $defn = $self->_get_defn($_);
341 0           print $FH "\t\t}\n";
342 0           print $FH "\t\telsif (\$_exception_id eq \"",$defn->{repos_id},"\") {\n";
343 0           print $FH "\t\t\tmy \$_value = ";
344 0           print $FH $defn->{pl_package},"::",$defn->{pl_name};
345 0           print $FH "__demarshal(\\\$_os,\\\$_offset,\$_endian);\n";
346 0           print $FH "\t\t\tthrow ",$defn->{pl_package},"::",$defn->{pl_name},"(\n";
347 0           print $FH "\t\t\t\t\t_repos_id => \$_exception_id,\n";
348 0           print $FH "\t\t\t\t\t\%{\$_value}\n";
349 0           print $FH "\t\t\t);\n";
350             }
351 0           print $FH "\t\t}\n";
352 0           print $FH "\t\telse {\n";
353 0           print $FH "\t\t\twarn \"unknown user exception \$_exception_id.\\n\";\n";
354 0           print $FH "\t\t}\n";
355 0           print $FH "\t}\n";
356 0           print $FH "\telsif (\$_status eq CORBA::Perl::CORBA::SYSTEM_EXCEPTION) {\n";
357 0           print $FH "\t\tmy \$_exception_id = CORBA::Perl::CORBA::string__demarshal(\\\$_os,\\\$_offset,\$_endian);\n";
358 0           print $FH "\t\tmy \$_minor_code_value = CORBA::Perl::CORBA::unsigned_long__demarshal(\\\$_os,\\\$_offset,\$_endian);\n";
359 0           print $FH "\t\tmy \$_completion_status = CORBA::Perl::CORBA::completion_status__demarshal(\\\$_os,\\\$_offset,\$_endian);\n";
360 0           print $FH "\t\tthrow CORBA::Perl::CORBA::SystemException(\n";
361 0           print $FH "\t\t\t\t_repos_id => \$_exception_id,\n";
362 0           print $FH "\t\t\t\tminor => \$_minor_code_value,\n";
363 0           print $FH "\t\t\t\tcompleted => \$_completion_status\n";
364 0           print $FH "\t\t);\n";
365 0           print $FH "\t}\n";
366 0           print $FH "\telse {\n";
367 0           print $FH "\t\twarn \"reply status \$_status.\\n\";\n";
368 0           print $FH "\t}\n";
369             }
370 0           print $FH "}\n";
371 0           print $FH "\n";
372             }
373            
374             #
375             # 3.14 Attribute Declaration (inherited)
376             #
377            
378             1;
379