| 1 | ## no critic qw(ProhibitUselessNoCritic PodSpelling ProhibitExcessMainComplexity) # DEVELOPER DEFAULT 1a: allow unreachable & POD-commented code; SYSTEM SPECIAL 4: allow complex code outside subroutines, must be on line 1 | ||
| 2 | package Perl::Structure::Array::SubTypes; | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Perl::Config; # don't use Perl::Types inside itself, in order to avoid circular includes | ||
| 6 | our $VERSION = 0.017_000; | ||
| 7 | |||
| 8 | # [[[ CRITICS ]]] | ||
| 9 | ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator | ||
| 10 | ## no critic qw(ProhibitUnreachableCode RequirePodSections RequirePodAtEnd) # DEVELOPER DEFAULT 1b: allow unreachable & POD-commented code, must be after line 1 | ||
| 11 | ## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils | ||
| 12 | ## no critic qw(Capitalization ProhibitMultiplePackages ProhibitReusedNames) # SYSTEM DEFAULT 3: allow multiple & lower case package names | ||
| 13 | |||
| 14 | # [[[ EXPORTS ]]] | ||
| 15 | # DEV NOTE, CORRELATION #rp051: hard-coded list of RPerl data types and data structures | ||
| 16 | use Exporter 'import'; | ||
| 17 | our @EXPORT = qw( | ||
| 18 | arrayref_CHECK | ||
| 19 | arrayref_CHECKTRACE | ||
| 20 | ); | ||
| 21 | our @EXPORT_OK = qw(); | ||
| 22 | |||
| 23 | # [[[ ARRAY ]]] | ||
| 24 | # [[[ ARRAY ]]] | ||
| 25 | # [[[ ARRAY ]]] | ||
| 26 | |||
| 27 | # an array is a 1-dimensional list/vector/sequence/set of data types; | ||
| 28 | # we never use this type directly, instead we always use the arrayref type, | ||
| 29 | # per LMPC #27: Thou Shalt Not Use Direct Access To Arrays & Hashes Stored In @ Or % Non-Scalar Variables | ||
| 30 | package array; | ||
| 31 | use strict; | ||
| 32 | use warnings; | ||
| 33 | use parent qw(Perl::Structure::Array); | ||
| 34 | |||
| 35 | # [[[ ARRAY REF ]]] | ||
| 36 | # [[[ ARRAY REF ]]] | ||
| 37 | # [[[ ARRAY REF ]]] | ||
| 38 | |||
| 39 | # ref to array | ||
| 40 | package arrayref; | ||
| 41 | use strict; | ||
| 42 | use warnings; | ||
| 43 | #use parent -norequire, qw(ref); # NEED REMOVE: properly replaced by line below? | ||
| 44 | use parent -norequire, qw(Perl::Structure::Array::Reference); | ||
| 45 | use Carp; | ||
| 46 | |||
| 47 | # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE FOR EXPORT TO WORK ]]] | ||
| 48 | package Perl::Structure::Array::SubTypes; | ||
| 49 | use strict; | ||
| 50 | use warnings; | ||
| 51 | |||
| 52 | # [[[ TYPE-CHECKING ]]] | ||
| 53 | |||
| 54 | sub arrayref_CHECK { | ||
| 55 | { my void $RETURN_TYPE }; | ||
| 56 | ( my $possible_arrayref ) = @ARG; | ||
| 57 | if ( not( defined $possible_arrayref ) ) { | ||
| 58 | croak( "\nERROR EAVRV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref value expected but undefined/null value found,\ncroaking" ); | ||
| 59 | } | ||
| 60 | |||
| 61 | # if ( UNIVERSAL::isa( $possible_arrayref, 'ARRAY' ) ) { # DEV NOTE: I believe these 2 lines are equivalent? | ||
| 62 | if ( not( main::PerlTypes_SvAROKp($possible_arrayref) ) ) { | ||
| 63 | croak( "\nERROR EAVRV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref value expected but non-arrayref value found,\ncroaking" ); | ||
| 64 | } | ||
| 65 | return; | ||
| 66 | } | ||
| 67 | |||
| 68 | sub arrayref_CHECKTRACE { | ||
| 69 | { my void $RETURN_TYPE }; | ||
| 70 | ( my $possible_arrayref, my $variable_name, my $subroutine_name ) = @ARG; | ||
| 71 | if ( not( defined $possible_arrayref ) ) { | ||
| 72 | croak( "\nERROR EAVRV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" ); | ||
| 73 | } | ||
| 74 | if ( not( main::PerlTypes_SvAROKp($possible_arrayref) ) ) { | ||
| 75 | croak( "\nERROR EAVRV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\narrayref value expected but non-arrayref value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" ); | ||
| 76 | } | ||
| 77 | return; | ||
| 78 | } | ||
| 79 | |||
| 80 | 1; # end of package |