blib/lib/Perl/Class.pm

filter: Statementstmt 8.1% 31 / 382 Branchbran 0.0% 0 / 210 Conditioncond 0.0% 0 / 44 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 62.5% 10 / 16 Podpod 0.0% 0 / 6 totaltotal 6.0% 41 / 681 CC 130 SCAR 90.8
CC
130
Cov
5%
create_symtab_entries_and_accessors_mutators
11772.0
save_object_properties_types
90.0
properties_inherited_initialized
42.0
CRAP 8777.1
↑ Summary blib/lib/perltypessizes.pm »
1 #
2 # This file is part of Perl-Types
3 #
4 # This software is Copyright (c) 2025 by Perl Community 501(c)(3) nonprofit organization.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU General Public License, Version 3, June 2007
9 #
10 # ABSTRACT: the Perl OO base class
11 # [[[ HEADER ]]]
12 package Perl::Class;
13 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Perl::Config; # don't use Perl::Types inside itself, in order to avoid circular includes
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 our $VERSION = 0.006_000;
17  
18 # [[[ OO INHERITANCE ]]]
19 # BASE CLASS HAS NO INHERITANCE
20 # "The Buck Stops Here"
21  
22 # [[[ CRITICS ]]]
23 ## no critic qw(ProhibitStringyEval) # SYSTEM DEFAULT 1: allow eval()
24 ## no critic qw(ProhibitAutoloading RequireArgUnpacking) # SYSTEM SPECIAL 2: allow Autoload & read-only @ARG
25 ## no critic qw(ProhibitExcessComplexity) # SYSTEM SPECIAL 5: allow complex code inside subroutines, must be after line 1
26 ## no critic qw(ProhibitDeepNests) # SYSTEM SPECIAL 7: allow deeply-nested code
27 ## no critic qw(ProhibitNoStrict) # SYSTEM SPECIAL 8: allow no strict
28 ## no critic qw(RequireBriefOpen) # SYSTEM SPECIAL 10: allow complex processing with open filehandle
29  
30 # [[[ INCLUDES ]]]
31 5 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶use File::Spec; # for splitpath() to test if @INC file entries are absolute or relative
Subroutine BEGIN: called CC=1 SCAR=0.0
33 5 ▶use Scalar::Util 'reftype'; # to test for HASH ref when given initialization values for new() method
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 ▶use perltypesnamespaces_generated; # load auto-generated skip-list data
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 # [[[ OO PROPERTIES ]]]
37 # BASE CLASS HAS NO PROPERTIES
38  
39 # [[[ OO PROPERTIES SPECIAL ]]]
40 # after compiling but before runtime: create symtab entries & accessors/mutators
41 INIT { create_symtab_entries_and_accessors_mutators(\%INC); }
42  
43 # [[[ SUBROUTINES & OO METHODS ]]]
44  
45 # Perl object constructor, SHORT FORM
46 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=12.2
Pod undocumented
47 5 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 0 ▶ if ( not defined ${ $_[0] . '::properties' } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined ${$_[0] . '::properties';}) 0 0 0
49 0 croak 'ERROR ECOOOCO00, SOURCE CODE, OO OBJECT CONSTRUCTOR: Undefined hashref $properties for class ' . $_[0] . ', croaking' . "\n";
50 }
51 # return bless { %{ ${ $_[0] . '::properties' } } }, $_[0]; # DOES NOT INHERIT PROPERTIES FROM PARENT CLASSES
52 # return bless { %{ ${ $_[0] . '::properties' } }, %{ properties_inherited($_[0]) } }, $_[0]; # WHAT DOES THIS DO???
53 # return bless { %{ properties_inherited($_[0]) } }, $_[0]; # WORKS PROPERLY, BUT DOES NOT INITIALIZE PROPERTIES
54 0 return bless { %{ properties_inherited_initialized($_[0], $_[1]) } }, $_[0];
55 }
56  
57  
58 # allow properties to be initialized by passing them as hashref arg to new() method
59 0 ▶sub properties_inherited_initialized {
Subroutine properties_inherited_initialized: not called CC=6 SCAR=37.4
Pod undocumented
60 # print {*STDERR} 'in Class::properties_inherited_initialized(), top of subroutine, received $ARG[0] = ', $ARG[0], "\n";
61 # print {*STDERR} 'in Class::properties_inherited_initialized(), top of subroutine, received $ARG[1] = ', Dumper($ARG[1]), "\n";
62  
63 0 my $properties_inherited = properties_inherited($_[0]);
64  
65 0 ▶ if (defined $_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
66 0 ▶ if ((not defined reftype($_[1])) or (reftype($_[1]) ne 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined builtin::reftype($_[1]) or builtin::reftype($_[1]) ne "HASH") 0 0 0
Condition0%0/3
not defined builtin::reftype($_[1]) or builtin::reftype($_[1]) ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined builtin::reftype($_[1]) or builtin::reftype($_[1]) ne "HASH"
not defined builtin::reftype($_[1]) builtin::reftype($_[1]) ne "HASH"
Truth table0%0/3
not(A) or B
A= not defined builtin::reftype($_[1])B= builtin::reftype($_[1]) ne "HASH"
ABresult
1X1
011
000
67 0 croak 'ERROR ECOOOCO01, SOURCE CODE, OO OBJECT CONSTRUCTOR: Initialization values for new() method must be key-value pairs inside a hash reference, croaking';
68 }
69 0 foreach my $property_name (sort keys %{$_[1]}) {
70 0 ▶ if (not exists $properties_inherited->{$property_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $properties_inherited->{$property_name}) 0 0 0
71 0 croak 'ERROR ECOOOCO02, SOURCE CODE, OO OBJECT CONSTRUCTOR: Attempted initialization of invalid property ' . q{'} . $property_name . q{'} . ', croaking';
72 }
73 0 $properties_inherited->{$property_name} = $_[1]->{$property_name};
74 }
75 }
76  
77 0 return $properties_inherited;
78 }
79  
80  
81 # inherit properties from parent and grandparent classes
82 0 ▶sub properties_inherited {
Subroutine properties_inherited: not called CC=5 SCAR=30.1
Pod undocumented
83 # print {*STDERR} 'in Class::properties_inherited(), top of subroutine, received $ARG[0] = ', $ARG[0], "\n";
84 5 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 # always keep self class' $properties
87 0 my $properties = { %{ ${ $ARG[0] . '::properties' } } };
88  
89 # inherit parent & (great*)grandparent class' $properties
90 0 foreach my $parent_package_name (@{ $ARG[0] . '::ISA' }) {
91 # print {*STDERR} 'in Class::properties_inherited(), top of foreach() loop, have $parent_package_name = ', $parent_package_name, "\n";
92  
93 # DEV NOTE: changed from original RPerl version, WBRASWELL 20230219
94 # DEV NOTE: changed from original RPerl version, WBRASWELL 20230219
95 # DEV NOTE: changed from original RPerl version, WBRASWELL 20230219
96 # base class has no $properties, skip
97 0 ▶ if ($parent_package_name eq 'Perl::Class') {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent_package_name eq "Perl::Class") 0 0 0
98 # Perl base class & Eyapp classes have no $properties, skip
99 # if (($parent_package_name eq 'Perl::Class') or
100 # ($parent_package_name eq 'Parse::Eyapp::Node')) {
101 0 next;
102 }
103  
104 # recurse to get inherited $properties
105 0 my $parent_and_grandparent_properties = properties_inherited($parent_package_name);
106  
107 # self class' $properties override inherited $properties, same as C++
108 0 foreach my $parent_property_key (keys %{ $parent_and_grandparent_properties }) {
109 0 ▶ if (not exists $properties->{$parent_property_key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $properties->{$parent_property_key}) 0 0 0
110 0 $properties->{$parent_property_key} = $parent_and_grandparent_properties->{$parent_property_key};
111 }
112 }
113 }
114 0 return $properties;
115 }
116  
117  
118 # DEV NOTE, RPERL REFACTOR: copied create_symtab_entries_and_accessors_mutators() from the old 'lib/RPerl/CompileUnit/Module/Class.pm' module
119 # NEED ANSWER: does this subroutine really belong here in 'lib/Perl/Class.pm', or do we need to create `lib/Perl/HelperFunctions.pm` etc?
120 # create symbol table entries for all Perl::Types subroutines/methods, and accessors/mutators for all Perl::Types class properties
121 0 ▶sub create_symtab_entries_and_accessors_mutators {
Subroutine create_symtab_entries_and_accessors_mutators: not called CC=108 SCAR=93.7
Pod undocumented
122 0 (my $INC_ref) = @ARG;
123 # $Perl::DEBUG = 1;
124 # $Perl::VERBOSE = 1;
125  
126 # add calling .pl driver to INC for subroutine activation;
127 # DEV NOTE: should be safe to use basename() here instead of fileparse(), because $PROGRAM_NAME should never end in a directory
128 0 $INC{ basename($PROGRAM_NAME) } = $PROGRAM_NAME;
129  
130 # Perl::diag('in Class::INIT() block, have $INC_ref =' . "\n" . Dumper($INC_ref) . "\n");
131 # Perl::diag('in Class::INIT() block, have $perltypesnamespaces_generated::CORE =' . "\n" . Dumper($perltypesnamespaces_generated::CORE) . "\n");
132  
133 0 my $module_filename_long; # string
134 0 my $module_filename_long_processed = {}; # hashref::boolean
135 0 my $module_file_line_remainder; # string
136 my $use_perltypes; # boolean
137 0 my $inside_package; # boolean
138 0 my $package_name; # string
139 0 my $package_name_underscores; # string
140 0 my $namespace_root; # string
141 0 my $object_properties; # hashref
142 0 my $object_properties_string; # string
143 0 my $object_properties_types; # hashref
144 0 my $inside_object_properties; # boolean
145 0 my $subroutine_type; # string
146 0 my $subroutine_name; # string
147 0 my $CHECK; # string
148 0 my $inside_subroutine; # boolean
149 0 my $inside_subroutine_header; # boolean
150 0 my $inside_subroutine_arguments; # boolean
151 0 my $subroutine_arguments_line; # string
152 0 my $TYPES_SUPPORTED = {}; # hashref::string
153  
154 # Perl::diag(q{in Class::INIT() block, have $PROGRAM_NAME = '} . $PROGRAM_NAME . "'\n");
155  
156 0 foreach my $type (@{$perltypes::SUPPORTED}, @{$perltypes::SUPPORTED_SPECIAL}) {
157 0 $TYPES_SUPPORTED->{$type} = 1;
158 }
159 # Perl::diag(q{in Class::INIT() block, have $TYPES_SUPPORTED = } . Dumper($TYPES_SUPPORTED) . "\n");
160  
161 0 MODULE_SCAN: foreach my $module_filename_short ( sort keys %{$INC_ref} ) {
162 # Perl::diag('in Class::INIT() block, have $module_filename_short = ', q{'}, $module_filename_short, q{'}, "\n");
163  
164 # skip special entry created by Filter::Util::Call
165 0 ▶ if ( $module_filename_short eq '-e' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($module_filename_short eq '-e') { } 0 0 0
elsif (substr($module_filename_short, -3, 3) eq '.ix') { } 0 0 0
elsif (substr($module_filename_short, -2, 2) eq '.t') { } 0 0 0
166 0 next;
167 }
168 # skip autosplit index files
169 elsif (( substr $module_filename_short, -3, 3 ) eq '.ix') {
170 0 next;
171 }
172 # skip test files
173 elsif (( substr $module_filename_short, -2, 2 ) eq '.t') {
174 0 next;
175 }
176  
177 0 $module_filename_long = $INC{$module_filename_short};
178 # Perl::diag( 'in Class::INIT() block, have $module_filename_long = ' . $module_filename_long . "\n" );
179  
180 # determine if both short & long module filenames are absolute;
181 # file names w/out any volume or directories are not absolute, allows 'use Foo;' where "Foo.pm" exists in current directory w/out any volume or directory
182 0 my $module_is_absolute = 0;
183 0 ▶ if (defined $module_filename_long) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $module_filename_long) 0 0 0
184 # skip already-processed modules, triggered by imaginary $module_filename_short created by Perl in %INC when one .pm file contains multiple packages
185 0 ▶ if (exists $module_filename_long_processed->{$module_filename_long}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $module_filename_long_processed->{$module_filename_long}) 0 0 0
186 # Perl::diag( 'in Class::INIT() block, skipping due to already-processed PM file, have $module_filename_long = ', q{'}, $module_filename_long, q{'}, ', $module_filename_short = ', q{'}, $module_filename_short, q{'}, "\n" );
187 0 next;
188 }
189 0 $module_filename_long_processed->{$module_filename_long} = 1;
190  
191 0 (my $module_volume, my $module_directories, my $module_file) = File::Spec->splitpath( $module_filename_long );
192 # Perl::diag( 'in Class::INIT() block, have $module_volume = ' . q{'} . $module_volume . q{'} . "\n" );
193 # Perl::diag( 'in Class::INIT() block, have $module_directories = ' . q{'} . $module_directories . q{'} . "\n" );
194 # Perl::diag( 'in Class::INIT() block, have $module_file = ' . q{'} . $module_file . q{'} . "\n" );
195 # if (($module_volume ne q{}) or ($module_directories ne q{})) { # DEV NOTE: this isn't right, if the volume is empty then it can't be absolute regardless of directories
196 0 ▶ if ($module_volume ne q{}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_volume ne "") 0 0 0
197 0 ▶ if ( $module_filename_long eq $module_filename_short ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_filename_long eq $module_filename_short) 0 0 0
198 # absolute module names include volume, and must match both short & long filenames
199 0 $module_is_absolute = 1;
200 }
201 }
202 }
203  
204 # Perl::diag( 'in Class::INIT() block, have $module_is_absolute = ' . $module_is_absolute . "\n" );
205  
206 # skip absolute file names (such as Komodo's perl5db.pl) which came from a runtime `require $scalar` or `require 'foo.pm'`,
207 # because we can not determine the correct package from the absolute path name, and we don't know how to figure out which part was in @INC from the absolute path;
208 0 ▶ if ((not defined $module_filename_long) or $module_is_absolute) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $module_filename_long or $module_is_absolute) 0 0 0
Condition0%0/3
not defined $module_filename_long or $module_is_absolute
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $module_filename_long or $module_is_absolute
not defined $module_filename_long $module_is_absolute
Truth table0%0/3
not(A) or B
A= not defined $module_filename_longB= $module_is_absolute
ABresult
1X1
011
000
209 # Perl::diag( 'in Class::INIT() block, skipping due to undefined or absolute module filename' . "\n" );
210 0 next;
211 }
212  
213 # skip already-compiled files with PMC counterparts
214 0 ▶ if (-e ($module_filename_long . 'c')) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $module_filename_long . 'c') 0 0 0
215 # Perl::diag( 'in Class::INIT() block, skipping due to already-compiled PMC file' . "\n" );
216 0 next;
217 }
218  
219 0 $module_file_line_remainder = q{};
220 0 $use_perltypes = 0;
221 0 $inside_package = 0;
222 0 $package_name = q{};
223 0 $CHECK = $Perl::CHECK; # reset data type checking to Perl::Types default for every file
224 0 $object_properties_string = q{};
225 0 $object_properties_types = {};
226 0 $inside_object_properties = 0;
227 0 $inside_subroutine = 0;
228 0 $inside_subroutine_header = 0;
229 0 $inside_subroutine_arguments = 0;
230 0 $subroutine_arguments_line = q{};
231  
232 0 $namespace_root = Perl::filename_short_to_namespace_root_guess($module_filename_short);
233 # detect if this module declares OO properties
234 0 my $has_properties = 0;
235 0 ▶ if (defined $module_filename_long) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $module_filename_long) 0 0 0
236 0 ▶ open my $FH, '<', $module_filename_long or croak $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
open my $FH, "<", $module_filename_long or croak($Perl::Class::OS_ERROR) 0 0 0
237 0 local $/ = undef;
238 0 my $text = <$FH>;
239 0 ▶ close $FH or croak $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
close $FH or croak($Perl::Class::OS_ERROR) 0 0 0
240 0 ▶ $has_properties = 1 if $text =~ /\bour\s+hashref\s+\$properties\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\bour\s+hashref\s+\$properties\b/ 0 0 0
241 }
242  
243 # Perl::diag(q{in Class::INIT() block, have $namespace_root = '} . $namespace_root . "'\n"); # repeated below, inside if() statement for concise debug output
244  
245 # DEV NOTE: avoid error...
246 # Name "perltypesnamespaces_generated::PERLTYPES_DEPS" used only once: possible typo
247 0 my $tmp = $perltypesnamespaces_generated::NONCOMPILED;
248 0 $tmp = $perltypesnamespaces_generated::CORE;
249 0 $tmp = $perltypesnamespaces_generated::PERLTYPES_DEPS;
250  
251 # do NOT skip these file(s): compilable driver, modules with OO properties, or those not in skip-lists
252 0 ▶ if ( (substr($module_filename_short, -13, 13) eq 'Compilable.pm')
Branch: 1 branch
BranchTrueFalseTotal
if (substr($module_filename_short, -13, 13) eq "Compilable.pm" or $has_properties or not exists $perltypesnamespaces_generated::NONCOMPILED->{$namespace_root} || exists $perltypesnamespaces_generated::CORE->{$namespace_root} || exists $perltypesnamespaces_generated::PERLTYPES_DEPS->{$namespace_root} || exists $perltypesnamespaces_generated::PERLTYPES_FILES->{$module_filename_short}) 0 0 0
Condition0%0/15
substr($module_filename_short, -13, 13) eq "Compilable.pm" or $has_properties or not exists $perltypesnamespaces_generated::NONCOMPILED->{$namespace_root} || exists $perltypesnamespaces_generated::CORE->{$namespace_root} || exists $perltypesnamespaces_generated::PERLTYPES_DEPS->{$namespace_root} || exists $perltypesnamespaces_generated::PERLTYPES_FILES->{$module_filename_short}
l!l&&r!l&&!r
000
substr($module_filename_short, -13, 13) eq "Compilable.pm" or $has_properties
l!l&&r!l&&!r
000
exists $perltypesnamespaces_generated::NONCOMPILED->{$namespace_root} || exists $perltypesnamespaces_generated::CORE->{$namespace_root} || exists $perltypesnamespaces_generated::PERLTYPES_DEPS->{$namespace_root} || exists $perltypesnamespaces_generated::PERLTYPES_FILES->{$module_filename_short}
l!l&&r!l&&!r
000
exists $perltypesnamespaces_generated::NONCOMPILED->{$namespace_root} or exists $perltypesnamespaces_generated::CORE->{$namespace_root} or exists $perltypesnamespaces_generated::PERLTYPES_DEPS->{$namespace_root}
l!l&&r!l&&!r
000
exists $perltypesnamespaces_generated::NONCOMPILED->{$namespace_root} or exists $perltypesnamespaces_generated::CORE->{$namespace_root}
l!l&&r!l&&!r
000
MC/DC0%0/6
substr($module_filename_short, -13, 13) eq "Compilable.pm" or $has_properties or not exists $perltypesnamespaces_generated::NONCOMPILED->{$namespace_root} || exists $perltypesnamespaces_generated::CORE->{$namespace_root} || exists $perltypesnamespaces_generated::PERLTYPES_DEPS->{$namespace_root} || exists $perltypesnamespaces_generated::PERLTYPES_FILES->{$module_filename_short}
substr($module_filename_short, -13, 13) eq "Compilable.pm" $has_properties exists $perltypesnamespaces_generated::NONCOMPILED->{$namespace_root} exists $perltypesnamespaces_generated::CORE->{$namespace_root} exists $perltypesnamespaces_generated::PERLTYPES_DEPS->{$namespace_root} exists $perltypesnamespaces_generated::PERLTYPES_FILES->{$module_filename_short}
Truth table0%0/7
A or B or not(C or D or E || F)
A= substr($module_filename_short, -13, 13) eq "Compilable.pm"B= $has_propertiesC= exists $perltypesnamespaces_generated::NONCOMPILED->{$namespace_root}D= exists $perltypesnamespaces_generated::CORE->{$namespace_root}E= exists $perltypesnamespaces_generated::PERLTYPES_DEPS->{$namespace_root}F= exists $perltypesnamespaces_generated::PERLTYPES_FILES->{$module_filename_short}
ABCDEFresult
1XXXXX1
01XXXX1
0000001
001XXX0
0001XX0
00001X0
0000010
253 or $has_properties
254 or ( (not exists $perltypesnamespaces_generated::NONCOMPILED->{$namespace_root})
255 and (not exists $perltypesnamespaces_generated::CORE->{$namespace_root})
256 and (not exists $perltypesnamespaces_generated::PERLTYPES_DEPS->{$namespace_root})
257 and (not exists $perltypesnamespaces_generated::PERLTYPES_FILES->{$module_filename_short})
258 )
259 )
260 {
261 # Perl::diag("\n\n", '=' x 50, "\n" );
262 # Perl::diag( 'in Class::INIT() block, not skipping due to CORE & PERLTYPES_DEPS namespaces, $module_filename_long = ' . $module_filename_long . "\n" );
263 # Perl::diag(q{in Class::INIT() block, have $namespace_root = '} . $namespace_root . "'\n");
264  
265 # debug: report module reaching scan stage (has properties = $has_properties)
266 0 Perl::diag("DEBUG: scanning module short='$module_filename_short', long='$module_filename_long', root='$namespace_root', has_properties=$has_properties\n");
267 # proceed to parse this module for OO properties
268 0 ▶ open my $MODULE_FILE, '<', $module_filename_long or croak $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
open my $MODULE_FILE, "<", $module_filename_long or croak($Perl::Class::OS_ERROR) 0 0 0
269 MODULE_FILE_LINE_LOOP:
270 0 ▶ while ( my $module_file_line = <$MODULE_FILE> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $module_file_line = readline $MODULE_FILE)) 0 0 0
271 0 MODULE_FILE_LINE_LOOP_INNER:
272 chomp $module_file_line;
273  
274 # Perl::diag('in Class::INIT() block, have $module_file_line =' . "\n" . $module_file_line . "\n");
275  
276 # set data type checking mode
277 0 ▶ if ( $module_file_line =~ /^\s*\#\s*\<\<\<\s*TYPE_CHECKING\s*\:\s*(\w+)\s*\>\>\>/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /^\s*\#\s*\<\<\<\s*TYPE_CHECKING\s*\:\s*(\w+)\s*\>\>\>/msx) 0 0 0
278  
279 # Perl::diag( "in Class::INIT() block, have \$module_filename_long = '$module_filename_long'\n" );
280 0 ▶ if ($inside_subroutine) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inside_subroutine) { } 0 0 0
281  
282 # Perl::diag( 'in Class::INIT() block, found <<< TYPE_CHECKING: ' . $1 . ' >>> while inside subroutine ' . $subroutine_name . '(), aborting Perl::Types activation of entire file' . "\n" );
283 0 last;
284 }
285 else {
286 # Perl::diag( 'in Class::INIT() block, found <<< TYPE_CHECKING: ' . $1 . " >>>\n" );
287 0 $CHECK = $1;
288 }
289 }
290  
291 # skip single-line comments
292 0 ▶ next if ( $module_file_line =~ /^\s*\#/xms );
Branch: 1 branch
BranchTrueFalseTotal
if $module_file_line =~ /^\s*\#/msx 0 0 0
293  
294 # skip multi-line POD comments
295 0 ▶ if ( $module_file_line =~ /^\=(\w+)/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /^\=(\w+)/msx) 0 0 0
296  
297 # Perl::diag("in Class::INIT() block, skipping multi-line POD comment, have \$1 = '$1'\n");
298 0 $module_file_line = <$MODULE_FILE>;
299 0 ▶ if ( not defined $module_file_line ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $module_file_line) 0 0 0
300 0 Perl::warning( "End of file '$module_filename_long' reached without finding '=cut' end of multi-line POD comment '=$1'\n" );
301 0 last;
302 }
303 0 ▶ while ( $module_file_line !~ /^\=cut/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module_file_line =~ /^\=cut/msx) 0 0 0
304 0 ▶ if ( not defined $module_file_line ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $module_file_line) 0 0 0
305 0 Perl::warning( "End of file '$module_filename_long' reached without finding '=cut' end of multi-line POD comment '=$1'\n" );
306 0 last;
307 }
308 0 $module_file_line = <$MODULE_FILE>;
309 }
310 0 next;
311 }
312  
313 # skip multi-line heredocs
314 0 ▶ if ( ( $module_file_line =~ /\=\s*\<\<\s*(\w+)\s*\;\s*$/xms )
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /\=\s*\<\<\s*(\w+)\s*\;\s*$/msx or $module_file_line =~ /\=\s*\<\<\s*\'(\w+)\'\s*\;\s*$/msx or $module_file_line =~ /\=\s*\<\<\s*\"(\w+)\"\s*\;\s*$/msx) 0 0 0
Condition0%0/6
$module_file_line =~ /\=\s*\<\<\s*(\w+)\s*\;\s*$/msx or $module_file_line =~ /\=\s*\<\<\s*\'(\w+)\'\s*\;\s*$/msx or $module_file_line =~ /\=\s*\<\<\s*\"(\w+)\"\s*\;\s*$/msx
l!l&&r!l&&!r
000
$module_file_line =~ /\=\s*\<\<\s*(\w+)\s*\;\s*$/msx or $module_file_line =~ /\=\s*\<\<\s*\'(\w+)\'\s*\;\s*$/msx
l!l&&r!l&&!r
000
MC/DC0%0/3
$module_file_line =~ /\=\s*\<\<\s*(\w+)\s*\;\s*$/msx or $module_file_line =~ /\=\s*\<\<\s*\'(\w+)\'\s*\;\s*$/msx or $module_file_line =~ /\=\s*\<\<\s*\"(\w+)\"\s*\;\s*$/msx
$module_file_line =~ /\=\s*\<\<\s*(\w+)\s*\;\s*$/msx $module_file_line =~ /\=\s*\<\<\s*\'(\w+)\'\s*\;\s*$/msx $module_file_line =~ /\=\s*\<\<\s*\"(\w+)\"\s*\;\s*$/msx
Truth table0%0/4
A or B or C
A= $module_file_line =~ /\=\s*\<\<\s*(\w+)\s*\;\s*$/msxB= $module_file_line =~ /\=\s*\<\<\s*\'(\w+)\'\s*\;\s*$/msxC= $module_file_line =~ /\=\s*\<\<\s*\"(\w+)\"\s*\;\s*$/msx
ABCresult
1XX1
01X1
0011
0000
315 or ( $module_file_line =~ /\=\s*\<\<\s*\'(\w+)\'\s*\;\s*$/xms )
316 or ( $module_file_line =~ /\=\s*\<\<\s*\"(\w+)\"\s*\;\s*$/xms ) )
317 {
318 # Perl::diag("in Class::INIT() block, skipping multi-line heredoc, have \$1 = '$1'\n");
319 0 $module_file_line = <$MODULE_FILE>;
320 0 ▶ if ( not defined $module_file_line ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $module_file_line) 0 0 0
321 0 Perl::warning( "End of file '$module_filename_long' reached without finding '$1' end of multi-line heredoc string\n" );
322 0 last;
323 }
324 0 ▶ while ( $module_file_line !~ /^$1/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module_file_line =~ /^$1/msx) 0 0 0
325 0 $module_file_line = <$MODULE_FILE>;
326 0 ▶ if ( not defined $module_file_line ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $module_file_line) 0 0 0
327 0 Perl::warning( "End of file '$module_filename_long' reached without finding '$1' end of multi-line heredoc string\n" );
328 0 last;
329 }
330 }
331 0 next;
332 }
333  
334 # skip __DATA__ footer
335 0 ▶ if ( $module_file_line eq '__DATA__' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line eq "__DATA__") 0 0 0
336 # if ($inside_subroutine) { Perl::diag( 'in Class::INIT() block, skipping __DATA__ footer while inside subroutine ' . $subroutine_name . '(), aborting Perl::Types activation of entire file' . "\n" ); }
337 # else { Perl::diag('in Class::INIT() block, skipping __DATA__ footer' . "\n"); }
338 0 last;
339 }
340  
341 # skip __END__ footer
342 0 ▶ if ( $module_file_line eq '__END__' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line eq "__END__") 0 0 0
343 # if ($inside_subroutine) { Perl::diag( 'in Class::INIT() block, skipping __END__ footer while inside subroutine ' . $subroutine_name . '(), aborting Perl::Types activation of entire file' . "\n" ); }
344 # else { Perl::diag('in Class::INIT() block, skipping __END__ footer' . "\n"); }
345 0 last;
346 }
347  
348 0 ▶ if ($module_file_line =~ m/sub\s*/xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /sub\s*/msx) 0 0 0
349 # Perl::diag("in Class::INIT() block, have \$module_file_line =\n$module_file_line\n");
350 }
351  
352 # create ops/types reporting subroutine & accessor/mutator object methods for each Perl::Types package
353  
354 # user-style Perl::Types header: accept 'use Perl::Types;', 'use perltypes;', or 'use types;'
355 0 ▶ if ( $module_file_line =~ /^\s*use\s+((?:Perl::Types|perltypes|types))\s*;/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /^\s*use\s+((?:Perl::Types|perltypes|types))\s*;/msx) 0 0 0
356 # Perl::diag(q{in Class::INIT() block, found user-style Perl::Types header '} . $1 . q{' in $module_filename_short = } . $module_filename_short . "\n");
357 0 $use_perltypes = 1;
358 0 next;
359 }
360  
361 # package declaration
362 0 ▶ if ( $module_file_line =~ /^\s*package\s+/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /^\s*package\s+/msx) 0 0 0
363 # Perl::diag( 'in Class::INIT() block, found package declaration', "\n" );
364  
365 # object properties, save types from just-finished package
366 0 ▶ if ($inside_package) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inside_package) 0 0 0
367 # Perl::diag( 'in Class::INIT() block, already $inside_package, about to call save_object_properties_types()...', "\n" );
368 0 $object_properties_types = save_object_properties_types( $package_name, $object_properties_string, $object_properties_types );
369 # Perl::diag( 'in Class::INIT() block, already $inside_package, ret from save_object_properties_types()', "\n" );
370 0 $object_properties_string = q{};
371 }
372 0 $inside_package = 1;
373  
374 # one-line package declaration, indexed by PAUSE unless listed in no_index in Makefile.PL
375 0 ▶ if ( $module_file_line =~ /^\s*package\s+(\w+(::\w+)*)\;.*$/xms ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($module_file_line =~ /^\s*package\s+(\w+(::\w+)*)\;.*$/msx) { } 0 0 0
elsif ($module_file_line =~ /^\s*package\s*\#\s*hide.*$/msx) { } 0 0 0
376 0 $package_name = $1;
377 # Perl::diag( 'in Class::INIT() block, one-line package declaration, have $package name = ' . $package_name . "\n" );
378 }
379  
380 # two-line package declaration, not indexed by PAUSE
381 elsif ( $module_file_line =~ /^\s*package\s*\#\s*hide.*$/xms ) { # EX. package # hide from PAUSE indexing
382 0 $module_file_line = <$MODULE_FILE>;
383 0 chomp $module_file_line;
384 0 ▶ if ( $module_file_line =~ /^\s*(\w+(::\w+)*)\;.*$/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /^\s*(\w+(::\w+)*)\;.*$/msx) { } 0 0 0
385 0 $package_name = $1;
386 # Perl::diag( 'in Class::INIT() block, two-line package declaration, have $package name = ' . $package_name . "\n" );
387 }
388 else {
389 0 Perl::warning( q{Improperly formed two-line package declaration found in file '}
390 . $module_filename_long
391 . q{' near '}
392 . $module_file_line
393 . q{'});
394 }
395 }
396 else {
397 0 Perl::warning( q{Improperly formed package declaration found in file '}
398 . $module_filename_long
399 . q{' near '}
400 . $module_file_line
401 . q{'});
402 }
403  
404 0 ▶ if ($inside_subroutine) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inside_subroutine) 0 0 0
405 # Perl::diag( 'in Class::INIT() block, have $package name = ' . $package_name . 'while inside subroutine ' . $subroutine_name . '(), aborting Perl::Types activation of entire file' . "\n" );
406 0 last;
407 }
408 # else { Perl::diag( 'in Class::INIT() block, have $package name = ' . $package_name . "\n" ); }
409  
410 # system-style Perl::Types header: 3 different lines containing 'use strict;', 'use warnings;',
411 # then any of 'use Perl::Types;', 'use perltypes;', or 'use types;';
412 # don't check for $VERSION due to numerous un-versioned subtypes
413 0 ▶ if ( not $use_perltypes ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($use_perltypes) 0 0 0
414 # first line, check strict
415 0 $module_file_line = <$MODULE_FILE>;
416 0 chomp $module_file_line;
417 0 ▶ if ($module_file_line !~ /^\s*use\s+strict\s*;/xms) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module_file_line =~ /^\s*use\s+strict\s*;/msx) 0 0 0
418 # Perl::diag(q{in Class::INIT() block, failed to find Perl::Types header line 'use strict;' for $module_filename_short = } . $module_filename_short . ', aborting Perl::Types activation of entire file' . "\n");
419 0 next MODULE_FILE_LINE_LOOP;
420 }
421  
422 # second line, check warnings
423 0 $module_file_line = <$MODULE_FILE>;
424 0 chomp $module_file_line;
425 0 ▶ if ($module_file_line !~ /^\s*use\s+warnings\s*;/xms) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module_file_line =~ /^\s*use\s+warnings\s*;/msx) 0 0 0
426 # Perl::diag(q{in Class::INIT() block, failed to find Perl::Types header line 'use warnings;' for $module_filename_short = } . $module_filename_short . ', aborting Perl::Types activation of entire file' . "\n");
427 0 next MODULE_FILE_LINE_LOOP;
428  
429 }
430  
431 # third line, accept any of the Perl::Types pragmas
432 0 $module_file_line = <$MODULE_FILE>;
433 0 chomp $module_file_line;
434 0 ▶ if ($module_file_line !~ /^\s*use\s+((?:Perl::Types|perltypes|types))\s*;/xms) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module_file_line =~ /^\s*use\s+((?:Perl::Types|perltypes|types))\s*;/msx) 0 0 0
435 # Perl::diag(q{in Class::INIT() block, failed to find Perl::Types header line 'use Perl::Types;' or 'use perltypes;' or 'use types;' for $module_filename_short = } . $module_filename_short . ', aborting Perl::Types activation of entire file' . "\n");
436 0 next MODULE_FILE_LINE_LOOP;
437 }
438  
439 # Perl::diag(q{in Class::INIT() block, found system-style Perl::Types header '} . $1 . q{' in $module_filename_short = } . $module_filename_short . "\n");
440 0 $use_perltypes = 1;
441 }
442  
443 # Perl::diag(q{in Class::INIT() block, have $use_perltypes, enabling package in $module_filename_short = } . $module_filename_short . "\n");
444  
445 # ops/types reporting subroutine
446 # DEV NOTE, CORRELATION #rp018: Perl::DataStructure::Array & Hash can not 'use Perl::Types;' so they are skipped in the header-checking loop above, their *__MODE_ID() subroutines are not created below
447 0 $package_name_underscores = $package_name;
448 0 $package_name_underscores =~ s/::/__/g;
449 0 ▶ if ( not eval( 'defined &main::' . $package_name_underscores . '__MODE_ID' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval 'defined &main::' . $package_name_underscores . '__MODE_ID') 0 0 0
450 0 ▶ eval( '*main::' . $package_name_underscores . '__MODE_ID = sub { return 0; };' ) # PERLOPS_PERLTYPES is 0
Branch: 1 branch
BranchTrueFalseTotal
eval '*main::' . $package_name_underscores . '__MODE_ID = sub { return 0; };' or croak($Perl::Class::EVAL_ERROR) 0 0 0
451  
452 # eval( 'sub main::' . $package_name_underscores . '__MODE_ID { return 0; }' ) # equivalent to previous line
453 or croak($EVAL_ERROR);
454 0 ▶ if ($EVAL_ERROR) { croak($EVAL_ERROR); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Perl::Class::EVAL_ERROR) 0 0 0
455 }
456  
457 0 next;
458 }
459  
460 # object properties, remember types for deferred accessor/mutator generation below
461 0 ▶ if ( $module_file_line =~ /^\s*our\s+hashref\s+\$properties/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /^\s*our\s+hashref\s+\$properties/msx) 0 0 0
462  
463 # hard-coded example
464 #our hashref $properties = { foo => my arrayref::Foo::Bar $TYPED_foo = undef, quux => my hashref::integer $TYPED_quux = {a => 12, b => 21} };
465 0 $inside_object_properties = 1;
466 0 chomp $module_file_line; # strip trailing newline
467 0 $object_properties_string .= $module_file_line;
468 0 next;
469 }
470  
471 # create symbol table entries for methods and plain-old non-method subroutines
472 # DEPRECATED, CORRELATION #rp120: old subroutine header
473 # if ( $module_file_line =~ /^\s*our\s+([\w:]+)\s+\$(\w+)\s+\=\s+sub\s+\{/xms ) {
474 # if ( $module_file_line =~ /^\s*sub\s+(\w+)\s*\{[\s\n\r]*\{\s*my\s+([\w:]+)\s+\$RETURN_TYPE\s*\};/xms ) { # can't match multi-line content against single-line input
475  
476 # first half of subroutine header (name)
477 0 ▶ if ( $module_file_line =~ /^\s*sub\s+(\w+)\s*\{\s*(.*)$/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /^\s*sub\s+(\w+)\s*\{\s*(.*)$/msx) 0 0 0
478 # Perl::diag(q{in Class::INIT() block, found first half of subroutine header for } . $1 . q{() in $module_filename_short = } . $module_filename_short . "\n");
479 0 ▶ if ($inside_subroutine_header) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inside_subroutine_header) { } 0 0 0
480 # Perl::diag(q{in Class::INIT() block, found first half of subroutine header for } . $1 . q{() when already marked as $inside_subroutine_header for } . $subroutine_name . q{(), skipping activation of non-Perl::Types subroutine } . $subroutine_name . q{() in $module_filename_short = } . $module_filename_short . "\n");
481 0 $inside_subroutine_header = 0;
482 }
483 else {
484 0 $inside_subroutine_header = 1;
485 }
486 0 $inside_object_properties = 0;
487 0 $inside_subroutine = 0;
488 0 ▶ if ( not $use_perltypes ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($use_perltypes) 0 0 0
489 # Perl::diag(q{in Class::INIT() block, do NOT have $use_perltypes, skipping subroutine } . $1 . q{() in $module_filename_short = } . $module_filename_short . "\n");
490 0 $subroutine_name = q{};
491 0 next;
492 }
493 # else { Perl::diag(q{in Class::INIT() block, have $use_perltypes, looking for second half of header for subroutine } . $1 . q{() in $module_filename_short = } . $module_filename_short . "\n"); }
494  
495 # NEED ANSWER: should this be a croak() or die() statement instead of just an abort?
496 0 ▶ if ($inside_subroutine_arguments) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inside_subroutine_arguments) 0 0 0
497 0 Perl::warning( q{WARNING WCOPR00, PRE-PROCESSOR: Found header for subroutine $subroutine_name = } . $1 . '() while we should still be inside arguments of subroutine ' . $subroutine_name . '(), aborting Perl::Types activation of entire file' . "\n" );
498 0 $subroutine_name = q{};
499 0 last; # last line of file
500 }
501  
502 # DEV NOTE, CORRELATION #rp053: even with the upgrade to normal Perl subroutine headers, we must still activate subroutines w/out args or when type-checking is explicitly disabled with CHECK OFF, in order for Perl::Exporter to work properly, presumably because Exporter.pm runs before Class.pm and thus we can not test for the existence of __CHECKED_*() subroutines in Perl::Exporter::import()
503 # activate previous subroutine, no arguments
504 0 ▶ if ($inside_subroutine) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inside_subroutine) 0 0 0
505 # Perl::diag( q{in Class::INIT() block, have $inside_subroutine = } . $inside_subroutine . q{, about to call activate_subroutine_args_checking() while inside subroutine } . $subroutine_name . '(), no arguments assumed' . "\n" );
506 0 activate_subroutine_args_checking( $package_name, $subroutine_name, $subroutine_type, q{}, $module_filename_long );
507 }
508  
509 0 $subroutine_name = $1;
510  
511 # enable single-line subroutine headers, continue parsing same input line if it contains more data
512 0 ▶ if ($2 ne q{}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 ne "") 0 0 0
513 0 $module_file_line = $2;
514 0 goto MODULE_FILE_LINE_LOOP_INNER;
515 }
516  
517 0 next;
518 }
519  
520 # second half of subroutine header (return type), TYPO WARNING
521 0 ▶ if ( $module_file_line =~ /^\s*\{\s*my\s+([\w:]+)\s+\$RETURN_VALUE\s*\}\s*;/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /^\s*\{\s*my\s+([\w:]+)\s+\$RETURN_VALUE\s*\}\s*;/msx) 0 0 0
522 0 Perl::warning(q{WARNING WCOPR01, PRE-PROCESSOR: Likely typo of '$RETURN_VALUE' instead of '$RETURN_TYPE' in subroutine } . $subroutine_name . q{() in $module_filename_short = } . $module_filename_short . "\n");
523 }
524 # second half of subroutine header (return type)
525 0 ▶ if ( $module_file_line =~ /^\s*\{\s*my\s+([\w:]+)\s+\$RETURN_TYPE\s*\}\s*;\s*(.*)/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /^\s*\{\s*my\s+([\w:]+)\s+\$RETURN_TYPE\s*\}\s*;\s*(.*)/msx) 0 0 0
526 # Perl::diag(q{in Class::INIT() block, found second half of subroutine header for } . $subroutine_name . q{() in $module_filename_short = } . $module_filename_short . "\n");
527 0 ▶ if ($inside_subroutine_header) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inside_subroutine_header) { } 0 0 0
528 0 $inside_subroutine_header = 0;
529 }
530 else {
531 # Perl::diag(q{in Class::INIT() block, found second half of subroutine header with $RETURN_TYPE } . $1 . q{ when not already marked as $inside_subroutine_header for } . $subroutine_name . q{(), skipping activation of unknown subroutine in $module_filename_short = } . $module_filename_short . "\n");
532 0 next;
533 }
534 0 $subroutine_type = $1;
535  
536 # Perl::diag( q{in Class::INIT() block, have $subroutine_type = } . $subroutine_type . q{, and $subroutine_name = } . $subroutine_name . "()\n" );
537 # Perl::diag( q{in Class::INIT() block, have $CHECK = '} . $CHECK . "'\n" );
538  
539 # DEV NOTE, CORRELATION #rp053: even with the upgrade to normal Perl subroutine headers, we must still activate subroutines w/out args or when type-checking is explicitly disabled with CHECK OFF, in order for Perl::Exporter to work properly, presumably because Exporter.pm runs before Class.pm and thus we can not test for the existence of __CHECKED_*() subroutines in Perl::Exporter::import()
540 0 ▶ if ( $CHECK eq 'OFF' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CHECK eq 'OFF') { } 0 0 0
elsif ($CHECK ne 'ON' and $CHECK ne 'TRACE') { } 0 0 0
541 ## Perl::diag( q{in Class::INIT() block, CHECK IS OFF, about to call activate_subroutine_args_checking()...} . "\n" );
542 0 activate_subroutine_args_checking( $package_name, $subroutine_name, $subroutine_type, q{}, $module_filename_long );
543 }
544 ▶ elsif ( ( $CHECK ne 'ON' ) and ( $CHECK ne 'TRACE' ) ) {
Condition0%0/3
$CHECK ne "ON" and $CHECK ne "TRACE"
!ll&&!rl&&r
000
MC/DC0%0/2
$CHECK ne "ON" and $CHECK ne "TRACE"
$CHECK ne "ON" $CHECK ne "TRACE"
Truth table0%0/3
A and B
A= $CHECK ne "ON"B= $CHECK ne "TRACE"
ABresult
0X0
100
111
545 0 croak( 'Received invalid value '
546 . $CHECK
547 . ' for Perl::Types preprocessor directive CHECK to control data type checking, valid values are OFF, ON, and TRACE, croaking' );
548 }
549 else {
550 0 $inside_subroutine = 1;
551 }
552  
553 # enable single-line subroutine headers, continue parsing same input line if it contains more data
554 0 ▶ if ($2 ne q{}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 ne "") 0 0 0
555 0 $module_file_line = $2;
556 0 goto MODULE_FILE_LINE_LOOP_INNER;
557 }
558  
559 0 next;
560 }
561  
562 # skip class properties AKA package variables
563 0 ▶ if ( $module_file_line =~ /^\s*our\s+[\w:]+\s+\$\w+\s+\=/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /^\s*our\s+[\w:]+\s+\$\w+\s+\=/msx) 0 0 0
564 0 $inside_object_properties = 0;
565 }
566  
567 # skip non-Perl::Types-enabled subroutine/method, using normal Perl 'sub foo {}' syntax instead of Perl::Types syntax
568 # DEPRECATED, CORRELATION #rp120: old subroutine header
569 # if ( $module_file_line =~ /^\s*sub\s+[\w:]+\s+\{/xms ) {
570 # $inside_object_properties = 0;
571 # }
572  
573 # skip end-of-module line
574 0 ▶ if ( $module_file_line =~ /^\s*1\;\s+\#\ end\ of/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /^\s*1\;\s+\#\ end\ of/msx) 0 0 0
575 0 $inside_object_properties = 0;
576 }
577  
578 # object properties, continue to aggregate types
579 0 ▶ if ($inside_object_properties) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inside_object_properties) 0 0 0
580 0 chomp $module_file_line; # strip trailing newline
581 0 $object_properties_string .= $module_file_line;
582 0 next;
583 }
584  
585 # subroutine/method, process arguments and activate type checking
586 0 ▶ if ($inside_subroutine) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inside_subroutine) 0 0 0
587 0 ▶ if ( not $use_perltypes ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($use_perltypes) 0 0 0
588 # Perl::diag(q{in Class::INIT() block, do NOT have $use_perltypes, skipping inside subroutine in $module_filename_short = } . $module_filename_short . "\n");
589 0 next;
590 }
591 # else { Perl::diag(q{in Class::INIT() block, have $use_perltypes, enabling inside subroutine in $module_filename_short = } . $module_filename_short . "\n"); }
592  
593 # Perl::diag('in Class::INIT() block, have $inside_subroutine = 1', "\n");
594 # Perl::diag("in Class::INIT() block, have \$module_file_line =\n$module_file_line\n");
595 0 ▶ if ( $module_file_line =~ /^\s*\(\s*my/xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line =~ /^\s*\(\s*my/msx) 0 0 0
596 0 $inside_subroutine_arguments = 1;
597 }
598  
599 # Perl::diag( q{in Class::INIT() block, have $inside_subroutine_arguments = }, $inside_subroutine_arguments, "\n" );
600 0 ▶ if ($inside_subroutine_arguments) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inside_subroutine_arguments) 0 0 0
601 0 $subroutine_arguments_line .= $module_file_line;
602 0 ▶ if ( $subroutine_arguments_line =~ /\@ARG\;/xms ) { # @ARG; found
Branch: 1 branch
BranchTrueFalseTotal
if ($subroutine_arguments_line =~ /\@ARG\;/msx) 0 0 0
603 0 ▶ if ( not( $subroutine_arguments_line =~ /\@ARG\;\s*$/xms ) ) { # @ARG; found not at end-of-line
Branch: 1 branch
BranchTrueFalseTotal
unless ($subroutine_arguments_line =~ /\@ARG\;\s*$/msx) 0 0 0
604 # Perl::diag( q{in Class::INIT() block, found @ARG; NOT at end-of-line while inside subroutine } . $subroutine_name . '(), have $subroutine_arguments_line = ' . "\n" . $subroutine_arguments_line . "\n\n" . 'continuing Perl::Types activation of file' . "\n" );
605  
606 # separate @ARG statement from remainder of line
607 0 my $after_arg_index = (index $subroutine_arguments_line, '@ARG;') + 5;
608 0 $module_file_line_remainder = substr $subroutine_arguments_line, $after_arg_index;
609 0 $subroutine_arguments_line = substr $subroutine_arguments_line, 0, $after_arg_index;
610  
611 # Perl::diag( 'in Class::INIT() block, set $subroutine_arguments_line =' . "\n>>>" . $subroutine_arguments_line . "<<<\n" );
612 # Perl::diag( 'in Class::INIT() block, set $module_file_line_remainder =' . "\n>>>" . $module_file_line_remainder . "<<<\n" );
613  
614 # DEV NOTE: do not abort if @ARG; found not at end-of-line, separate line and continue
615 # Perl::diag( q{in Class::INIT() block, found @ARG; NOT at end-of-line while inside subroutine } . $subroutine_name . '(), have $subroutine_arguments_line = ' . "\n" . $subroutine_arguments_line . "\n\n" . 'aborting Perl::Types activation of entire file' . "\n" );
616 # last;
617 }
618  
619 # Perl::diag( q{in Class::INIT() block, found @ARG; at end-of-line while inside subroutine } . $subroutine_name . '(), have $subroutine_arguments_line = ' . "\n" . $subroutine_arguments_line . "\n" );
620  
621 0 my $subroutine_arguments = []; # arrayref::arrayref::string
622  
623 # loop once per subroutine argument
624 # while ( $subroutine_arguments_line =~ m/my\s+(\w+)\s+\$(\w+)/g ) { # WRONG: does not match scoped Class names
625 0 ▶ while ( $subroutine_arguments_line =~ m/my\s+([\w:]+)\s+\$(\w+)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subroutine_arguments_line =~ /my\s+([\w:]+)\s+\$(\w+)/g) 0 0 0
626 0 push @{$subroutine_arguments}, [ $1, $2 ];
627 # Perl::diag( q{in Class::INIT() block, have subroutine argument type = } . $1 . q{ and subroutine argument name = } . $2 . "\n" );
628 }
629  
630 # Perl::diag( q{in Class::INIT() block, have $subroutine_arguments = } . "\n" . Dumper($subroutine_arguments) . "\n" );
631  
632 0 my $subroutine_arguments_check_code = "\n"; # string
633  
634 0 ▶ if ( $CHECK eq 'ON' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($CHECK eq 'ON') { } 0 0 0
elsif ($CHECK eq 'TRACE') { } 0 0 0
635 # Perl::diag( 'in Class::INIT() block, CHECK IS ON' . "\n" );
636 0 my $i = 0; # integer
637 0 foreach my $subroutine_argument ( @{$subroutine_arguments} ) {
638 # only enable type-checking for arguments of supported type;
639 # NEED UPGRADE: enable checking of user-defined Class types & all other remaining Perl::Types types
640 0 ▶ if (exists $TYPES_SUPPORTED->{$subroutine_argument->[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$TYPES_SUPPORTED{$subroutine_argument->[0]}) 0 0 0
641 # $subroutine_arguments_check_code .= q{ } . $subroutine_argument->[0] . '_CHECK( $_[' . $i . '] );' . "\n"; # DOES NOT WORK, fails to find Perl::Exporter::integer_CHECKTRACE() etc.
642 # $subroutine_arguments_check_code .= q{ ::} . $subroutine_argument->[0] . '_CHECK( $_[' . $i . '] );' . "\n"; # DOES NOT WORK, we no longer export all the type-checking subroutines to the main '::' namespace
643 0 $subroutine_arguments_check_code .= q{ perltypes::} . $subroutine_argument->[0] . '_CHECK( $_[' . $i . '] );' . "\n"; # does work, hard-code all automatically-generated type-checking code to 'perltypes::' namespace
644 }
645 0 $i++;
646 }
647  
648 # Perl::diag( 'in Class::INIT() block, CHECK IS ON, have $subroutine_arguments_check_code = ', "\n", $subroutine_arguments_check_code, "\n" );
649 # Perl::diag( 'in Class::INIT() block, CHECK IS ON, about to call activate_subroutine_args_checking()...' . "\n" );
650 0 activate_subroutine_args_checking( $package_name, $subroutine_name, $subroutine_type, $subroutine_arguments_check_code, $module_filename_long );
651 0 $inside_subroutine = 0;
652 0 $subroutine_arguments_line = q{};
653 }
654 elsif ( $CHECK eq 'TRACE' ) {
655 # Perl::diag( 'in Class::INIT() block, CHECK IS TRACE' . "\n" );
656 # Perl::diag( 'in Class::INIT() block, CHECK IS TRACE, have $subroutine_name = ' . $subroutine_name . "\n" );
657  
658 0 my $i = 0; # integer
659 0 foreach my $subroutine_argument ( @{$subroutine_arguments} ) {
660 # Perl::diag( 'in Class::INIT() block, CHECK IS TRACE, have $subroutine_argument->[0] = ' . $subroutine_argument->[0] . "\n" );
661 # Perl::diag( 'in Class::INIT() block, CHECK IS TRACE, have $subroutine_argument->[1] = ' . $subroutine_argument->[1] . "\n" );
662  
663 # only enable type-checking for arguments of supported type;
664 # NEED UPGRADE: enable checking of user-defined Class types & all other remaining Perl::Types types
665 0 ▶ if (exists $TYPES_SUPPORTED->{$subroutine_argument->[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$TYPES_SUPPORTED{$subroutine_argument->[0]}) 0 0 0
666 # $subroutine_arguments_check_code .= q{ } . $subroutine_argument->[0] . '_CHECKTRACE( $_[' . $i . q{], '$} . $subroutine_argument->[1] . q{', '} . $subroutine_name . q{()' );} . "\n"; # DOES NOT WORK
667 # $subroutine_arguments_check_code .= q{ ::} . $subroutine_argument->[0] . '_CHECKTRACE( $_[' . $i . q{], '$} . $subroutine_argument->[1] . q{', '} . $subroutine_name . q{()' );} . "\n"; # DOES NOT WORK
668 0 $subroutine_arguments_check_code .= q{ perltypes::} . $subroutine_argument->[0] . '_CHECKTRACE( $_[' . $i . q{], '$} . $subroutine_argument->[1] . q{', '} . $subroutine_name . q{()' );} . "\n";
669 }
670 0 $i++;
671 }
672 # Perl::diag( 'in Class::INIT() block, CHECK IS TRACE, about to call activate_subroutine_args_checking()...' . "\n" );
673 0 activate_subroutine_args_checking( $package_name, $subroutine_name, $subroutine_type, $subroutine_arguments_check_code, $module_filename_long );
674 0 $inside_subroutine = 0;
675 0 $subroutine_arguments_line = q{};
676 }
677 else {
678 0 croak( 'Received invalid value '
679 . $CHECK
680 . ' for Perl::Types preprocessor directive CHECK to control data type checking, valid values are OFF, ON, and TRACE, croaking'
681 );
682 }
683 0 $inside_subroutine_arguments = 0;
684 # Perl::diag( 'in Class::INIT() block, have $subroutine_arguments_check_code =' . "\n" . $subroutine_arguments_check_code . "\n" );
685 }
686  
687 # enable @ARG; not at end-of-line, continue parsing same input line if it contains more data
688 0 ▶ if ($module_file_line_remainder ne q{}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_file_line_remainder ne "") 0 0 0
689 # Perl::diag( 'in Class::INIT() block, have non-empty $module_file_line_remainder =' . "\n>>>" . $module_file_line_remainder . "<<<\n" );
690 0 $module_file_line = $module_file_line_remainder;
691 0 $module_file_line_remainder = q{};
692 0 goto MODULE_FILE_LINE_LOOP_INNER;
693 }
694  
695 0 next; # next file line
696 }
697 }
698 }
699  
700 0 ▶ close $MODULE_FILE or croak $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
close $MODULE_FILE or croak($Perl::Class::OS_ERROR) 0 0 0
701  
702 # activate final subroutine in file, no arguments
703 0 ▶ if ($inside_subroutine) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inside_subroutine) 0 0 0
704 0 ▶ if ($inside_subroutine_arguments) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inside_subroutine_arguments) 0 0 0
705 0 croak('Did not find @ARG to end subroutine arguments before end of file, croaking');
706 }
707  
708 # DEV NOTE, CORRELATION #rp053: even with the upgrade to normal Perl subroutine headers, we must still activate subroutines w/out args or when type-checking is explicitly disabled with CHECK OFF, in order for Perl::Exporter to work properly, presumably because Exporter.pm runs before Class.pm and thus we can not test for the existence of __CHECKED_*() subroutines in Perl::Exporter::import()
709 # Perl::diag( 'in Class::INIT() block, activating final subroutine in file, no subroutine arguments found' . "\n" );
710 0 activate_subroutine_args_checking( $package_name, $subroutine_name, $subroutine_type, q{}, $module_filename_long );
711 0 $inside_subroutine = 0;
712 }
713  
714 # object properties, save final package's types
715 0 $object_properties_types = save_object_properties_types( $package_name, $object_properties_string, $object_properties_types );
716  
717 # Perl::diag( 'in Class::INIT() block, have $object_properties_types = ' . "\n" . Dumper($object_properties_types) . "\n" ) if ( keys %{$object_properties_types} );
718  
719 # accessor/mutator object methods, deferred creation for all packages found in this file
720 0 foreach $package_name ( sort keys %{$object_properties_types} ) {
721 # Perl::diag("in Class::INIT() block, about to create accessors/mutators, have \$package_name = '$package_name'\n");
722 0 $object_properties = eval "\$$package_name\:\:properties";
723  
724 0 foreach my $property_name ( sort keys %{$object_properties} ) {
725  
726 # Perl::diag("in Class::INIT() block, about to create accessors/mutators, have \$property_name = '$property_name'\n");
727 # DEV NOTE, CORRELATION #rp003: avoid re-defining class accessor/mutator methods; so far only triggered by Perl::CodeBlock::Subroutine
728 # because it has a special BEGIN{} block with multiple package names including it's own package name
729  
730 0 my $property_type = $object_properties_types->{$package_name}->{$property_name};
731 0 my $eval_string;
732 0 my $return_whole = 0;
733  
734 # Perl::diag("in Class::INIT() block, about to create accessors/mutators, have \$property_type = '$property_type'\n");
735  
736 # array element accessor/mutator
737 0 ▶ if ( ( $property_type =~ /^arrayref::/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($property_type =~ /^arrayref::/ and not eval 'defined &' . $package_name . '::get_' . $property_name . '_element') { } 0 0 0
elsif ($property_type =~ /^hashref::/ and not eval 'defined &' . $package_name . '::get_' . $property_name . '_entry_value') { } 0 0 0
Condition0%0/3
$property_type =~ /^arrayref::/ and not eval 'defined &' . $package_name . '::get_' . $property_name . '_element'
!ll&&!rl&&r
000
MC/DC0%0/2
$property_type =~ /^arrayref::/ and not eval 'defined &' . $package_name . '::get_' . $property_name . '_element'
$property_type =~ /^arrayref::/ not eval 'defined &' . $package_name . '::get_' . $property_name . '_element'
Truth table0%0/3
A and not(B)
A= $property_type =~ /^arrayref::/B= not eval 'defined &' . $package_name . '::get_' . $property_name . '_element'
ABresult
0X0
100
111
738 and ( not eval( 'defined &' . $package_name . '::get_' . $property_name . '_element' ) ) )
739 {
740 # HARD-CODED EXAMPLE
741 # sub get_foo_size { { my integer $RETURN_TYPE }; ( my Foo::Bar $self ) = @ARG; return (scalar @{$self->{foo}}); }
742 # sub get_foo_element { { my Foo::Quux $RETURN_TYPE }; ( my Foo::Bar $self, my integer $i ) = @ARG; return $self->{foo}->[$i]; }
743 # sub set_foo_element { { my void $RETURN_TYPE }; ( my Foo::Bar $self, my integer $i, my Foo::Quux $foo_element ) = @ARG; $self->{foo}->[$i] = $foo_element; }
744  
745 # Perl::diag('in Class::INIT() block, about to create accessors/mutators, have arrayref type' . "\n");
746 # DEV NOTE, CORRELATION #rp054: auto-generation of OO property accessors/mutators checks the auto-generated Perl::Types type list for base data types to determine if the entire data structure can be returned by setting ($return_whole = 1)
747 0 my $property_element_type = substr $property_type, 10; # strip leading 'arrayref::'
748 0 ▶ if ( exists $perltypesnamespaces_generated::PERLTYPES->{ $property_element_type . '::' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$perltypesnamespaces_generated::PERLTYPES{$property_element_type . '::'}) 0 0 0
749 # Perl::diag('in Class::INIT() block, about to create accessors/mutators, have Perl::Types arrayref type, setting $return_whole flag' . "\n");
750 0 $return_whole = 1;
751 }
752 # DEV NOTE: do not enable "else" below, because we always want to enable special array accessors/mutators for all array types, not just for user-defined types;
753 # use of these special accessors/mutators provide additional OO encapsulation for Perl::Types types, which is purely optional;
754 # since Perl::Types types set ($return_whole = 1) above, you can bypass getting/setting individual array elements and simply access the entire data structure directly
755 # else {
756 $eval_string
757 0 = '*{'
758 . $package_name
759 . '::get_'
760 . $property_name . '_size'
761 . '} = sub { ( my '
762 . $package_name
763 . ' $self ) = @ARG; return (scalar @{$self->{'
764 . $property_name
765 . '}}); };' . "\n";
766 0 $eval_string
767 .= '*{'
768 . $package_name
769 . '::get_'
770 . $property_name
771 . '_element'
772 . '} = sub { ( my '
773 . $package_name
774 . ' $self, my integer $i ) = @ARG; return $self->{'
775 . $property_name
776 . '}->[$i]; };' . "\n";
777 0 $eval_string
778 .= '*{'
779 . $package_name
780 . '::set_'
781 . $property_name
782 . '_element'
783 . '} = sub { ( my '
784 . $package_name
785 . ' $self, my integer $i, my '
786 . $property_element_type . ' $'
787 . $property_name
788 . '_element ) = @ARG; $self->{'
789 . $property_name
790 . '}->[$i] = $'
791 . $property_name
792 . '_element; };';
793  
794 # Perl::diag( 'in Class::INIT() block, have user-defined object array element accessor $eval_string = ' . "\n" . $eval_string . "\n" );
795 0 ▶ eval($eval_string) or croak($EVAL_ERROR);
Branch: 1 branch
BranchTrueFalseTotal
eval $eval_string or croak($Perl::Class::EVAL_ERROR) 0 0 0
796 0 ▶ if ($EVAL_ERROR) { croak($EVAL_ERROR); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Perl::Class::EVAL_ERROR) 0 0 0
797 # }
798 }
799  
800 # hash value accessor/mutator
801 ▶ elsif ( ( $property_type =~ /^hashref::/ )
Condition0%0/3
$property_type =~ /^hashref::/ and not eval 'defined &' . $package_name . '::get_' . $property_name . '_entry_value'
!ll&&!rl&&r
000
MC/DC0%0/2
$property_type =~ /^hashref::/ and not eval 'defined &' . $package_name . '::get_' . $property_name . '_entry_value'
$property_type =~ /^hashref::/ not eval 'defined &' . $package_name . '::get_' . $property_name . '_entry_value'
Truth table0%0/3
A and not(B)
A= $property_type =~ /^hashref::/B= not eval 'defined &' . $package_name . '::get_' . $property_name . '_entry_value'
ABresult
0X0
100
111
802 and ( not eval( 'defined &' . $package_name . '::get_' . $property_name . '_entry_value' ) ) )
803 {
804 # HARD-CODED EXAMPLE
805 # sub get_foo_keys { { my arrayref::string $RETURN_TYPE }; ( my Foo::Bar $self ) = @ARG; return [sort keys %{$self->{foo}}]; }
806 # sub get_foo_entry_value { { my Foo::Quux $RETURN_TYPE }; ( my Foo::Bar $self, my string $key ) = @ARG; return $self->{foo}->{$key}; }
807 # sub set_foo_entry_value { { my void $RETURN_TYPE }; ( my Foo::Bar $self, my string $key, my Foo::Quux $foo_entry_value ) = @ARG; $self->{foo}->{$key} = $foo_entry_value; }
808  
809 # Perl::diag('in Class::INIT() block, about to create accessors/mutators, have hashref type' . "\n");
810 # DEV NOTE, CORRELATION #rp054: auto-generation of OO property accessors/mutators checks the auto-generated Perl::Types type list for base data types to determine if the entire data structure can be returned by setting ($return_whole = 1)
811 0 my $property_value_type = substr $property_type, 9; # strip leading 'hashref::'
812 # Perl::diag('in Class::INIT() block, about to create accessors/mutators, have $property_value_type = ' . q{'} . $property_value_type . q{'} . "\n");
813 # Perl::diag('in Class::INIT() block, about to create accessors/mutators, have $perltypesnamespaces_generated::PERLTYPES = ' . Dumper($perltypesnamespaces_generated::PERLTYPES) . "\n");
814  
815 0 ▶ if ( exists $perltypesnamespaces_generated::PERLTYPES->{ $property_value_type . '::' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$perltypesnamespaces_generated::PERLTYPES{$property_value_type . '::'}) 0 0 0
816 # Perl::diag('in Class::INIT() block, about to create accessors/mutators, have Perl::Types hashref type, setting $return_whole flag' . "\n");
817 0 $return_whole = 1;
818 }
819 # DEV NOTE: do not enable "else" below, because we always want to enable special array accessors/mutators for all array types, not just for user-defined types;
820 # use of these special accessors/mutators provide additional OO encapsulation for Perl::Types types, which is purely optional;
821 # since Perl::Types types set ($return_whole = 1) above, you can bypass getting/setting individual array elements and simply access the entire data structure directly
822 # else {
823 $eval_string
824 0 = '*{'
825 . $package_name
826 . '::get_'
827 . $property_name . '_keys'
828 . '} = sub { ( my '
829 . $package_name
830 . ' $self ) = @ARG; return [sort keys %{$self->{'
831 . $property_name
832 . '}}]; };' . "\n";
833 0 $eval_string
834 .= '*{'
835 . $package_name
836 . '::get_'
837 . $property_name
838 . '_entry_value'
839 . '} = sub { ( my '
840 . $package_name
841 . ' $self, my string $key ) = @ARG; return $self->{'
842 . $property_name
843 . '}->{$key}; };' . "\n";
844 0 $eval_string
845 .= '*{'
846 . $package_name
847 . '::set_'
848 . $property_name
849 . '_entry_value'
850 . '} = sub { ( my '
851 . $package_name
852 . ' $self, my string $key, my '
853 . $property_value_type . ' $'
854 . $property_name
855 . '_entry_value ) = @ARG; $self->{'
856 . $property_name
857 . '}->{$key} = $'
858 . $property_name
859 . '_entry_value; };';
860  
861 # Perl::diag( 'in Class::INIT() block, have user-defined object hash value accessor $eval_string = ' . "\n" . $eval_string . "\n" );
862 0 ▶ eval($eval_string) or croak($EVAL_ERROR);
Branch: 1 branch
BranchTrueFalseTotal
eval $eval_string or croak($Perl::Class::EVAL_ERROR) 0 0 0
863 0 ▶ if ($EVAL_ERROR) { croak($EVAL_ERROR); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Perl::Class::EVAL_ERROR) 0 0 0
864 # }
865 }
866  
867 # scalar accessor/mutator
868 else {
869 0 $return_whole = 1;
870 }
871  
872 # return whole values for scalars, scalar arrayrefs, and scalar hashrefs
873 0 ▶ if ($return_whole) {
Branch: 1 branch
BranchTrueFalseTotal
if ($return_whole) 0 0 0
874 0 ▶ if ( not eval( 'defined &' . $package_name . '::get_' . $property_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval 'defined &' . $package_name . '::get_' . $property_name) 0 0 0
875 0 $eval_string = '*{' . $package_name . '::get_' . $property_name . '} = sub { return $_[0]->{' . $property_name . '}; };';
876 # Perl::diag( 'in Class::INIT() block, have $return_whole accessor $eval_string = ' . "\n" . $eval_string . "\n" );
877 0 ▶ eval($eval_string) or croak($EVAL_ERROR);
Branch: 1 branch
BranchTrueFalseTotal
eval $eval_string or croak($Perl::Class::EVAL_ERROR) 0 0 0
878 0 ▶ if ($EVAL_ERROR) { croak($EVAL_ERROR); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Perl::Class::EVAL_ERROR) 0 0 0
879 }
880  
881 0 ▶ if ( not eval( 'defined &' . $package_name . '::set_' . $property_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval 'defined &' . $package_name . '::set_' . $property_name) 0 0 0
882 0 $eval_string
883 = '*{'
884 . $package_name
885 . '::set_'
886 . $property_name
887 . '} = sub { $_[0]->{'
888 . $property_name
889 . '} = $_[1]; return $_[0]->{'
890 . $property_name . '}; };';
891 # Perl::diag( 'in Class::INIT() block, have $return_whole mutator $eval_string = ' . "\n" . $eval_string . "\n" );
892 0 ▶ eval($eval_string) or croak($EVAL_ERROR);
Branch: 1 branch
BranchTrueFalseTotal
eval $eval_string or croak($Perl::Class::EVAL_ERROR) 0 0 0
893 0 ▶ if ($EVAL_ERROR) { croak($EVAL_ERROR); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Perl::Class::EVAL_ERROR) 0 0 0
894 }
895 }
896 }
897 }
898 }
899 # else { Perl::diag('in Class::INIT() block, found existing $perltypesnamespaces_generated::CORE->{' . $namespace_root . '}, aborting Perl::Types activation of entire file' . "\n"); }
900 }
901 }
902  
903  
904 0 ▶sub save_object_properties_types {
Subroutine save_object_properties_types: not called CC=9 SCAR=45.0
Pod undocumented
905 0 ( my $package_name, my $object_properties_string, my $object_properties_types ) = @ARG;
906 0 ▶ if ( $object_properties_string eq q{} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($object_properties_string eq '') { } 0 0 0
elsif ($object_properties_string =~ /^\s*our\s+hashref\s+\$properties\s*=\s*\{\s*\}\;/msx) { } 0 0 0
907  
908 # Perl::diag( 'in Class::save_object_properties_types(), have NO PROPERTIES $object_properties_string ' . "\n" );
909 }
910 elsif ( $object_properties_string =~ /^\s*our\s+hashref\s+\$properties\s*=\s*\{\s*\}\;/xms ) {
911  
912 # Perl::diag( 'in Class::save_object_properties_types(), have EMPTY PROPERTIES $object_properties_string = ' . "\n" . $object_properties_string . "\n" );
913 }
914 else {
915 0 my $object_property_key = undef;
916 0 my $object_property_type = undef;
917 0 my $object_property_inner_type_name = undef;
918  
919 0 $object_properties_string =~ s/^\s*our\s+hashref\s+\$properties\s*=\s*\{(.*)\}\;\s*$/$1/xms; # strip everything but hash entries
920  
921 # Perl::diag( 'in Class::save_object_properties_types(), have NON-EMPTY PROPERTIES $object_properties_string = ' . "\n" . $object_properties_string . "\n\n" );
922  
923 0 ▶ if ( $object_properties_string =~ /(\w+)\s*\=\>\s*my\s+([\w:]+)\s+\$TYPED_(\w+)/gxms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object_properties_string =~ /(\w+)\s*\=\>\s*my\s+([\w:]+)\s+\$TYPED_(\w+)/gmsx) 0 0 0
924 0 $object_property_key = $1;
925 0 $object_property_type = $2;
926 0 $object_property_inner_type_name = $3;
927 }
928  
929 # Perl::diag( 'in Class::save_object_properties_types(), before while() loop, have $object_property_key = ' . $object_property_key . "\n" );
930 # Perl::diag( 'in Class::save_object_properties_types(), before while() loop, have $object_property_type = ' . $object_property_type . "\n" );
931 # Perl::diag( 'in Class::save_object_properties_types(), before while() loop, have $object_property_inner_type_name = ' . $object_property_inner_type_name . "\n" );
932  
933 0 ▶ while ( ( defined $object_property_key ) and ( defined $object_property_type ) and ( defined $object_property_inner_type_name ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $object_property_key and defined $object_property_type and defined $object_property_inner_type_name) 0 0 0
Condition0%0/6
defined $object_property_key and defined $object_property_type and defined $object_property_inner_type_name
!ll&&!rl&&r
000
defined $object_property_key and defined $object_property_type
!ll&&!rl&&r
000
MC/DC0%0/3
defined $object_property_key and defined $object_property_type and defined $object_property_inner_type_name
defined $object_property_key defined $object_property_type defined $object_property_inner_type_name
Truth table0%0/4
A and B and C
A= defined $object_property_keyB= defined $object_property_typeC= defined $object_property_inner_type_name
ABCresult
0XX0
10X0
1100
1111
934 0 ▶ if ( $object_property_key ne $object_property_inner_type_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object_property_key ne $object_property_inner_type_name) 0 0 0
935 0 die 'ERROR ECOGEPPRP20, CODE GENERATOR, INTERPRETED PERL TO COMPILED PERL, NAME-CHECKING MISMATCH: redundant inner type name ' . q{'}
936 . $object_property_inner_type_name . q{'}
937 . ' does not equal OO properties key ' . q{'}
938 . $object_property_key . q{'}
939 . ', dying' . "\n";
940 }
941 0 $object_properties_types->{$package_name}->{$object_property_key} = $object_property_type;
942  
943 0 ▶ if ( $object_properties_string =~ /(\w+)\s*\=\>\s*my\s+([\w:]+)\s+\$TYPED_(\w+)/gxms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object_properties_string =~ /(\w+)\s*\=\>\s*my\s+([\w:]+)\s+\$TYPED_(\w+)/gmsx) { } 0 0 0
944 0 $object_property_key = $1;
945 0 $object_property_type = $2;
946 0 $object_property_inner_type_name = $3;
947 }
948 else {
949 0 $object_property_key = undef;
950 0 $object_property_type = undef;
951 0 $object_property_inner_type_name = undef;
952 }
953  
954 # Perl::diag( 'in Class::save_object_properties_types(), bottom of while() loop, have $object_property_key = ' . $object_property_key . "\n" );
955 # Perl::diag( 'in Class::save_object_properties_types(), bottom of while() loop, have $object_property_type = ' . $object_property_type . "\n" );
956 # Perl::diag( 'in Class::save_object_properties_types(), bottom of while() loop, have $object_property_inner_type_name = ' . $object_property_inner_type_name . "\n" );
957 }
958 }
959 0 return $object_properties_types;
960 }
961  
962  
963 # create Perl symbol table entries for Perl::Types subroutines and methods
964 0 ▶sub activate_subroutine_args_checking {
Subroutine activate_subroutine_args_checking: not called CC=5 SCAR=31.5
Pod undocumented
965 0 ( my $package_name, my $subroutine_name, my $subroutine_type, my $subroutine_arguments_check_code, my $module_filename_long ) = @ARG;
966  
967 # Perl::diag('in Class::activate_subroutine_args_checking(), received $package_name = ' . $package_name . "\n");
968 # Perl::diag('in Class::activate_subroutine_args_checking(), received $subroutine_name = ' . $subroutine_name . "\n");
969 # Perl::diag('in Class::activate_subroutine_args_checking(), received $subroutine_type = ' . $subroutine_type . "\n");
970 # Perl::diag('in Class::activate_subroutine_args_checking(), received $subroutine_arguments_check_code = ' . $subroutine_arguments_check_code . "\n");
971 # Perl::diag('in Class::activate_subroutine_args_checking(), received $module_filename_long = ' . $module_filename_long . "\n");
972  
973 0 my $package_name_tmp; # string
974 0 my $subroutine_definition_code = q{}; # string
975 0 my $subroutine_definition_diag_code = q{}; # string
976 0 my $check_code_subroutine_name = q{}; # string
977  
978 # RPERL REFACTOR, NEED FIX: removed old '::method' types, need to check if first argument is '$self' with matching package name
979 # RPERL REFACTOR, NEED FIX: removed old '::method' types, need to check if first argument is '$self' with matching package name
980 # RPERL REFACTOR, NEED FIX: removed old '::method' types, need to check if first argument is '$self' with matching package name
981 # if ( $subroutine_type =~ /\::method$/xms ) {
982 ## Perl::diag("in Class::activate_subroutine_args_checking(), $subroutine_name is a method\n");
983 # if ( $package_name eq q{} ) {
984 # croak( 'ERROR ECOPR01, PRE-PROCESSOR: Received no package name for method ', $subroutine_name, ' in file ' . $module_filename_long . ' ... croaking' );
985 # }
986 # }
987 # else {
988 ## Perl::diag("in Class::activate_subroutine_args_checking(), $subroutine_name is not a method\n");
989 # non-method subroutines which are not inside any package are actually in the 'main' package namespace
990 0 ▶ if ( $package_name eq q{} ) { $package_name = 'main'; }
Branch: 1 branch
BranchTrueFalseTotal
if ($package_name eq "") 0 0 0
991 # }
992  
993 # $subroutine_definition_diag_code = "\n " . q{Perl::diag("IN POST-INIT, direct call MODE } . $package_name . '::' . $subroutine_name . q{\n"); };
994  
995 =comment DEPRECATED
996 # set symbol table entry for subroutine to new anonymous subroutine containing dereferenced call to real anonymous subroutine, old header style
997 $subroutine_definition_code
998 = '*{'
999 . $package_name . '::'
1000 . $subroutine_name
1001 . '} = sub { '
1002 . $subroutine_definition_diag_code
1003 . $subroutine_arguments_check_code
1004 . 'return &${'
1005 . $package_name . '::'
1006 . $subroutine_name
1007 . '(@ARG); };';
1008 =cut
1009  
1010 # re-define subroutine call to include type checking code; new header style
1011 do
1012 0 {
1013 5 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1014  
1015 # create unchecked symbol table entry for original subroutine
1016 0 *{ $package_name . '::__UNCHECKED_' . $subroutine_name } = \&{ $package_name . '::' . $subroutine_name }; # short form, symbol table direct, not strict
1017  
1018 # delete original symtab entry
1019 0 undef *{ $package_name . '::' . $subroutine_name };
1020  
1021 # re-create new symtab entry pointing to checking code plus unchecked symtab entry
1022 0 ▶ $subroutine_definition_code .=
Condition0%0/2
$subroutine_arguments_check_code || "\n"
l!l
00
MC/DC0%0/1
$subroutine_arguments_check_code || "\n"
$subroutine_arguments_check_code
Truth table0%0/2
A
A= $subroutine_arguments_check_code
Aresult
11
00
1023 '*' . $package_name . '::' . $subroutine_name . ' = sub { ' .
1024 $subroutine_definition_diag_code .
1025 ($subroutine_arguments_check_code or "\n") .
1026 ' return ' . $package_name . '::__UNCHECKED_' . $subroutine_name . '(@ARG);' . "\n" . '};';
1027  
1028 # create new checked symtab entries, for use by Exporter
1029 0 $check_code_subroutine_name = $package_name . '::__CHECK_CODE_' . $subroutine_name;
1030 0 $subroutine_definition_code .= "\n" . '*' . $package_name . '::__CHECKED_' . $subroutine_name . ' = \&' . $package_name . '::' . $subroutine_name . "\n" . ';';
1031 # ${ $check_code_subroutine_name } = $subroutine_arguments_check_code; # DOES NOT WORK
1032 # $subroutine_definition_code .= "\n" . ' $' . $check_code_subroutine_name . q{ =<<'EOF';} . "\n" . $subroutine_arguments_check_code . "\n" . 'EOF' . "\n"; # DOES NOT WORK
1033 # Perl::diag('in Class::activate_subroutine_args_checking(), have $' . $check_code_subroutine_name . ' = ' . "\n" . '[BEGIN_CHECK_CODE]' . "\n" . ${ $check_code_subroutine_name } . "\n" . ' [END_CHECK_CODE]' . "\n");
1034 # Perl::diag('in Class::activate_subroutine_args_checking(), have $' . $check_code_subroutine_name . ' = ' . "\n" . '[BEGIN_CHECK_CODE]' . "\n" . $check_code_subroutine_name . "\n" . ' [END_CHECK_CODE]' . "\n");
1035  
1036 0 $subroutine_definition_code .= "\n" . '*' . $check_code_subroutine_name . ' = sub {' . "\n" . ' my $retval ' . q{ =<<'EOF';} . "\n" . $subroutine_arguments_check_code . "\n" . 'EOF' . "\n" . '};' . "\n";
1037 };
1038  
1039 # if ($subroutine_arguments_check_code ne q{}) {
1040 # Perl::diag('in Class::activate_subroutine_args_checking(), have method $subroutine_definition_code =' . "\n" . $subroutine_definition_code . "\n");
1041 # }
1042  
1043 # eval($subroutine_definition_code) or (croak 'ERROR ECOPR02, PRE-PROCESSOR: Failed to enable type checking for subroutine ' . $package_name . '::' . $subroutine_name . '(),' . "\n" . $EVAL_ERROR . "\n" . 'croaking'); # TRIGGERS FALSE ALARMS ON OUTPUT FROM Perl::diag()
1044 0 ▶ eval($subroutine_definition_code) or (Perl::diag('ERROR ECOPR02, PRE-PROCESSOR: Possible failure to enable type checking for subroutine ' . $package_name . '::' . $subroutine_name . '(),' . "\n" . $EVAL_ERROR . "\n" . 'not croaking'));
Branch: 1 branch
BranchTrueFalseTotal
eval $subroutine_definition_code or Perl::diag('ERROR ECOPR02, PRE-PROCESSOR: Possible failure to enable type checking for subroutine ' . $package_name . '::' . $subroutine_name . '(),' . "\n" . $Perl::Class::EVAL_ERROR . "\n" . "not croaking") 0 0 0
1045 0 ▶ if ($EVAL_ERROR) { croak 'ERROR ECOPR03, PRE-PROCESSOR: Failed to enable type checking for subroutine ' . $package_name . '::' . $subroutine_name . '(),' . "\n" . $EVAL_ERROR . "\n" . 'croaking'; }
Branch: 1 branch
BranchTrueFalseTotal
if ($Perl::Class::EVAL_ERROR) 0 0 0
1046  
1047 # do { no strict;
1048 # Perl::diag('in Class::activate_subroutine_args_checking(), have ' . $check_code_subroutine_name . '() = ' . "\n" . '[BEGIN_CHECK_CODE]' . "\n" . &{ $check_code_subroutine_name } . "\n" . ' [END_CHECK_CODE]' . "\n");
1049 # };
1050 }
↑ Summary blib/lib/perltypessizes.pm »