File Coverage

blib/lib/RPerl/CodeBlock/Subroutine/Method.pm
Criterion Covered Total %
statement 171 171 100.0
branch n/a
condition n/a
subroutine 57 57 100.0
pod n/a
total 228 228 100.0


line stmt bran cond sub pod time code
1             # [[[ HEADER ]]]
2             package RPerl::CodeBlock::Subroutine::Method;
3 9     9   58 use strict;
  9         21  
  9         213  
4 9     9   43 use warnings;
  9         21  
  9         199  
5 9     9   48 use RPerl::AfterSubclass;
  9         19  
  9         1167  
6             our $VERSION = 0.006_000;
7              
8             # [[[ OO INHERITANCE ]]]
9 9     9   62 use parent qw(RPerl::CodeBlock::Subroutine);
  9         20  
  9         65  
10 9     9   499 use RPerl::CodeBlock::Subroutine;
  9         25  
  9         257  
11              
12             # [[[ CRITICS ]]]
13             ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
14             ## no critic qw(Capitalization ProhibitMultiplePackages ProhibitReusedNames) # SYSTEM DEFAULT 3: allow multiple & lower case package names
15              
16             # [[[ INCLUDES ]]]
17 9     9   5860 use Storable qw(dclone);
  9         24963  
  9         9112  
