File Coverage

gen/attr-PerlBean_Attribute_Multi_Unique_Associative_MethodKey.pl
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1 1     1   5 use strict;
  1         2  
  1         233  
2              
3             push(@::bean_desc, {
4             bean_opt => {
5             abstract => 'Unique, associative MULTI bean attribute information',
6             package => 'PerlBean::Attribute::Multi::Unique::Associative::MethodKey',
7             use_perl_version => 5.005,
8             base => [ qw(PerlBean::Attribute::Multi)],
9             description => <
10             C contains information on unique associative MULTI bean attribute that gets its key from an object method. It is a subclass of C. The code generation and documentation methods from C are implemented.
11             EOF
12             short_description => 'contains unique associative MULTI bean attribute information',
13             synopsis => &get_syn(),
14             },
15             attr_opt => [
16             {
17             method_factory_name => 'id_method',
18             type => 'SINGLE',
19             default_value => 'get_id',
20             short_description => 'the method to obtain the ID from the item in the list',
21             },
22             ],
23             meth_opt => [
24             {
25             method_name => 'create_method_add',
26             documented => 0,
27             body => <<'THE_EOF',
28             my $self = shift;
29              
30             my $an = $self->get_method_factory_name();
31             my $an_esc = $self->_esc_apos($an);
32             my $op = &{$MOF}('add');
33             my $mb = $self->get_method_base();
34             my $ec = $self->get_exception_class();
35             my $pkg = $self->get_package();
36             my $pkg_us = $self->get_package_us();
37             my $idm = $self->get_id_method();
38             my $desc = defined($self->get_short_description()) ? $self->get_short_description() : 'not described option';
39             my $exc = ' On error an exception C<' . $self->get_exception_class() . '> is thrown.';
40              
41             # Make body
42             my $body = <
43             ${IND}my \$self${AO}=${AO}shift;
44              
45             EOF
46              
47             # Check if isas/refs/rxs/values are allowed
48             $body .= <
49             ${IND}# Check if isas/refs/rxs/values are allowed
50             ${IND}\&_value_is_allowed${BFP}(${ACS}$an_esc,${AC}\@_${ACS})${AO}||${AO}throw $ec${BFP}("ERROR: ${pkg}::$op$mb, one or more specified value(s) '\@_' is/are not allowed.");
51              
52             EOF
53              
54             # Method tail
55             $body .= <
56             ${IND}# Add keys/values
57             ${IND}foreach my \$val (\@_)${PBOC[1]}{
58             ${IND}${IND}\$self->{$pkg_us}{$an}{${ACS}\$val->$idm${BFP}()${ACS}}${AO}=${AO}\$val;
59             ${IND}}
60             EOF
61              
62             # Make description
63             my $description = <
64             Add additional values on ${desc}. Each C is an object out of which the id is obtained through method C<$idm${BFP}()>. The obtained B is used to store the value and may be used for deletion and to fetch the value. 0 or more values may be supplied. Multiple occurrences of the same key yield in the last occurring key to be inserted and the rest to be ignored. Each key of the specified values is allowed to occur only once.${exc}
65             EOF
66              
67             # Add clauses to the description
68             my $clauses = $self->mk_doc_clauses();
69             if ($clauses) {
70             $description .= "\n" . $clauses;
71             }
72              
73             # Create and return the method
74             return( PerlBean::Method->new( {
75             method_name => "$op$mb",
76             parameter_description => "${ACS}\[${ACS}VALUE ...${ACS}]${ACS}",
77             documented => $self->is_documented(),
78             volatile => 1,
79             description => $description,
80             body => $body,
81             } ) );
82             THE_EOF
83             },
84             {
85             method_name => 'create_method_delete',
86             documented => 0,
87             body => <<'THE_EOF',
88             my $self = shift;
89              
90             my $an = $self->get_method_factory_name();
91             my $an_esc = $self->_esc_apos($an);
92             my $op = &{$MOF}('delete');
93             my $mb = $self->get_method_base();
94             my $ec = $self->get_exception_class();
95             my $pkg = $self->get_package();
96             my $pkg_us = $self->get_package_us();
97             my $desc = defined( $self->get_short_description() ) ? $self->get_short_description() : 'not described option';
98             my $empt = $self->is_allow_empty() ? '' : ' After deleting at least one element must remain.';
99             my $exc = ' On error an exception C<' . $self->get_exception_class() . '> is thrown.';
100              
101             # Make body
102             my $body = <
103             ${IND}my \$self${AO}=${AO}shift;
104              
105             EOF
106              
107             # Check if list value is allowed to be empty
108             if ( ! $self->is_allow_empty() ) {
109             $body .= <
110             ${IND}# List value for $an_esc is not allowed to be empty
111             ${IND}my \%would_delete${AO}=${AO}();
112             ${IND}foreach my \$val (\@_)${PBOC[1]}{
113             ${IND}${IND}\$would_delete{\$val}${AO}=${AO}\$val if${BCP}(${ACS}exists${BFP}(${ACS}\$self->{$pkg_us}{$an}{\$val}${ACS})${ACS})
114             ${IND}}
115             ${IND}(${ACS}scalar${BFP}(${ACS}keys${BFP}(${ACS}\%{${ACS}\$self->{$pkg_us}{$an}${ACS}}${ACS})${ACS})${AO}==${AO}scalar${BFP}(${ACS}keys${BFP}(\%would_delete)${ACS})${ACS})${AO}&&${AO}throw $ec${BFP}("ERROR: ${pkg}::$op$mb, list value may not be empty.");
116              
117             EOF
118             }
119              
120             # Method tail
121             $body .= <
122             ${IND}# Delete values
123             ${IND}my \$del${AO}=${AO}0;
124             ${IND}foreach my \$val (\@_)${PBOC[1]}{
125             ${IND}${IND}exists${BFP}(${ACS}\$self->{$pkg_us}{$an}{\$val}${ACS})${AO}||${AO}next;
126             ${IND}${IND}delete${BFP}(${ACS}\$self->{$pkg_us}{$an}{\$val}${ACS});
127             ${IND}${IND}\$del${AO}++;
128             ${IND}}
129             ${IND}return(\$del);
130             EOF
131              
132             # Create and return the method
133             return( PerlBean::Method->new( {
134             method_name => "$op$mb",
135             parameter_description => 'ARRAY',
136             documented => $self->is_documented(),
137             volatile => 1,
138             description => <
139             Delete elements from ${desc}.${empt} Returns the number of deleted elements.${exc}
140             EOF
141             body => $body,
142             } ) );
143             THE_EOF
144             },
145             {
146             method_name => 'create_method_exists',
147             documented => 0,
148             body => <<'THE_EOF',
149             my $self = shift;
150              
151             my $an = $self->get_method_factory_name();
152             my $op = &{$MOF}('exists');
153             my $mb = $self->get_method_base();
154             my $pkg_us = $self->get_package_us();
155             my $desc = defined( $self->get_short_description() ) ? $self->get_short_description() : 'not described option';
156              
157             # Make body
158             my $body = <
159             ${IND}my \$self${AO}=${AO}shift;
160              
161             ${IND}# Count occurrences
162             ${IND}my \$count${AO}=${AO}0;
163             ${IND}foreach my \$val (\@_)${PBOC[1]}{
164             ${IND}${IND}\$count${AO}+=${AO}exists${BFP}(${ACS}\$self->{$pkg_us}{$an}{\$val}${ACS});
165             ${IND}}
166             ${IND}return${BFP}(\$count);
167             EOF
168              
169             # Create and return the method
170             return( PerlBean::Method->new( {
171             method_name => "$op$mb",
172             parameter_description => 'ARRAY',
173             documented => $self->is_documented(),
174             volatile => 1,
175             description => <
176             Returns the count of items in C that are in ${desc}.
177             EOF
178             body => $body,
179             } ) );
180             THE_EOF
181             },
182             {
183             method_name => 'create_method_keys',
184             documented => 0,
185             body => <<'THE_EOF',
186             my $self = shift;
187              
188             my $an = $self->get_method_factory_name();
189             my $op = &{$MOF}('keys');
190             my $mb = $self->get_method_base();
191             my $pkg_us = $self->get_package_us();
192             my $desc = defined( $self->get_short_description() ) ? $self->get_short_description() : 'not described option';
193              
194             # Make body
195             my $body = <
196             ${IND}my \$self${AO}=${AO}shift;
197              
198             ${IND}# Return all keys
199             ${IND}return${BFP}(${ACS}keys${BFP}(${ACS}\%{${ACS}\$self->{$pkg_us}{$an}${ACS}}${ACS})${ACS});
200             EOF
201              
202             # Create and return the method
203             return( PerlBean::Method->new( {
204             method_name => "$op$mb",
205             documented => $self->is_documented(),
206             volatile => 1,
207             description => <
208             Returns an C containing the keys of ${desc}.
209             EOF
210             body => $body,
211             } ) );
212             THE_EOF
213             },
214             {
215             method_name => 'create_method_set',
216             documented => 0,
217             body => <<'THE_EOF',
218             my $self = shift;
219              
220             my $an = $self->get_method_factory_name();
221             my $an_esc = $self->_esc_apos($an);
222             my $op = &{$MOF}('set');
223             my $mb = $self->get_method_base();
224             my $ec = $self->get_exception_class();
225             my $pkg = $self->get_package();
226             my $pkg_us = $self->get_package_us();
227             my $idm = $self->get_id_method();
228             my $desc = defined( $self->get_short_description() ) ? $self->get_short_description() : 'not described option';
229             my $def = defined( $self->get_default_value() ) ? ' Default value at initialization is C<' . join( ', ', $self->_esc_aq ( @{ $self->get_default_value() } ) ) . '>.' : '';
230             my $empt = $self->is_allow_empty() ? '' : ' C must at least have one element.';
231             my $exc = ' On error an exception C<' . $self->get_exception_class() . '> is thrown.';
232             my $attr_overl = $self->_get_overloaded_attribute();
233             my $overl = defined($attr_overl) ? " B Methods B> are overloaded from package C<". $attr_overl->get_package() .'>.': '';
234              
235             # Make body
236             my $body = <
237             ${IND}my \$self${AO}=${AO}shift;
238              
239             EOF
240              
241             # Check if list value is allowed to be empty
242             if ( ! $self->is_allow_empty() ) {
243             $body .= <
244             ${IND}# List value for $an_esc is not allowed to be empty
245             ${IND}scalar${BFP}(\@_)${AO}||${AO}throw $ec${BFP}("ERROR: ${pkg}::$op$mb, list value may not be empty.");
246              
247             EOF
248             }
249              
250             # Check if isas/refs/rxs/values are allowed
251             $body .= <
252             ${IND}# Check if isas/refs/rxs/values are allowed
253             ${IND}\&_value_is_allowed${BFP}(${ACS}$an_esc,${AC}\@_${ACS})${AO}||${AO}throw $ec${BFP}("ERROR: ${pkg}::$op$mb, one or more specified value(s) '\@_' is/are not allowed.");
254              
255             EOF
256              
257             # Method tail
258             $body .= <
259             ${IND}# Empty list
260             ${IND}\$self->{$pkg_us}{$an}${AO}=${AO}\{};
261              
262             ${IND}# Add keys/values
263             ${IND}foreach my \$val (\@_)${PBOC[1]}{
264             ${IND}${IND}\$self->{$pkg_us}{$an}{${ACS}\$val->$idm${BFP}()${ACS}}${AO}=${AO}\$val;
265             ${IND}}
266             EOF
267              
268             # Make description
269             my $description = <
270             Set ${desc} absolutely using values. Each C is an object out of which the id is obtained through method C<$idm${BFP}()>. The obtained B is used to store the value and may be used for deletion and to fetch the value. 0 or more values may be supplied. Multiple occurrences of the same key yield in the last occurring key to be inserted and the rest to be ignored. Each key of the specified values is allowed to occur only once.${def}${empt}${exc}${overl}
271             EOF
272              
273             # Add clauses to the description
274             my $clauses = $self->mk_doc_clauses();
275             if ($clauses) {
276             $description .= "\n" . $clauses;
277             }
278              
279             # Create and return the method
280             return( PerlBean::Method->new( {
281             method_name => "$op$mb",
282             parameter_description => "${ACS}\[${ACS}VALUE ...${ACS}]${ACS}",
283             documented => $self->is_documented(),
284             volatile => 1,
285             description => $description,
286             body => $body,
287             } ) );
288             THE_EOF
289             },
290             {
291             method_name => 'create_method_values',
292             documented => 0,
293             body => <<'THE_EOF',
294             my $self = shift;
295              
296             my $an = $self->get_method_factory_name();
297             my $op = &{$MOF}('values');
298             my $mb = $self->get_method_base();
299             my $pkg_us = $self->get_package_us();
300             my $desc = defined( $self->get_short_description() ) ? $self->get_short_description() : 'not described option';
301              
302             # Make body
303             my $body = <
304             ${IND}my \$self${AO}=${AO}shift;
305              
306             ${IND}if${BCP}(${ACS}scalar(\@_)${ACS})${PBOC[1]}{
307             ${IND}${IND}my \@ret${AO}=${AO}();
308             ${IND}${IND}foreach my \$key (\@_)${PBOC[2]}{
309             ${IND}${IND}${IND}exists${BFP}(${ACS}\$self->{$pkg_us}{$an}{\$key}${ACS})${AO}&&${AO}push${BFP}(${ACS}\@ret,${AC}\$self->{$pkg_us}{$an}{\$key}${ACS});
310             ${IND}${IND}}
311             ${IND}${IND}return${BFP}(\@ret);
312             ${IND}}${PBCC[1]}else${PBOC[1]}{
313             ${IND}${IND}# Return all values
314             ${IND}${IND}return${BFP}(${ACS}values${BFP}(${ACS}\%{${ACS}\$self->{$pkg_us}{$an}${ACS}}${ACS})${ACS});
315             ${IND}}
316             EOF
317              
318             # Create and return the method
319             return( PerlBean::Method->new( {
320             method_name => "$op$mb",
321             parameter_description => "${ACS}\[${ACS}KEY_ARRAY${ACS}]${ACS}",
322             documented => $self->is_documented(),
323             volatile => 1,
324             description => <
325             Returns an C containing the values of ${desc}. If C contains one or more Cs the values related to the Cs are returned. If no Cs specified all values are returned.
326             EOF
327             body => $body,
328             } ) );
329             THE_EOF
330             },
331             {
332             method_name => 'create_methods',
333             description => <
334             __SUPER_POD__ Access methods are B, B, B, B, B and B.
335             EOF
336             body => <<'EOF',
337             my $self = shift;
338              
339             return(
340             $self->create_method_add(),
341             $self->create_method_delete(),
342             $self->create_method_exists(),
343             $self->create_method_keys(),
344             $self->create_method_set(),
345             $self->create_method_values(),
346             );
347             EOF
348             },
349             ],
350             sym_opt => [
351             ],
352             use_opt => [
353             {
354             dependency_name => 'PerlBean::Style',
355             import_list => [ 'qw(:codegen)' ],
356             },
357             ],
358             } );
359              
360             sub get_syn {
361 1     1   7 use IO::File;
  1         2  
  1         197  
362             my $fh = IO::File->new('< syn-PerlBean_Attribute_Multi_Unique_Associative_MethodKey.pl');
363             $fh = IO::File->new('< gen/syn-PerlBean_Attribute_Multi_Unique_Associative_MethodKey.pl') if (! defined($fh));
364             my $syn = '';
365             my $prev_line = $fh->getline ();
366             while (my $line = $fh->getline ()) {
367             $syn .= ' ' . $prev_line;
368             $prev_line = $line;
369             }
370             return($syn);
371             }
372              
373             1;