File Coverage

gen/attr-PerlBean_Method.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         250  
2              
3             push(@::bean_desc, {
4             bean_opt => {
5             abstract => 'Abstract PerlBean method information',
6             package => 'PerlBean::Method',
7             use_perl_version => 5.005,
8             description => <
9             C class for bean method information.
10             EOF
11             short_description => 'contains bean method information',
12             #synopsis => '???',
13             },
14             attr_opt => [
15             {
16             method_factory_name => 'body',
17             type => 'SINGLE',
18             allow_rx => [qw(.*)],
19             short_description => 'the method\'s body',
20             },
21             {
22             method_factory_name => 'exception_class',
23             type => 'SINGLE',
24             allow_empty => 0,
25             default_value => 'Error::Simple',
26             short_description => 'the class to throw in eventual interface implementations',
27             },
28             {
29             method_factory_name => 'interface',
30             type => 'BOOLEAN',
31             short_description => 'the method is defined as interface',
32             },
33             {
34             method_factory_name => 'method_name',
35             type => 'SINGLE',
36             mandatory => 1,
37             allow_empty => 0,
38             allow_rx => [qw(^\w+$)],
39             short_description => 'the method\'s name',
40             },
41             {
42             method_factory_name => 'parameter_description',
43             type => 'SINGLE',
44             short_description => 'the parameter description',
45             },
46             {
47             method_factory_name => 'perl_bean',
48             type => 'SINGLE',
49             allow_isa => [qw(PerlBean)],
50             short_description => 'the PerlBean to which this method belongs',
51             },
52             {
53             method_factory_name => 'description',
54             type => 'SINGLE',
55             short_description => 'the method description',
56             },
57             {
58             method_factory_name => 'documented',
59             type => 'BOOLEAN',
60             default_value => 1,
61             short_description => 'the method is documented',
62             },
63             {
64             method_factory_name => 'implemented',
65             type => 'BOOLEAN',
66             default_value => 1,
67             short_description => 'the method is implemented',
68             },
69             {
70             method_factory_name => 'volatile',
71             type => 'BOOLEAN',
72             short_description => 'the method is volatile',
73             },
74             ],
75             meth_opt => [
76             {
77             method_name => 'write_code',
78             parameter_description => 'FILEHANDLE',
79             description => <
80             Write the code for the method to C. C is an C object. On error an exception C is thrown.
81             EOF
82             body => <<'THE_EOF',
83             my $self = shift;
84             my $fh = shift;
85              
86             # Do nothing if not implemented
87             $self->is_implemented() || return;
88              
89             my $name = $self->get_method_name();
90             my $ec = $self->get_exception_class();
91             my $body = $self->is_interface() ?
92             "${IND}throw $ec${BFP}(\"ERROR: " .
93             $self->get_package() .
94             '::' .
95             $self->get_method_name() .
96             ", call this method in a subclass that has implemented it.\");\n"
97             : '';
98             $body = defined( $self->get_body() ) ? $self->get_body() : $body;
99             $fh->print(<
100             $SUB $name${PBOC[0]}{
101             $body}
102              
103             EOF
104             THE_EOF
105             },
106             {
107             method_name => 'write_pod',
108             parameter_description => 'FILEHANDLE',
109             description => <
110             Write the documentation for the method to C. C is an C object. On error an exception C is thrown.
111             EOF
112             body => <<'THE_EOF',
113             my $self = shift;
114             my $fh = shift;
115             my $pkg = shift;
116              
117             # Do nothing if not documented
118             $self->is_documented() || return;
119              
120             my $name = $self->get_method_name();
121             my $pre = '';
122             my $par = $self->get_parameter_description();
123             my $desc = $self->get_description() || "\n";;
124             if ( $pkg eq $self->get_package() ) {
125             if ( $self->is_interface() ) {
126             $pre = "This is an interface method. ";
127             }
128             else {
129             my $super_meth = $self->_get_super_method();
130             if ( defined($super_meth) ) {
131             if ( $super_meth->is_interface() ) {
132             $pre = "This method is an implementation from package C<" .
133             $super_meth->get_package() . ">. ";
134             }
135             elsif( ! $self->isa('PerlBean::Method::Constructor') ) {
136             $pre = "This method is overloaded from package C<" .
137             $super_meth->get_package() . ">. ";
138             }
139             }
140             }
141             }
142             elsif( ! $self->isa('PerlBean::Method::Constructor') ) {
143             $pre = "This method is inherited from package C<" .
144             $self->get_package() . ">. ";
145             }
146             $fh->print(<
147             \=item $name${BFP}($par)
148              
149             $pre$desc
150             EOF
151             THE_EOF
152             },
153             {
154             method_name => '_get_super_method',
155             documented => 0,
156             description => <
157             Search the superclass hierarchy for an identically named C and return it. If no method is found C is returned.
158             EOF
159             body => <<'THE_EOF',
160             my $self = shift;
161              
162             # No super method found if no collection defined
163             defined( $self->get_perl_bean() ) || return(undef);
164             defined( $self->get_perl_bean()->get_collection() ) || return(undef);
165              
166             # Look for the method in super classes
167             foreach my $super_pkg ( $self->get_perl_bean()->get_base() ) {
168             # Get the superclass bean
169             my $super_bean = ( $self->get_perl_bean()->get_collection()->values_perl_bean($super_pkg) )[0];
170              
171             # If the super class bean has no bean in the collection then no method is found
172             defined($super_bean) || return(undef);
173              
174             # See if the super class bean has the method
175             my $super_meth = $super_bean->_get_super_method( $self, {
176             $self->get_perl_bean()->get_package() => 1,
177             } );
178              
179             # Return the suprclass method if found
180             defined($super_meth) && return($super_meth);
181             }
182              
183             # Nothing found
184             return(undef);
185             THE_EOF
186             },
187             {
188             method_name => 'get_package',
189             description => <
190             Returns the package name. The package name is obtained from the C to which the C belongs. Or, if the C does not belong to a C, C
is returned.
191             EOF
192             body => <<'EOF',
193             my $self = shift;
194              
195             # Get the package name from the PerlBean
196             defined( $self->get_perl_bean ) &&
197             return( $self->get_perl_bean()->get_package() );
198              
199             # Return 'main' as default
200             return('main');
201             EOF
202             },
203             ],
204             sym_opt => [
205             {
206             symbol_name => '$SUB',
207             comment => <
208             # Variable to not confuse AutoLoader
209             EOF
210             assignment => "'sub';\n",
211             },
212             ],
213             use_opt => [
214             {
215             dependency_name => 'PerlBean::Style',
216             import_list => [ 'qw(:codegen)' ],
217             },
218             ],
219             } );
220              
221             1;