18              
19             # [[[ OO PROPERTIES ]]]
20             our hashref $properties = {};
21              
22             # [[[ SUBROUTINES & OO METHODS ]]]
23              
24             our string_hashref::method $ast_to_rperl__generate = sub {
25             ( my object $self, my string_hashref $modes) = @_;
26             my string_hashref $rperl_source_group = { PMC => q{} };
27             my string_hashref $rperl_source_subgroup;
28              
29             # RPerl::diag( 'in Method->ast_to_rperl__generate(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
30              
31             # unwrap Method_71 from SubroutineOrMethod_77
32             if ( ( ref $self ) eq 'SubroutineOrMethod_77' ) {
33             $self = $self->{children}->[0];
34             }
35              
36             if ( ( ref $self ) ne 'Method_71' ) {
37             die RPerl::Parser::rperl_rule__replace(
38             'ERROR ECOGEASRP00, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: Grammar rule ' . ( ref $self ) . ' found where Method_71 expected, dying' )
39             . "\n";
40             }
41              
42             my string $our = $self->{children}->[0];
43             my string $return_type = $self->{children}->[1];
44             my string $name = $self->{children}->[2];
45             my string $equal_sub = $self->{children}->[3];
46             my object $arguments_optional = $self->{children}->[4];
47             my object $operations_star = $self->{children}->[5];
48             my string $right_brace = $self->{children}->[6];
49             my string $semicolon = $self->{children}->[7];
50              
51             if ((substr $name, 1, 1) eq '_') {
52             die 'ERROR ECOGEASRP09, CODE GENERATOR, ABSTRACT SYNTAX TO RPERL: method name ' . ($name)
53             . ' must not start with underscore, dying' . "\n";
54             }
55              
56             # CREATE SYMBOL TABLE ENTRY
57             $modes->{_symbol_table}->{_subroutine} = $name; # set current subroutine/method
58             $modes->{_symbol_table}->{$modes->{_symbol_table}->{_namespace}}->{_global}->{$name} = {isa => 'RPerl::CodeBlock::Subroutine::Method', type => $return_type}; # create individual symtab entry
59            
60             $rperl_source_group->{PMC} .= $our . q{ } . $return_type . q{ } . $name . q{ } . $equal_sub . "\n";
61              
62             if ( exists $arguments_optional->{children}->[0] ) {
63             $rperl_source_subgroup = $arguments_optional->{children}->[0]->ast_to_rperl__generate($modes);
64             RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup );
65             }
66              
67             foreach my object $operation ( @{ $operations_star->{children} } ) {
68             $rperl_source_subgroup = $operation->ast_to_rperl__generate($modes);
69             RPerl::Generator::source_group_append( $rperl_source_group, $rperl_source_subgroup );
70             }
71              
72             $rperl_source_group->{PMC} .= $right_brace . $semicolon . "\n\n";
73             return $rperl_source_group;
74             };
75              
76             our string_hashref::method $ast_to_cpp__generate__CPPOPS_PERLTYPES = sub {
77             ( my object $self, my string_hashref $modes) = @_;
78             my string_hashref $cpp_source_group = { CPP => q{// <<< RP::CB::S::M __DUMMY_SOURCE_CODE CPPOPS_PERLTYPES >>>} . "\n" };
79              
80             #...
81             return $cpp_source_group;
82             };
83              
84             our string_hashref::method $ast_to_cpp__generate_declaration__CPPOPS_CPPTYPES = sub {
85             ( my object $self, my string_hashref $modes) = @_;
86             # RPerl::diag( 'in Method->ast_to_cpp__generate_declaration__CPPOPS_CPPTYPES(), received $modes->{_symbol_table} = ' . "\n" . Dumper($modes->{_symbol_table}) . "\n");
87              
88             my string_hashref $cpp_source_group = { H => q{} };
89              
90             # RPerl::diag( 'in Method->ast_to_cpp__generate_declaration__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
91              
92             $self = $self->{children}->[0]; # unwrap Method_71 from SubroutineOrMethod_77
93             my string $return_type = $self->{children}->[1];
94             my string $name = $self->{children}->[2];
95             my object $arguments_optional = $self->{children}->[4];
96              
97             substr $name, 0, 1, q{}; # remove leading $ sigil
98             substr $return_type, -8, 8, ''; # strip trailing '::method'
99            
100             # RPerl::diag( 'in Method->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $name = ' . $name . "\n" );
101             # RPerl::diag( 'in Method->ast_to_cpp__generate__CPPOPS_CPPTYPES(), have $arguments_optional = ' . "\n" . RPerl::Parser::rperl_ast__dump($arguments_optional) . "\n" );
102              
103             if ((substr $name, 0, 1) eq '_') {
104             die 'ERROR ECOGEASCP09, CODE GENERATOR, ABSTRACT SYNTAX TO C++: method name ' . ($name)
105             . ' must not start with underscore, dying' . "\n";
106             }
107              
108             # CREATE SYMBOL TABLE ENTRY
109             $modes->{_symbol_table}->{_subroutine} = $name; # set current subroutine/method
110             $modes->{_symbol_table}->{$modes->{_symbol_table}->{_namespace}}->{_global}->{$name} = {isa => 'RPerl::CodeBlock::Subroutine::Method', type => $return_type}; # create individual symtab entry
111              
112             $return_type = RPerl::Generator::type_convert_perl_to_cpp($return_type, 1); # $pointerify_classes = 1
113             $modes->{_symbol_table}->{$modes->{_symbol_table}->{_namespace}}->{_global}->{$name}->{type_cpp} = $return_type; # add converted C++ type to symtab entry
114              
115             $cpp_source_group->{H} .= q{ } . $return_type . q{ } . $name . '(';
116             if ( exists $arguments_optional->{children}->[0] ) {
117             my object $arguments = $arguments_optional->{children}->[0];
118             my string_hashref $cpp_source_subgroup = $arguments->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
119             $cpp_source_group->{H} .= $cpp_source_subgroup->{CPP};
120             }
121             $cpp_source_group->{H} .= ');';
122              
123             return $cpp_source_group;
124             };
125              
126             our string_hashref::method $ast_to_cpp__generate__CPPOPS_CPPTYPES = sub {
127             ( my object $self, my string $package_name_underscores, my string_hashref $modes) = @_;
128             # RPerl::diag( 'in Method->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $modes->{_symbol_table} = ' . "\n" . Dumper($modes->{_symbol_table}) . "\n");
129              
130             my string_hashref $cpp_source_group = { CPP => q{} };
131             my string_hashref $cpp_source_subgroup;
132              
133             # RPerl::diag( 'in Method->ast_to_cpp__generate__CPPOPS_CPPTYPES(), received $self = ' . "\n" . RPerl::Parser::rperl_ast__dump($self) . "\n" );
134              
135             # unwrap Method_71 from SubroutineOrMethod_77
136             if ( ( ref $self ) eq 'SubroutineOrMethod_77' ) {
137             $self = $self->{children}->[0];
138             }
139              
140             if ( ( ref $self ) ne 'Method_71' ) {
141             die RPerl::Parser::rperl_rule__replace(
142             'ERROR ECOGEASCP00, CODE GENERATOR, ABSTRACT SYNTAX TO C++: Grammar rule ' . ( ref $self ) . ' found where Method_71 expected, dying' )
143             . "\n";
144             }
145              
146             my string $return_type = $self->{children}->[1];
147             my string $name = $self->{children}->[2];
148             my object $arguments_optional = $self->{children}->[4];
149             my object $operations_star = $self->{children}->[5];
150            
151             substr $name, 0, 1, q{}; # remove leading $ sigil
152             substr $return_type, -8, 8, ''; # strip trailing '::method'
153              
154             $return_type = RPerl::Generator::type_convert_perl_to_cpp($return_type, 1); # $pointerify_classes = 1
155             $cpp_source_group->{CPP} .= $return_type . q{ } . $package_name_underscores . '::' . $name . '(';
156              
157             if ( exists $arguments_optional->{children}->[0] ) {
158             $cpp_source_subgroup = $arguments_optional->{children}->[0]->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
159             RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup );
160             }
161              
162             $cpp_source_group->{CPP} .= ') {' . "\n";
163             my string $CPP_saved = $cpp_source_group->{CPP};
164             $cpp_source_group->{CPP} = q{};
165              
166             foreach my object $operation ( @{ $operations_star->{children} } ) {
167             $cpp_source_subgroup = $operation->ast_to_cpp__generate__CPPOPS_CPPTYPES($modes);
168             RPerl::Generator::source_group_append( $cpp_source_group, $cpp_source_subgroup );
169             }
170              
171             # COMPILE-TIME OPTIMIZATION #02: declare all loop iterators at top of subroutine/method to avoid re-declarations in nested loops
172             if ((exists $modes->{_loop_iterators}) and (defined $modes->{_loop_iterators})) {
173             foreach my string $loop_iterator_symbol (sort keys %{$modes->{_loop_iterators}}) {
174             $CPP_saved .= $modes->{_loop_iterators}->{$loop_iterator_symbol} . q{ } . $loop_iterator_symbol . ';' . "\n";
175             }
176             delete $modes->{_loop_iterators};
177             }
178            
179             $CPP_saved .= $cpp_source_group->{CPP};
180             $cpp_source_group->{CPP} = $CPP_saved;
181              
182             $cpp_source_group->{CPP} .= '}';
183             return $cpp_source_group;
184             };
185              
186             # [[[ TYPES & SUBTYPES BELOW THIS LINE ]]]
187              
188             # a method is a subroutine belonging to a class or object
189             package # hide from PAUSE indexing
190             method;
191 9     9   104 use strict;
  9         23  
  9         322  
192 9     9   79 use warnings;
  9         27  
  9         379  
193 9     9   53 use parent qw(RPerl::CodeBlock::Subroutine::Method);
  9         21  
  9         56  
194              
195             # [[[ SCALAR & SCALAR REF METHODS ]]]
196              
197             # method with void return type
198             package # hide from PAUSE indexing
199             void::method;
200 9     9   1031 use strict;
  9         25  
  9         201  
201 9     9   53 use warnings;
  9         21  
  9         280  
202 9     9   47 use parent -norequire, qw(method);
  9         22  
  9         652  
203              
204             # method with integer return type
205             package # hide from PAUSE indexing
206             integer::method;
207 9     9   501 use strict;
  9         20  
  9         224  
208 9     9   46 use warnings;
  9         20  
  9         263  
209 9     9   48 use parent -norequire, qw(method);
  9         16  
  9         44  
210              
211             # method with number return type
212             package # hide from PAUSE indexing
213             number::method;
214 9     9   419 use strict;
  9         17  
  9         158  
215 9     9   39 use warnings;
  9         19  
  9         283  
216 9     9   52 use parent -norequire, qw(method);
  9         26  
  9         50  
217              
218             # method with character return type
219             package # hide from PAUSE indexing
220             character::method;
221 9     9   516 use strict;
  9         20  
  9         162  
222 9     9   54 use warnings;
  9         16  
  9         251  
223 9     9   44 use parent -norequire, qw(method);
  9         21  
  9         44  
224              
225             # method with string return type
226             package # hide from PAUSE indexing
227             string::method;
228 9     9   402 use strict;
  9         21  
  9         170  
229 9     9   40 use warnings;
  9         24  
  9         243  
230 9     9   52 use parent -norequire, qw(method);
  9         21  
  9         47  
231              
232             # method with scalartype return type
233             package # hide from PAUSE indexing
234             scalartype::method;
235 9     9   452 use strict;
  9         24  
  9         182  
236 9     9   40 use warnings;
  9         17  
  9         232  
237 9     9   46 use parent -norequire, qw(method);
  9         19  
  9         50  
238              
239             # method with unknown return type
240             package # hide from PAUSE indexing
241             unknown::method;
242 9     9   417 use strict;
  9         21  
  9         239  
243 9     9   44 use warnings;
  9         18  
  9         295  
244 9     9   55 use parent -norequire, qw(method);
  9         21  
  9         44  
245              
246             # [[[ HASH METHODS ]]]
247              
248             package # hide from PAUSE indexing
249             integer_hashref::method;
250 9     9   432 use strict;
  9         19  
  9         187  
251 9     9   49 use warnings;
  9         25  
  9         263  
252 9     9   53 use parent -norequire, qw(method);
  9         26  
  9         48  
253              
254             package # hide from PAUSE indexing
255             number_hashref::method;
256 9     9   430 use strict;
  9         24  
  9         153  
257 9     9   44 use warnings;
  9         18  
  9         254  
258 9     9   56 use parent -norequire, qw(method);
  9         27  
  9         52  
259              
260             package # hide from PAUSE indexing
261             string_hashref::method;
262 9     9   453 use strict;
  9         19  
  9         151  
263 9     9   37 use warnings;
  9         25  
  9         225  
264 9     9   46 use parent -norequire, qw(method);
  9         19  
  9         44  
265              
266             package # hide from PAUSE indexing
267             object_hashref::method;
268 9     9   445 use strict;
  9         24  
  9         155  
269 9     9   43 use warnings;
  9         25  
  9         270  
270 9     9   52 use parent -norequire, qw(method);
  9         18  
  9         44  
271              
272             package # hide from PAUSE indexing
273             hashref_hashref::method;
274 9     9   444 use strict;
  9         18  
  9         136  
275 9     9   39 use warnings;
  9         25  
  9         269  
276 9     9   44 use parent -norequire, qw(method);
  9         18  
  9         40  
277              
278             # [[[ ARRAY METHODS ]]]
279              
280             package # hide from PAUSE indexing
281             integer_arrayref::method;
282 9     9   418 use strict;
  9         22  
  9         182  
283 9     9   43 use warnings;
  9         24  
  9         244  
284 9     9   45 use parent -norequire, qw(method);
  9         21  
  9         46  
285              
286             package # hide from PAUSE indexing
287             number_arrayref::method;
288 9     9   417 use strict;
  9         22  
  9         150  
289 9     9   45 use warnings;
  9         18  
  9         217  
290 9     9   42 use parent -norequire, qw(method);
  9         16  
  9         37  
291              
292             package # hide from PAUSE indexing
293             string_arrayref::method;
294 9     9   366 use strict;
  9         18  
  9         121  
295 9     9   35 use warnings;
  9         21  
  9         207  
296 9     9   58 use parent -norequire, qw(method);
  9         17  
  9         47  
297              
298             package # hide from PAUSE indexing
299             arrayref_arrayref::method;
300 9     9   404 use strict;
  9         44  
  9         153  
301 9     9   34 use warnings;
  9         20  
  9         238  
302 9     9   46 use parent -norequire, qw(method);
  9         19  
  9         42  
303              
304             1;