File Coverage

gen/attr-PerlBean_Attribute_Multi.pl
Criterion Covered Total %
statement 3 3 100.0
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 4 4 100.0


line stmt bran cond sub pod time code
1 1     1   4 use strict;
  1         2  
  1         188  
2              
3             push(@::bean_desc, {
4             bean_opt => {
5             abstract => 'MULTI bean attribute abstraction',
6             package => 'PerlBean::Attribute::Multi',
7             use_perl_version => 5.005,
8             base => [ qw(PerlBean::Attribute::Single)],
9             description => <
10             C is a subclass of C and it's only function is to group the MULTI attribute classes.
11             EOF
12             short_description => 'contains MULTI bean attribute information',
13             synopsis => "None. This is an abstract class.\n",
14             },
15             attr_opt => [
16             ],
17             meth_opt => [
18             {
19             method_name => 'mk_doc_clauses_allow_isa',
20             documented => 0,
21             body => <<'THE_EOF',
22             my $self = shift;
23              
24             # Return empty string if no values_allow_isa
25             return('') if ( ! scalar( $self->values_allow_isa() ) );
26              
27             # Make clauses head
28             my $clauses = <
29             \=item The values in C must be a (sub)class of:
30              
31             \=over
32              
33             EOF
34              
35             # Make clauses body
36             foreach my $class ( sort( $self->values_allow_isa() ) ) {
37             $clauses .= <
38             \=item ${class}
39              
40             EOF
41             }
42              
43             # Make clauses tail
44             $clauses .= <
45             \=back
46              
47             EOF
48              
49             # Return clauses
50             return($clauses);
51             THE_EOF
52             },
53             {
54             method_name => 'mk_doc_clauses_allow_ref',
55             documented => 0,
56             body => <<'THE_EOF',
57             my $self = shift;
58              
59             # Return empty string if no values_allow_ref
60             return('') if ( ! scalar( $self->values_allow_ref() ) );
61              
62             # Make $or for other clauses that apply and that are written before these
63             # clauses
64             my $or = scalar( $self->values_allow_isa() ) ? 'Or, the' : 'The';
65              
66             # Make clauses head
67             my $clauses = <
68             \=item ${or} values in C must be a reference of:
69              
70             \=over
71              
72             EOF
73              
74             # Make clauses body
75             foreach my $class ( sort( $self->values_allow_ref() ) ) {
76             $clauses .= <
77             \=item ${class}
78              
79             EOF
80             }
81              
82             # Make clauses tail
83             $clauses .= <
84             \=back
85              
86             EOF
87              
88             # Return clauses
89             return($clauses);
90             THE_EOF
91             },
92             {
93             method_name => 'mk_doc_clauses_allow_rx',
94             documented => 0,
95             body => <<'THE_EOF',
96             my $self = shift;
97              
98             # Return empty string if no values_allow_rx
99             return('') if ( ! scalar( $self->values_allow_rx() ) );
100              
101             # Make $or for other clauses that apply and that are written before these
102             # clauses
103             my $or = scalar( $self->values_allow_isa() || $self->values_allow_ref() ) ?
104             'Or, the' : 'The';
105              
106             # Make clauses head
107             my $clauses = <
108             \=item ${or} values in C must match regular expression:
109              
110             \=over
111              
112             EOF
113              
114             # Make clauses body
115             foreach my $class ( sort( $self->values_allow_rx() ) ) {
116             $clauses .= <
117             \=item ${class}
118              
119             EOF
120             }
121              
122             # Make clauses tail
123             $clauses .= <
124             \=back
125              
126             EOF
127              
128             # Return clauses
129             return($clauses);
130             THE_EOF
131             },
132             {
133             method_name => 'mk_doc_clauses_allow_value',
134             documented => 0,
135             body => <<'THE_EOF',
136             my $self = shift;
137              
138             # Return empty string if no values_allow_value
139             return('') if ( ! scalar( $self->values_allow_value() ) );
140              
141             # Make $or for other clauses that apply and that are written before these
142             # clauses
143             my $or = scalar( $self->values_allow_isa() || $self->values_allow_ref() ||
144             $self->values_allow_rx() ) ? 'Or, the' : 'The';
145              
146             # Make clauses head
147             my $clauses = <
148             \=item ${or} values in C must be a one of:
149              
150             \=over
151              
152             EOF
153              
154             # Make clauses body
155             foreach my $val ( sort( $self->values_allow_value() ) ) {
156             $clauses .= <
157             \=item ${val}
158              
159             EOF
160             }
161              
162             # Make clauses tail
163             $clauses .= <
164             \=back
165              
166             EOF
167              
168             # Return clauses
169             return($clauses);
170             THE_EOF
171             },
172             {
173             method_name => 'create_methods',
174             interface => 1,
175             },
176             {
177             method_name => 'write_default_value',
178             body => <<'THE_EOF',
179             my $self = shift;
180              
181             defined( $self->get_default_value() ) || return('');
182              
183             my $an = $self->_esc_aq( $self->get_method_factory_name() );
184             my $dv = $self->_esc_aq( @{ $self->get_default_value() } );
185              
186             return( "${IND}$an${AO}=>${AO}\[$dv],\n" );
187             THE_EOF
188             },
189             {
190             method_name => 'write_constructor_option_code',
191             body => <<'THE_EOF',
192             my $self = shift;
193              
194             my $an = $self->get_method_factory_name();
195             my $mb = $self->get_method_base();
196             my $ec = $self->get_exception_class();
197             my $pkg = $self->get_perl_bean()->get_package();
198              
199             # Comment
200             my $code = "${IND}# $an, " . $self->type();
201             $code .= $self->is_mandatory() ? ', mandatory' : '';
202             $code .= defined( $self->get_default_value() ) ? ', with default value' : '';
203             $code .= "\n";
204              
205             # is_mandatory check
206             if ( $self->is_mandatory() ) {
207             $code .= <
208             ${IND}exists${BFP}(${ACS}\$opt->{$an}${ACS})${AO}||${AO}throw $ec${BFP}("ERROR: ${pkg}::_initialize, option '$an' is mandatory.");
209             EOF
210             }
211              
212             my $pre = '';
213             if ( ! $self->is_mandatory() ) {
214             $pre .= "${IND}";
215             $code .= <
216             ${IND}if${BCP}(${ACS}exists${BFP}(${ACS}\$opt->{$an}${ACS})${ACS})${PBOC[1]}{
217             EOF
218             }
219             $code .= <
220             ${IND}${pre}ref${BFP}(${ACS}\$opt->{$an}${ACS})${AO}eq${AO}'ARRAY'${AO}||${AO}throw $ec${BFP}("ERROR: ${pkg}::_initialize, specified value for option '$an' must be an 'ARRAY' reference.");
221             ${IND}${pre}\$self->set$mb${BFP}(${ACS}\@{${ACS}\$opt->{$an}${ACS}}${ACS});
222             EOF
223             # default value
224             if ( ! $self->is_mandatory() ) {
225             if ( defined( $self->get_default_value() ) ) {
226             $code .= <
227             ${IND}}${PBCC[1]}else${PBOC[1]}{
228             ${IND}${IND}\$self->set$mb${BFP}(${ACS}\@{${ACS}\$DEFAULT_VALUE{$an}${ACS}}${ACS});
229             EOF
230             }
231             else {
232             $code .= <
233             ${IND}}${PBCC[1]}else${PBOC[1]}{
234             ${IND}${IND}\$self->set$mb${BFP}();
235             EOF
236             }
237             }
238             if ( ! $self->is_mandatory()) {
239             $code .= <
240             ${IND}}
241             EOF
242             }
243              
244             # Empty line
245             $code .= "\n";
246              
247             return($code);
248             THE_EOF
249             },
250             {
251             method_name => 'write_constructor_option_doc',
252             body => <<'THE_EOF',
253             my $self = shift;
254              
255             # Do nothing if not documented
256             $self->is_documented() || return('');
257              
258             my $an = $self->get_method_factory_name();
259             my $mb = $self->get_method_base();
260             my $mand = $self->is_mandatory() ? ' Mandatory option.' : '';
261             my $multi = ( $self->isa('PerlBean::Attribute::Multi') ) ? ' Must be an C reference.' : '';
262             my $def = '';
263             if ( defined( $self->get_default_value() ) ) {
264             my $list = join( '> , B<', $self->_esc_aq( @{ $self->get_default_value() } ) );
265             $def = ' Defaults to B<[> B<' . $list . '> B<]>.';
266             }
267              
268             return(<
269              
270             \=item B>
271              
272             Passed to L.${multi}${mand}${def}
273             EOF
274             THE_EOF
275             },
276             ],
277             sym_opt => [
278             ],
279             use_opt => [
280             {
281             dependency_name => 'PerlBean::Style',
282             import_list => [ 'qw(:codegen)' ],
283             },
284             ],
285             } );
286              
287             1;