| 1 | package Fukurama::Class::Attributes::OOStandard::DefinitionCheck; | ||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use Fukurama::Class::Version(0.03); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Fukurama::Class::Rigid; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Fukurama::Class::Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Fukurama::Class::DataTypes(); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Fukurama::Class::Attributes::OOStandard::Decorator(); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Data::Dumper(); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Fukurama::Class::Tree(); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Fukurama::Class::Attributes::OOStandard::InheritationCheck(); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 3 | my $DATATYPES = 'Fukurama::Class::DataTypes'; | |||||||||||||||||||||||||||||||
| 12 | 3 | my $DECORATOR = 'Fukurama::Class::Attributes::OOStandard::Decorator'; | |||||||||||||||||||||||||||||||
| 13 | 3 | my $WHITESPACES = qr/(?:[ \t\n\r]*,[ \t\n\r]*|[ \t\n\r]+)/; | |||||||||||||||||||||||||||||||
| 14 | 3 | my $SPLIT_TYPE = qr/^(.*?)((?:\[\]|\(\))*)$/; | |||||||||||||||||||||||||||||||
| 15 | 3 | my $SPLIT_PART = qr/\|/; | |||||||||||||||||||||||||||||||
| 16 | 3 | my $SPLIT_SUBPART = qr/[\@;]/; | |||||||||||||||||||||||||||||||
| 17 | 3 | my $DEF_ERROR = undef; | |||||||||||||||||||||||||||||||
| 18 | 3 | my $ATT_TYPE = undef; | |||||||||||||||||||||||||||||||
| 19 | 3 | my $REGISTER = {}; | |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 3 | my $ACCESS_LEVEL = { | |||||||||||||||||||||||||||||||
| 22 | public => 1, | ||||||||||||||||||||||||||||||||
| 23 | protected => 2, | ||||||||||||||||||||||||||||||||
| 24 | private => 3, | ||||||||||||||||||||||||||||||||
| 25 | }; | ||||||||||||||||||||||||||||||||
| 26 | 3 | my $ACCESS_LEVEL_TYPE = {# ENUM('', 'unoverwritable') | |||||||||||||||||||||||||||||||
| 27 | public => '', | ||||||||||||||||||||||||||||||||
| 28 | protected => '', | ||||||||||||||||||||||||||||||||
| 29 | private => '', | ||||||||||||||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||||||||||||||
| 31 | 3 | my $STATIC = { | |||||||||||||||||||||||||||||||
| 32 | static => 1, | ||||||||||||||||||||||||||||||||
| 33 | '' => 1, | ||||||||||||||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||||||||||||||
| 35 | 3 | my $TYPE = { | |||||||||||||||||||||||||||||||
| 36 | abstract => 'overwrite', | ||||||||||||||||||||||||||||||||
| 37 | '' => 'normal', | ||||||||||||||||||||||||||||||||
| 38 | final => 'unoverwritable', | ||||||||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | Fukurama::Class::Attributes::OOStandard::DefinitionCheck - Helper-class to check syntax of code attributes | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | Version 0.03 (beta) | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | - (its only a collection of methods, it's unusable outside of it's own context :) | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | A Helper class for Fukurama::Class::Attributes::OOStandard to check code attribute syntax. | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | =head1 EXPORT | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | - | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | =over 4 | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | =item get_translated_def( sub_data:\HASH, def:\HASH, sub_def:\ARRAY, result_def:\ARRAY, | ||||||||||||||||||||||||||||||||
| 66 | array_result_def:\ARRAY, para_def:\ARRAY, opt_para_def:\ARRAY) return:\HASH | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | Translate the given attribute data (e.g. static|void|string) into an wellformed hash which contain | ||||||||||||||||||||||||||||||||
| 69 | all definitions include implizit definitions. | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | =item set_type( type:STRING ) return:VOID | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | Set the type-name of the actual checked code attribute. It's only for error messages. | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | =item throw_def_error( sub_data:\HASH, msg:STRING) return:VOID | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | Died with the given message and output some detailed informations about the involved method(s). | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | =item resolve_def( sub_data:\HASH ) return:VOID | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | Resolved the method name from a given subroutine code reference. | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | =item try_check_translated_def( sub_data:\HASH, translated_def:\HASH, def:\HASH ) return:VOID | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | Check all defintions of the given code attribute declaration. | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | =item decorate_sub( def:\HASH ) return:VOID | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | Decorates subroutines with a check method to check parameter and return values. | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | =item try_check_parameter( id:STRING, io_list:\ARRAY ) return:VOID | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | Check the content of the parameter list for a subroutine. | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | =item try_check_result( id:SRING, io_list:\ARRAY, list_context:BOOLEAN ) return:VOID | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | Check the content of the return value(s) for a subroutine. | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | =item try_check_abstract( id:STRING ) return:VOID | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | Check the caller of a subroutine, to avoid directly called, abstract methods. | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | =item try_check_access( id:STRING ) return:VOID | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | Check the caller of a subroutine, to avoid unauthorized calls for e.g. private methods from outside the own class. | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | =item try_check_call( id:STRING, class_parameter:SCALAR ) return:VOID | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | Check the first argument of the method for static or nonstatic calls and the correct usage. | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | =item check_inheritation( method_name:STRING, parent_class:CLASS, child_class:CLASS, inheritation_type:STRING ) return:VOID | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | Check the inheritations of all defined declarations to avoid differend method signatures for parent and child. | ||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | =back | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | =head1 AUTHOR, BUGS, SUPPORT, ACKNOWLEDGEMENTS, COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | see perldoc of L<Fukurama::Class> | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | =cut | ||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | # STATIC boolean | ||||||||||||||||||||||||||||||||
| 125 | 11 | ▶ | sub get_translated_def { | ||||||||||||||||||||||||||||||
|
Subroutine
get_translated_def: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 126 | 11 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 127 | 11 | my $sub_data = $_[1]; | |||||||||||||||||||||||||||||||
| 128 | 11 | my $def = $_[2]; | |||||||||||||||||||||||||||||||
| 129 | 11 | my $sub_def = $_[3]; | |||||||||||||||||||||||||||||||
| 130 | 11 | my $result_def = $_[4]; | |||||||||||||||||||||||||||||||
| 131 | 11 | my $array_result_def = $_[5]; | |||||||||||||||||||||||||||||||
| 132 | 11 | my $para_def = $_[6]; | |||||||||||||||||||||||||||||||
| 133 | 11 | my $opt_para_def = $_[7]; | |||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | 11 | my $access_level = $class->_extract_access_level_def($sub_def, $sub_data->{'sub_name'}); | |||||||||||||||||||||||||||||||
| 136 | 11 | $class->_try_check_access_level_def($sub_data, $access_level); | |||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | 11 | my $static = $class->_extract_static_def($sub_def); | |||||||||||||||||||||||||||||||
| 139 | 11 | $class->_try_check_static_def($sub_data, $static); | |||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 11 | my $type = $class->_extract_type_def($sub_def); | |||||||||||||||||||||||||||||||
| 142 | 11 | $class->_try_check_type_def($sub_data, $type); | |||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 11 | my $result = $class->_extract_io_def($result_def); | |||||||||||||||||||||||||||||||
| 145 | 11 | $class->_try_check_io_def($sub_data, $result, '$return value', []); | |||||||||||||||||||||||||||||||
| 146 | 11 | ▶ | if(scalar(@$result) != 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 147 | 0 | $class->throw_def_error($sub_data, "\$return value definition must contain exact 1 element but is " . scalar(@$result) . " elements long."); | |||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||
| 149 | 11 | ▶ | if($result->[0]->{'ref'} eq '()') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 150 | 0 | $class->throw_def_error($sub_data, "\$return value '$result->[0]->{'type'}$result->[0]->{'ref'}' is not allowed. You can't use () in scalar context."); | |||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | 11 | my $array_result = $class->_extract_io_def($array_result_def); | |||||||||||||||||||||||||||||||
| 154 | 11 | ▶ | if(@$array_result) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 155 | 5 | $class->_try_check_io_def($sub_data, $array_result, '@return value', [qw/void/]); | |||||||||||||||||||||||||||||||
| 156 | 5 | $class->_try_check_list_result($sub_data, [@$array_result]); | |||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | 11 | my $para = $class->_extract_io_def($para_def); | |||||||||||||||||||||||||||||||
| 160 | 11 | $class->_try_check_io_def($sub_data, $para, 'parameter', [qw/void/]); | |||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | 11 | my $opt_para = $class->_extract_io_def($opt_para_def); | |||||||||||||||||||||||||||||||
| 163 | 11 | $class->_try_check_io_def($sub_data, $opt_para, 'optional parameter', [qw/void/]); | |||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | 11 | $class->_try_check_list_parameter($sub_data, [@$para, @$opt_para], scalar(@$para)); | |||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | return { | ||||||||||||||||||||||||||||||||
| 168 | 11 | access_level => $access_level, | |||||||||||||||||||||||||||||||
| 169 | static => $static, | ||||||||||||||||||||||||||||||||
| 170 | type => $type, | ||||||||||||||||||||||||||||||||
| 171 | result => $result, | ||||||||||||||||||||||||||||||||
| 172 | array_result => $array_result, | ||||||||||||||||||||||||||||||||
| 173 | para => $para, | ||||||||||||||||||||||||||||||||
| 174 | opt_para => $opt_para, | ||||||||||||||||||||||||||||||||
| 175 | sub_data => $sub_data, | ||||||||||||||||||||||||||||||||
| 176 | }; | ||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||
| 178 | # STATIC void | ||||||||||||||||||||||||||||||||
| 179 | 5 | ▶ | sub _try_check_list_result { | ||||||||||||||||||||||||||||||
|
Subroutine
_try_check_list_result: called CC=3 SCAR=13.0
| |||||||||||||||||||||||||||||||||
| 180 | 5 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 181 | 5 | my $sub_data = $_[1]; | |||||||||||||||||||||||||||||||
| 182 | 5 | my $list = $_[2]; | |||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | 5 | my $last_element = pop(@$list); | |||||||||||||||||||||||||||||||
| 185 | 5 | my $i = 0; | |||||||||||||||||||||||||||||||
| 186 | 5 | foreach my $entry (@$list) { | |||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if($entry->{'ref'} eq '()') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 188 | 0 | $class->throw_def_error($sub_data, "\@result $i '$entry->{'type'}$entry->{'ref'}' is not allowed. You can use () only as last element."); | |||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||
| 190 | 0 | ++$i; | |||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||
| 192 | 5 | return; | |||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||
| 194 | # STATIC void | ||||||||||||||||||||||||||||||||
| 195 | 11 | ▶ | sub _try_check_list_parameter { | ||||||||||||||||||||||||||||||
|
Subroutine
_try_check_list_parameter: called CC=4 SCAR=15.0
| |||||||||||||||||||||||||||||||||
| 196 | 11 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 197 | 11 | my $sub_data = $_[1]; | |||||||||||||||||||||||||||||||
| 198 | 11 | my $list = $_[2]; | |||||||||||||||||||||||||||||||
| 199 | 11 | my $needed_length = $_[3]; | |||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | 11 | my $last_element = pop(@$list); | |||||||||||||||||||||||||||||||
| 202 | 11 | my $i = 0; | |||||||||||||||||||||||||||||||
| 203 | 11 | foreach my $entry (@$list) { | |||||||||||||||||||||||||||||||
| 204 | 11 | ▶ | if($entry->{'ref'} eq '()') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | my $name = ($i > $needed_length ? 'optional parameter' : 'parameter'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 206 | 0 | $class->throw_def_error($sub_data, "$name $i '$entry->{'type'}$entry->{'ref'}' is not allowed. You can use () only as last element."); | |||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||
| 208 | 11 | ++$i; | |||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||
| 210 | 11 | return; | |||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||
| 212 | # STATIC void | ||||||||||||||||||||||||||||||||
| 213 | 11 | ▶ | sub set_type { | ||||||||||||||||||||||||||||||
|
Subroutine
set_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 214 | 11 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 215 | 11 | my $type = $_[1]; | |||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||
| 217 | 11 | $ATT_TYPE = $type; | |||||||||||||||||||||||||||||||
| 218 | return: | ||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||
| 220 | # STATIC void | ||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | sub throw_def_error { | ||||||||||||||||||||||||||||||
|
Subroutine
throw_def_error: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 222 | 0 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 223 | 0 | my $sub_data = $_[1]; | |||||||||||||||||||||||||||||||
| 224 | 0 | my $msg = $_[2]; | |||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | my $type = (defined($ATT_TYPE) ? " $ATT_TYPE": ''); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | if($DEF_ERROR) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 228 | 0 | $DEF_ERROR = "Last error thrown twice"; | |||||||||||||||||||||||||||||||
| 229 | } else { | ||||||||||||||||||||||||||||||||
| 230 | 0 | $DEF_ERROR = "Error in$type declaration:\n $sub_data->{'class'}\->$sub_data->{'sub_name'}($sub_data->{'data'})\n> $msg\n\n"; | |||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||
| 232 | 0 | _croak($DEF_ERROR); | |||||||||||||||||||||||||||||||
| 233 | 0 | return; | |||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||
| 235 | # STATIC array[] | ||||||||||||||||||||||||||||||||
| 236 | 11 | ▶ | sub resolve_def { | ||||||||||||||||||||||||||||||
|
Subroutine
resolve_def: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 237 | 11 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 238 | 11 | my $sub_data = $_[1]; | |||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||
| 240 | 11 | my @data = (); | |||||||||||||||||||||||||||||||
| 241 | 11 | foreach my $part (split($SPLIT_PART, $sub_data->{'data'})) { | |||||||||||||||||||||||||||||||
| 242 | 27 | my @subdata = (); | |||||||||||||||||||||||||||||||
| 243 | 27 | foreach my $subpart (split($SPLIT_SUBPART, $part . ' ')) { | |||||||||||||||||||||||||||||||
| 244 | 36 | my @entry = (); | |||||||||||||||||||||||||||||||
| 245 | 36 | foreach my $entry (split($WHITESPACES, $subpart)) { | |||||||||||||||||||||||||||||||
| 246 | 48 | my ($type, $ref) = $entry =~ $SPLIT_TYPE; | |||||||||||||||||||||||||||||||
| 247 | 48 | push(@entry, { | |||||||||||||||||||||||||||||||
| 248 | data => $type, | ||||||||||||||||||||||||||||||||
| 249 | type => $ref, | ||||||||||||||||||||||||||||||||
| 250 | }); | ||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||
| 252 | 36 | ▶ | if($subpart =~ m/,$/ || $subpart =~ m/^$WHITESPACES$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$subpart =~ /,$/ or $subpart =~ /^$WHITESPACES$/
MC/DC50%1/2
$subpart =~ /,$/ or $subpart =~ /^$WHITESPACES$/
$subpart =~ /,$/
$subpart =~ /^$WHITESPACES$/
Truth table66%2/3
A or B
A= $subpart =~ /,$/B= $subpart =~ /^$WHITESPACES$/
| |||||||||||||||||||||||||||||||||
| 253 | 3 | push(@entry, { | |||||||||||||||||||||||||||||||
| 254 | data => '', | ||||||||||||||||||||||||||||||||
| 255 | type => '', | ||||||||||||||||||||||||||||||||
| 256 | }); | ||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||
| 258 | 36 | push(@subdata, \@entry); | |||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||
| 260 | 27 | push(@data, \@subdata); | |||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||
| 262 | 11 | return \@data; | |||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||
| 264 | # STATIC string | ||||||||||||||||||||||||||||||||
| 265 | 11 | ▶ | sub _extract_access_level_def { | ||||||||||||||||||||||||||||||
|
Subroutine
_extract_access_level_def: called CC=11 SCAR=25.6
| |||||||||||||||||||||||||||||||||
| 266 | 11 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 267 | 11 | my $sub_def = $_[1]; | |||||||||||||||||||||||||||||||
| 268 | 11 | my $sub_name = $_[2]; | |||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | 11 | my $access_level = {}; | |||||||||||||||||||||||||||||||
| 271 | 11 | foreach my $entry (@$sub_def) { | |||||||||||||||||||||||||||||||
| 272 | 19 | ▶ | if($ACCESS_LEVEL->{$entry->{'data'}}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 273 | 7 | ▶ | return undef if($access_level->{$entry->{'data'}}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 274 | 7 | $access_level->{$entry->{'data'}} = 1; | |||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | 11 | ▶ | if($sub_name =~ /^_/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 279 | 1 | ▶ | return undef if($access_level->{'public'}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 280 | 1 | ▶ | $access_level->{'protected'} = 1 if(!$access_level->{'protected'} && !$access_level->{'private'}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$access_level->{"protected"} or $access_level->{"private"}
MC/DC0%0/2
$access_level->{"protected"} or $access_level->{"private"}
$access_level->{"protected"}
$access_level->{"private"}
Truth table33%1/3
A or B
A= $access_level->{"protected"}B= $access_level->{"private"}
| |||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||
| 282 | } else { | ||||||||||||||||||||||||||||||||
| 283 | 10 | ▶ | return undef if($access_level->{'protected'} || $access_level->{'private'}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$access_level->{"protected"} or $access_level->{"private"}
MC/DC0%0/2
$access_level->{"protected"} or $access_level->{"private"}
$access_level->{"protected"}
$access_level->{"private"}
Truth table33%1/3
A or B
A= $access_level->{"protected"}B= $access_level->{"private"}
| |||||||||||||||||||||||||||||||||
| 284 | 10 | $access_level->{'public'} = 1; | |||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||
| 288 | 11 | my @access_level = keys(%$access_level); | |||||||||||||||||||||||||||||||
| 289 | 11 | ▶ | return undef if(scalar(@access_level) != 1); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 290 | 11 | return $access_level[0]; | |||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||
| 292 | # STATIC void | ||||||||||||||||||||||||||||||||
| 293 | 11 | ▶ | sub _try_check_access_level_def { | ||||||||||||||||||||||||||||||
|
Subroutine
_try_check_access_level_def: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||
| 294 | 11 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 295 | 11 | my $sub_data = $_[1]; | |||||||||||||||||||||||||||||||
| 296 | 11 | my $access_level = $_[2]; | |||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||
| 298 | 11 | ▶ | $class->throw_def_error($sub_data, 'access level declaration is wrong. Maybe a conflict between sub name and declared access level.') if(!defined($access_level) || !$ACCESS_LEVEL->{$access_level}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $access_level and $ACCESS_LEVEL->{$access_level}
MC/DC0%0/2
defined $access_level and $ACCESS_LEVEL->{$access_level}
defined $access_level
$ACCESS_LEVEL->{$access_level}
Truth table33%1/3
A and B
A= defined $access_levelB= $ACCESS_LEVEL->{$access_level}
| |||||||||||||||||||||||||||||||||
| 299 | 11 | return; | |||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||
| 301 | # STATIC string | ||||||||||||||||||||||||||||||||
| 302 | 11 | ▶ | sub _extract_static_def { | ||||||||||||||||||||||||||||||
|
Subroutine
_extract_static_def: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||
| 303 | 11 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 304 | 11 | my $sub_def = $_[1]; | |||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||
| 306 | 11 | my $static = {}; | |||||||||||||||||||||||||||||||
| 307 | 11 | foreach my $entry (@$sub_def) { | |||||||||||||||||||||||||||||||
| 308 | 19 | ▶ | if($STATIC->{$entry->{'data'}}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 309 | 11 | ▶ | return undef if($static->{$entry->{'data'}}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 310 | 11 | $static->{$entry->{'data'}} = 1; | |||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||
| 313 | 11 | my @static = keys(%$static); | |||||||||||||||||||||||||||||||
| 314 | 11 | ▶ | return undef if(scalar(@static) > 1); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 315 | 11 | ▶ | return $static[0] || ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$static[0] || ''
MC/DC0%0/1
$static[0] || ''
$static[0]
Truth table50%1/2
A
A= $static[0]
| |||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||
| 317 | # STATIC void | ||||||||||||||||||||||||||||||||
| 318 | 11 | ▶ | sub _try_check_static_def { | ||||||||||||||||||||||||||||||
|
Subroutine
_try_check_static_def: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||
| 319 | 11 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 320 | 11 | my $sub_data = $_[1]; | |||||||||||||||||||||||||||||||
| 321 | 11 | my $static = $_[2]; | |||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||
| 323 | 11 | ▶ | $class->throw_def_error($sub_data, 'static declaration is wrong') if(!defined($static) || !$STATIC->{$static}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $static and $STATIC->{$static}
MC/DC0%0/2
defined $static and $STATIC->{$static}
defined $static
$STATIC->{$static}
Truth table33%1/3
A and B
A= defined $staticB= $STATIC->{$static}
| |||||||||||||||||||||||||||||||||
| 324 | 11 | return; | |||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||
| 326 | # STATIC string[] | ||||||||||||||||||||||||||||||||
| 327 | 11 | ▶ | sub _extract_type_def { | ||||||||||||||||||||||||||||||
|
Subroutine
_extract_type_def: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||
| 328 | 11 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 329 | 11 | my $sub_def = $_[1]; | |||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||
| 331 | 11 | my $type = {}; | |||||||||||||||||||||||||||||||
| 332 | 11 | foreach my $entry (@$sub_def) { | |||||||||||||||||||||||||||||||
| 333 | 19 | ▶ | if($TYPE->{$entry->{'data'}}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 334 | 1 | ▶ | return undef if($type->{$entry->{'data'}}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 335 | 1 | $type->{$entry->{'data'}} = 1; | |||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||
| 339 | 11 | my @type = keys(%$type); | |||||||||||||||||||||||||||||||
| 340 | 11 | ▶ | return undef if(scalar(@type) > 1); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 341 | 11 | ▶ | return $type[0] || ''; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$type[0] || ''
MC/DC100%1/1
$type[0] || ''
$type[0]
Truth table100%2/2
A
A= $type[0]
| |||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||
| 343 | # STATIC void | ||||||||||||||||||||||||||||||||
| 344 | 11 | ▶ | sub _try_check_type_def { | ||||||||||||||||||||||||||||||
|
Subroutine
_try_check_type_def: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||
| 345 | 11 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 346 | 11 | my $sub_data = $_[1]; | |||||||||||||||||||||||||||||||
| 347 | 11 | my $type = $_[2]; | |||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||
| 349 | 11 | ▶ | $class->throw_def_error($sub_data, 'type declaration is not allowed') if(!defined($type) || !$TYPE->{$type}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $type and $TYPE->{$type}
MC/DC0%0/2
defined $type and $TYPE->{$type}
defined $type
$TYPE->{$type}
Truth table33%1/3
A and B
A= defined $typeB= $TYPE->{$type}
| |||||||||||||||||||||||||||||||||
| 350 | 11 | return; | |||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||
| 352 | # STATIC string[] | ||||||||||||||||||||||||||||||||
| 353 | 44 | ▶ | sub _extract_io_def { | ||||||||||||||||||||||||||||||
|
Subroutine
_extract_io_def: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 354 | 44 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 355 | 44 | my $io_def = $_[1]; | |||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||
| 357 | 44 | my $io = []; | |||||||||||||||||||||||||||||||
| 358 | 44 | foreach my $entry (@$io_def) { | |||||||||||||||||||||||||||||||
| 359 | push(@$io, { | ||||||||||||||||||||||||||||||||
| 360 | type => $entry->{'data'}, | ||||||||||||||||||||||||||||||||
| 361 | ref => $entry->{'type'}, | ||||||||||||||||||||||||||||||||
| 362 | 38 | check => $DATATYPES->get_check_definition($entry->{'data'}, $entry->{'type'}), | |||||||||||||||||||||||||||||||
| 363 | }); | ||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||
| 365 | 44 | return $io; | |||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||
| 367 | # STATIC void | ||||||||||||||||||||||||||||||||
| 368 | 38 | ▶ | sub _try_check_io_def { | ||||||||||||||||||||||||||||||
|
Subroutine
_try_check_io_def: called CC=8 SCAR=25.5
| |||||||||||||||||||||||||||||||||
| 369 | 38 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 370 | 38 | my $sub_data = $_[1]; | |||||||||||||||||||||||||||||||
| 371 | 38 | my $io = $_[2]; | |||||||||||||||||||||||||||||||
| 372 | 38 | my $name = $_[3]; | |||||||||||||||||||||||||||||||
| 373 | 38 | my $forbidden_types = $_[4]; | |||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||
| 375 | 38 | foreach my $entry (@$io) { | |||||||||||||||||||||||||||||||
| 376 | 38 | ▶ | if(!$DATATYPES->is_ref_allowed($entry->{'ref'})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 377 | 0 | $class->throw_def_error($sub_data, "$name definition '$entry->{'type'}$entry->{'ref'}' is not allowed"); | |||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||
| 379 | 38 | my $error = 0; | |||||||||||||||||||||||||||||||
| 380 | 38 | foreach my $type (@$forbidden_types) { | |||||||||||||||||||||||||||||||
| 381 | 27 | ▶ | $error = 1 if($entry->{'type'} eq $type); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||
| 383 | 38 | ▶ | if($error || !$DATATYPES->check_parameter_definition($entry->{'type'}, $entry->{'check'})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$error or not $DATATYPES->check_parameter_definition($entry->{"type"}, $entry->{"check"})
MC/DC0%0/2
$error or not $DATATYPES->check_parameter_definition($entry->{"type"}, $entry->{"check"})
$error
not $DATATYPES->check_parameter_definition($entry->{"type"}, $entry->{"check"})
Truth table33%1/3
A or not(B)
A= $errorB= not $DATATYPES->check_parameter_definition($entry->{"type"}, $entry->{"check"})
| |||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | if($entry->{'check'}->{'is_class'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 385 | 0 | $class->throw_def_error( | |||||||||||||||||||||||||||||||
| 386 | $sub_data, | ||||||||||||||||||||||||||||||||
| 387 | "$name '$entry->{'type'}$entry->{'ref'}' is wrong. This class is not loaded or doesn't exist." | ||||||||||||||||||||||||||||||||
| 388 | ); | ||||||||||||||||||||||||||||||||
| 389 | } else { | ||||||||||||||||||||||||||||||||
| 390 | 0 | $class->throw_def_error( | |||||||||||||||||||||||||||||||
| 391 | $sub_data, | ||||||||||||||||||||||||||||||||
| 392 | "$name '$entry->{'type'}$entry->{'ref'}' is not allowed." | ||||||||||||||||||||||||||||||||
| 393 | ); | ||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||
| 398 | # STATIC void | ||||||||||||||||||||||||||||||||
| 399 | 11 | ▶ | sub try_check_translated_def { | ||||||||||||||||||||||||||||||
|
Subroutine
try_check_translated_def: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 400 | 11 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 401 | 11 | my $sub_data = $_[1]; | |||||||||||||||||||||||||||||||
| 402 | 11 | my $translated_def = $_[2]; | |||||||||||||||||||||||||||||||
| 403 | 11 | my $def = $_[3]; | |||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||
| 405 | 11 | my $def_keys = {}; | |||||||||||||||||||||||||||||||
| 406 | 11 | foreach my $entry (@{$def->[0]->[0]}) { | |||||||||||||||||||||||||||||||
| 407 | 19 | $def_keys->{$entry->{'data'}} = 1; | |||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||
| 410 | 11 | foreach my $key (values(%$translated_def)) { | |||||||||||||||||||||||||||||||
| 411 | 88 | delete($def_keys->{$key}); | |||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||
| 414 | 11 | my @forbidden_keys = keys(%$def_keys); | |||||||||||||||||||||||||||||||
| 415 | 11 | ▶ | if(@forbidden_keys) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 416 | 0 | my $keys = join(', ', @forbidden_keys); | |||||||||||||||||||||||||||||||
| 417 | 0 | $class->throw_def_error($sub_data, "forbidden key(s): '$keys' used in declaration"); | |||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||
| 419 | 11 | return; | |||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||
| 421 | # STATIC void | ||||||||||||||||||||||||||||||||
| 422 | 11 | ▶ | sub decorate_sub { | ||||||||||||||||||||||||||||||
|
Subroutine
decorate_sub: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 423 | 11 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 424 | 11 | my $def = $_[1]; | |||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||
| 426 | 11 | my $sub_data = $def->{'sub_data'}; | |||||||||||||||||||||||||||||||
| 427 | 11 | my $old = $sub_data->{'sub'}; | |||||||||||||||||||||||||||||||
| 428 | 11 | my $identifier = $sub_data->{'class'} . '::' . $sub_data->{'sub_name'}; | |||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||
| 430 | 11 | ▶ | $DECORATOR->remove_decoration($identifier, $old) if($REGISTER->{$identifier}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 431 | 11 | $DECORATOR->decorate($identifier, $old, __PACKAGE__); | |||||||||||||||||||||||||||||||
| 432 | 11 | $REGISTER->{$identifier} = $def; | |||||||||||||||||||||||||||||||
| 433 | 11 | return; | |||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||
| 435 | # STATIC void | ||||||||||||||||||||||||||||||||
| 436 | 5 | ▶ | sub try_check_parameter { | ||||||||||||||||||||||||||||||
|
Subroutine
try_check_parameter: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 437 | 5 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 438 | 5 | my $id = $_[1]; | |||||||||||||||||||||||||||||||
| 439 | 5 | my $io_list = $_[2]; | |||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||
| 441 | 5 | my $def = $REGISTER->{$id}; | |||||||||||||||||||||||||||||||
| 442 | 5 | ▶ | _croak("Internal error:\n sub $id() has no definition\n\n") if(!$def); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||
| 444 | 5 | my $io_def_list = [@{$def->{'para'}}, @{$def->{'opt_para'}}]; | |||||||||||||||||||||||||||||||
| 445 | 5 | my $length = scalar(@$io_def_list); | |||||||||||||||||||||||||||||||
| 446 | 5 | my $needed_length = scalar(@{$def->{'para'}}); | |||||||||||||||||||||||||||||||
| 447 | 5 | my $given_length = scalar(@$io_list); | |||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||
| 449 | 5 | ▶ | $length = $given_length if($given_length >= $needed_length); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 450 | 5 | $class->_try_check_io($io_def_list, $io_list, $length, $def, 'parameter'); | |||||||||||||||||||||||||||||||
| 451 | 4 | return; | |||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||
| 453 | # STATIC void | ||||||||||||||||||||||||||||||||
| 454 | 4 | ▶ | sub try_check_result { | ||||||||||||||||||||||||||||||
|
Subroutine
try_check_result: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 455 | 4 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 456 | 4 | my $id = $_[1]; | |||||||||||||||||||||||||||||||
| 457 | 4 | my $io_list = $_[2]; | |||||||||||||||||||||||||||||||
| 458 | 4 | my $list_context = $_[3]; | |||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||
| 460 | 4 | my $def = $REGISTER->{$id}; | |||||||||||||||||||||||||||||||
| 461 | 4 | ▶ | _croak("Internal error:\n sub $id() has no definition\n\n") if(!$def); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||
| 463 | 4 | my $io_type = undef; | |||||||||||||||||||||||||||||||
| 464 | 4 | my $io_def_list = undef; | |||||||||||||||||||||||||||||||
| 465 | 4 | ▶ | if($list_context && scalar(@{$def->{'array_result'}})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$list_context and scalar @{$def->{"array_result"};}
MC/DC100%1/1
$list_context and scalar @{$def->{"array_result"};}
$list_context
Truth table100%2/2
A
A= $list_context
| |||||||||||||||||||||||||||||||||
| 466 | 2 | $io_def_list = [@{$def->{'array_result'}}]; | |||||||||||||||||||||||||||||||
| 467 | 2 | $io_type = 'listcontext result'; | |||||||||||||||||||||||||||||||
| 468 | } else { | ||||||||||||||||||||||||||||||||
| 469 | 2 | $io_def_list = [@{$def->{'result'}}]; | |||||||||||||||||||||||||||||||
| 470 | 2 | $io_type = 'result'; | |||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||
| 474 | 4 | my $length = scalar(@$io_def_list); | |||||||||||||||||||||||||||||||
| 475 | 4 | my $needed_length = $length; | |||||||||||||||||||||||||||||||
| 476 | 4 | my $given_length = scalar(@$io_list); | |||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||
| 478 | 4 | ▶ | $length = $given_length if($given_length > $needed_length); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 479 | 4 | $class->_try_check_io($io_def_list, $io_list, $length, $def, $io_type); | |||||||||||||||||||||||||||||||
| 480 | 3 | return; | |||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||
| 482 | # STATIC void | ||||||||||||||||||||||||||||||||
| 483 | 9 | ▶ | sub _try_check_io { | ||||||||||||||||||||||||||||||
|
Subroutine
_try_check_io: called CC=13 SCAR=28.5
| |||||||||||||||||||||||||||||||||
| 484 | 9 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 485 | 9 | my $io_def_list = $_[1]; | |||||||||||||||||||||||||||||||
| 486 | 9 | my $io_list = $_[2]; | |||||||||||||||||||||||||||||||
| 487 | 9 | my $length = $_[3]; | |||||||||||||||||||||||||||||||
| 488 | 9 | my $def = $_[4]; | |||||||||||||||||||||||||||||||
| 489 | 9 | my $io_type = $_[5]; | |||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||
| 491 | 9 | my $errors = []; | |||||||||||||||||||||||||||||||
| 492 | 9 | ▶ | for(my $i = 0; $i < $length; $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 493 | 16 | my $pdef = $io_def_list->[$i]; | |||||||||||||||||||||||||||||||
| 494 | 16 | my $entry = $io_list->[$i]; | |||||||||||||||||||||||||||||||
| 495 | 16 | ▶ | if(!ref($pdef)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 496 | 1 | my $defined = ''; | |||||||||||||||||||||||||||||||
| 497 | 1 | ▶ | if(!defined($entry)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 498 | 0 | $defined = ' (undefined)'; | |||||||||||||||||||||||||||||||
| 499 | 0 | $entry = ''; | |||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||
| 501 | 1 | push(@$errors, "Error in $io_type " . ($i + 1) . | |||||||||||||||||||||||||||||||
| 502 | ":\n $def->{'sub_data'}->{'class'}->$def->{'sub_data'}->{'sub_name'}($def->{'sub_data'}->{'data'})\n" . | ||||||||||||||||||||||||||||||||
| 503 | "> no further $io_type expected, only " . scalar(@$io_def_list) . " is/are allowed.\n" . | ||||||||||||||||||||||||||||||||
| 504 | "> extra $io_type '$entry'$defined given\n\n"); | ||||||||||||||||||||||||||||||||
| 505 | 1 | next; | |||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||
| 507 | 15 | my $old_entry = $entry; | |||||||||||||||||||||||||||||||
| 508 | 15 | (my $is_ok, $entry, my $error_msg) = &{$pdef->{'check'}->{'check'}}($pdef->{'check'}->{'param_0'}, $entry, $pdef->{'type'}, \$i, $io_list); | |||||||||||||||||||||||||||||||
| 509 | 15 | ▶ | if(!$is_ok) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 510 | 1 | my $defined = ''; | |||||||||||||||||||||||||||||||
| 511 | 1 | ▶ | if(!defined($old_entry) || !defined($entry)) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $old_entry && defined $entry
MC/DC0%0/2
defined $old_entry && defined $entry
defined $old_entry
defined $entry
Truth table33%1/3
A && B
A= defined $old_entryB= defined $entry
| |||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | $defined = ' (undefined)' if(!defined($old_entry)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 513 | 0 | $entry = ''; | |||||||||||||||||||||||||||||||
| 514 | } elsif(ref($entry) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
| 515 | 0 | local $Data::Dumper::Maxdepth = 1; | |||||||||||||||||||||||||||||||
| 516 | 0 | $entry = Data::Dumper::Dumper($entry); | |||||||||||||||||||||||||||||||
| 517 | 0 | $entry =~ s/^[^\[]*//; | |||||||||||||||||||||||||||||||
| 518 | 0 | $entry =~ s/[^\]]*$//; | |||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||
| 520 | 1 | ▶ | my $class = ($pdef->{'check'}->{'is_class'} ? ' class (or child of)' : ''); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 521 | 1 | ▶ | $class = 'Any kind of a' if($pdef->{'type'} eq 'class'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 522 | 1 | ▶ | my $extended_msg = (defined($error_msg) ? " ($error_msg)" : ''); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 523 | 1 | push(@$errors, "Error in $io_type " . ($i + 1) . | |||||||||||||||||||||||||||||||
| 524 | ":\n $def->{'sub_data'}->{'class'}->$def->{'sub_data'}->{'sub_name'}($def->{'sub_data'}->{'data'})\n" . | ||||||||||||||||||||||||||||||||
| 525 | "> $class '$pdef->{'type'}$pdef->{'ref'}' expected but '$entry'$defined given$extended_msg.\n\n"); | ||||||||||||||||||||||||||||||||
| 526 | 1 | next; | |||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||
| 529 | 9 | ▶ | _croak(join('', @$errors)) if(@$errors); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 530 | 7 | return; | |||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||
| 532 | # STATIC void | ||||||||||||||||||||||||||||||||
| 533 | 5 | ▶ | sub try_check_abstract { | ||||||||||||||||||||||||||||||
|
Subroutine
try_check_abstract: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 534 | 5 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 535 | 5 | my $id = $_[1]; | |||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||
| 537 | 5 | my $def = $REGISTER->{$id}; | |||||||||||||||||||||||||||||||
| 538 | 5 | ▶ | _croak("Internal error:\n sub $id() has no definition\n\n") if(!$def); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||
| 540 | 5 | ▶ | if($def->{'type'} eq 'abstract') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 541 | $class->_throw_access_error( | ||||||||||||||||||||||||||||||||
| 542 | $def, | ||||||||||||||||||||||||||||||||
| 543 | 0 | 'This ' . lcfirst($def->{'sub_data'}->{'attribute'}) . ' is declared as abstract but called directly.' | |||||||||||||||||||||||||||||||
| 544 | ); | ||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||
| 546 | 5 | return; | |||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||
| 548 | # STATIC void | ||||||||||||||||||||||||||||||||
| 549 | 6 | ▶ | sub try_check_access { | ||||||||||||||||||||||||||||||
|
Subroutine
try_check_access: called CC=8 SCAR=24.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 550 | 6 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 551 | 6 | my $id = $_[1]; | |||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||
| 553 | 6 | my $def = $REGISTER->{$id}; | |||||||||||||||||||||||||||||||
| 554 | 6 | ▶ | _croak("Internal error:\n sub $id() has no definition\n\n") if(!$def); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||
| 556 | 6 | ▶ | return if($def->{'access_level'} eq 'public'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||
| 558 | 3 | my ($caller_package, $filename, $line) = caller(); | |||||||||||||||||||||||||||||||
| 559 | 3 | my $msg = ''; | |||||||||||||||||||||||||||||||
| 560 | 3 | ▶ | if($def->{'access_level'} eq 'protected') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | return if(UNIVERSAL::isa($caller_package, $def->{'sub_data'}->{'class'}) || UNIVERSAL::isa($def->{'sub_data'}->{'class'}, $caller_package)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
UNIVERSAL::isa($caller_package, $def->{"sub_data"}{"class"}) or UNIVERSAL::isa($def->{"sub_data"}{"class"}, $caller_package)
MC/DC0%0/2
UNIVERSAL::isa($caller_package, $def->{"sub_data"}{"class"}) or UNIVERSAL::isa($def->{"sub_data"}{"class"}, $caller_package)
UNIVERSAL::isa($caller_package, $def->{"sub_data"}{"class"})
UNIVERSAL::isa($def->{"sub_data"}{"class"}, $caller_package)
Truth table0%0/3
A or B
A= UNIVERSAL::isa($caller_package, $def->{"sub_data"}{"class"})B= UNIVERSAL::isa($def->{"sub_data"}{"class"}, $caller_package)
| |||||||||||||||||||||||||||||||||
| 562 | 0 | $msg = 'protected but called from outside the inheritation'; | |||||||||||||||||||||||||||||||
| 563 | } elsif($def->{'access_level'} eq 'private') { | ||||||||||||||||||||||||||||||||
| 564 | 3 | ▶ | return if($caller_package eq $def->{'sub_data'}->{'class'}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 565 | 1 | $msg = 'private but called from another class'; | |||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||
| 567 | $class->_throw_access_error( | ||||||||||||||||||||||||||||||||
| 568 | $def, | ||||||||||||||||||||||||||||||||
| 569 | 1 | 'This ' . lcfirst($def->{'sub_data'}->{'attribute'}) . " is declared as $msg", | |||||||||||||||||||||||||||||||
| 570 | "Called from class/package: '$caller_package'" | ||||||||||||||||||||||||||||||||
| 571 | ); | ||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||
| 573 | 0 | return; | |||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||
| 575 | # STATIC void | ||||||||||||||||||||||||||||||||
| 576 | 152 | ▶ | sub check_inheritation { | ||||||||||||||||||||||||||||||
|
Subroutine
check_inheritation: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 577 | 152 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 578 | 152 | my $method_name = $_[1]; | |||||||||||||||||||||||||||||||
| 579 | 152 | my $parent_class = $_[2]; | |||||||||||||||||||||||||||||||
| 580 | 152 | my $child_class = $_[3]; | |||||||||||||||||||||||||||||||
| 581 | 152 | my $inheritation_type = $_[4]; | |||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||
| 583 | 152 | my $definition_data = { | |||||||||||||||||||||||||||||||
| 584 | register => $REGISTER, | ||||||||||||||||||||||||||||||||
| 585 | type => $TYPE, | ||||||||||||||||||||||||||||||||
| 586 | access_level_type => $ACCESS_LEVEL_TYPE, | ||||||||||||||||||||||||||||||||
| 587 | access_level => $ACCESS_LEVEL, | ||||||||||||||||||||||||||||||||
| 588 | }; | ||||||||||||||||||||||||||||||||
| 589 | 152 | Fukurama::Class::Attributes::OOStandard::InheritationCheck->check_inheritation($method_name, $parent_class, $child_class, $inheritation_type, $definition_data); | |||||||||||||||||||||||||||||||
| 590 | 152 | return; | |||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||
| 592 | #STATIC void | ||||||||||||||||||||||||||||||||
| 593 | 6 | ▶ | sub try_check_call { | ||||||||||||||||||||||||||||||
|
Subroutine
try_check_call: called CC=9 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 594 | 6 | my $class = $_[0]; | |||||||||||||||||||||||||||||||
| 595 | 6 | my $id = $_[1]; | |||||||||||||||||||||||||||||||
| 596 | 6 | my $class_param = $_[2]; | |||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||
| 598 | 6 | my $def = $REGISTER->{$id}; | |||||||||||||||||||||||||||||||
| 599 | 6 | ▶ | _croak("Internal error:\n sub $id() has no definition\n\n") if(!$def); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||
| 601 | 6 | ▶ | my $is_class = ref($class_param) || $class_param; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class_param || $class_param
MC/DC0%0/2
ref $class_param || $class_param
ref $class_param
$class_param
Truth table33%1/3
A || B
A= ref $class_paramB= $class_param
| |||||||||||||||||||||||||||||||||
| 602 | 6 | my $should_class = $def->{'sub_data'}->{'class'}; | |||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||
| 604 | 6 | ▶ | if(!defined($is_class) || !defined($should_class)) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $is_class && defined $should_class
MC/DC0%0/2
defined $is_class && defined $should_class
defined $is_class
defined $should_class
Truth table33%1/3
A && B
A= defined $is_classB= defined $should_class
| |||||||||||||||||||||||||||||||||
| 605 | 0 | $class->_throw_access_error($def, 'this subroutine was called directly, not over a class or an object'); | |||||||||||||||||||||||||||||||
| 606 | ▶ | } elsif(UNIVERSAL::isa($is_class, $should_class) || UNIVERSAL::isa($should_class, $is_class)) { | |||||||||||||||||||||||||||||||
|
Condition33%1/3
UNIVERSAL::isa($is_class, $should_class) or UNIVERSAL::isa($should_class, $is_class)
MC/DC0%0/2
UNIVERSAL::isa($is_class, $should_class) or UNIVERSAL::isa($should_class, $is_class)
UNIVERSAL::isa($is_class, $should_class)
UNIVERSAL::isa($should_class, $is_class)
Truth table33%1/3
A or B
A= UNIVERSAL::isa($is_class, $should_class)B= UNIVERSAL::isa($should_class, $is_class)
| |||||||||||||||||||||||||||||||||
| 607 | 6 | ▶ | return if($def->{'static'} eq 'static'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | return if(ref($class_param)); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 610 | 0 | $class->_throw_access_error( | |||||||||||||||||||||||||||||||
| 611 | $def, | ||||||||||||||||||||||||||||||||
| 612 | 'this non-static method was called as static method', | ||||||||||||||||||||||||||||||||
| 613 | 'only over a class, not an object', | ||||||||||||||||||||||||||||||||
| 614 | 'used class: ' . $class_param | ||||||||||||||||||||||||||||||||
| 615 | ); | ||||||||||||||||||||||||||||||||
| 616 | } else { | ||||||||||||||||||||||||||||||||
| 617 | 0 | $class->_throw_access_error( | |||||||||||||||||||||||||||||||
| 618 | $def, | ||||||||||||||||||||||||||||||||
| 619 | 'this method was called over the wrong class/object', | ||||||||||||||||||||||||||||||||
| 620 | 'it seems that you call it direct an pass a wrong, first parameter into it', | ||||||||||||||||||||||||||||||||
| 621 | '1st parameter: ' . $class_param | ||||||||||||||||||||||||||||||||
| 622 | ); | ||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||
| 624 | 0 | return; | |||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||
| 626 | # STATIC void | ||||||||||||||||||||||||||||||||
| 627 | 1 | ▶ | sub _throw_access_error { | ||||||||||||||||||||||||||||||
|
Subroutine
_throw_access_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 628 | 1 | my ($class, $def, @msg) = @_; | |||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||
| 630 | 1 | _croak("Error in access " . | |||||||||||||||||||||||||||||||
| 631 | ":\n $def->{'sub_data'}->{'class'}->$def->{'sub_data'}->{'sub_name'}($def->{'sub_data'}->{'data'})\n" . | ||||||||||||||||||||||||||||||||
| 632 | " > " . join("\n > ", @msg) . "\n\n"); | ||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||
| 634 | 3 | 1; | |||||||||||||||||||||||||||||||