| 1 | # [[[ HEADER ]]] | ||
| 2 | package Perl::Type::FileHandle; | ||
| 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.006_000; | ||
| 7 | |||
| 8 | # [[[ CRITICS ]]] | ||
| 9 | ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator | ||
| 10 | ## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils | ||
| 11 | ## no critic qw(Capitalization ProhibitMultiplePackages ProhibitReusedNames) # SYSTEM DEFAULT 3: allow multiple & lower case package names | ||
| 12 | |||
| 13 | # [[[ OO INHERITANCE ]]] | ||
| 14 | use parent qw(Perl::Type); | ||
| 15 | use Perl::Type; | ||
| 16 | |||
| 17 | # [[[ SUB-TYPES BEFORE SETUP ]]] | ||
| 18 | |||
| 19 | # "If FILEHANDLE -- the first argument in a call to open -- is an undefined scalar variable | ||
| 20 | # (or array or hash element), a new filehandle is autovivified, meaning that the variable is assigned | ||
| 21 | # a reference to a newly allocated anonymous filehandle." | ||
| 22 | # https://perldoc.perl.org/functions/open#Direct-versus-by-reference-assignment-of-filehandles | ||
| 23 | |||
| 24 | package filehandleref; | ||
| 25 | use strict; | ||
| 26 | use warnings; | ||
| 27 | use parent -norequire, qw(ref); | ||
| 28 | |||
| 29 | # "Otherwise if FILEHANDLE is an expression, its value is the real filehandle. | ||
| 30 | # (This is considered a symbolic reference, so use strict "refs" should not be in effect.)" | ||
| 31 | # https://perldoc.perl.org/functions/open#Direct-versus-by-reference-assignment-of-filehandles | ||
| 32 | |||
| 33 | package filehandle; | ||
| 34 | use strict; | ||
| 35 | use warnings; | ||
| 36 | use parent qw(Perl::Type::FileHandle); | ||
| 37 | |||
| 38 | # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE ]]] | ||
| 39 | package Perl::Type::FileHandle; | ||
| 40 | use strict; | ||
| 41 | use warnings; | ||
| 42 | |||
| 43 | # [[[ OO INHERITANCE ]]] | ||
| 44 | use parent qw(Perl::Type); | ||
| 45 | use Perl::Type; | ||
| 46 | |||
| 47 | # NEED FIX: is a filehandleref really an integer?!? | ||
| 48 | |||
| 49 | # [[[ TYPE-CHECKING ]]] | ||
| 50 | sub filehandleref_CHECK { | ||
| 51 | { my void $RETURN_TYPE }; | ||
| 52 | ( my $possible_filehandleref ) = @ARG; | ||
| 53 | if ( not( defined $possible_filehandleref ) ) { | ||
| 54 | # croak( "\nERROR EFH00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nfilehandleref value expected but undefined/null value found,\ncroaking" ); | ||
| 55 | die( "\nERROR EFH00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nfilehandleref value expected but undefined/null value found,\ndying\n" ); | ||
| 56 | } | ||
| 57 | if ( not( main::PerlTypes_SvIOKp($possible_filehandleref) ) ) { | ||
| 58 | # croak( "\nERROR EFH01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nfilehandleref value expected but non-filehandleref value found,\ncroaking" ); | ||
| 59 | die( "\nERROR EFH01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nfilehandleref value expected but non-filehandleref value found,\ndying\n" ); | ||
| 60 | } | ||
| 61 | return; | ||
| 62 | } | ||
| 63 | |||
| 64 | sub filehandleref_CHECKTRACE { | ||
| 65 | { my void $RETURN_TYPE }; | ||
| 66 | ( my $possible_filehandleref, my $variable_name, my $subroutine_name ) = @ARG; | ||
| 67 | if ( not( defined $possible_filehandleref ) ) { | ||
| 68 | # croak( "\nERROR EFH00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nfilehandleref value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" ); | ||
| 69 | die( "\nERROR EFH00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nfilehandleref value expected but undefined/null value found,\nin variable $variable_name from subroutine $subroutine_name,\ndying\n" ); | ||
| 70 | } | ||
| 71 | if ( not( main::PerlTypes_SvIOKp($possible_filehandleref) ) ) { | ||
| 72 | # croak( "\nERROR EFH01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nfilehandleref value expected but non-filehandleref value found,\nin variable $variable_name from subroutine $subroutine_name,\ncroaking" ); | ||
| 73 | die( "\nERROR EFH01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nfilehandleref value expected but non-filehandleref value found,\nin variable $variable_name from subroutine $subroutine_name,\ndying\n" ); | ||
| 74 | } | ||
| 75 | return; | ||
| 76 | } | ||
| 77 | |||
| 78 | # DEV NOTE, CORRELATION #rp018: Perl::Type::*.pm files do not 'use RPerl;' and thus do not trigger the pseudo-source-filter contained in | ||
| 79 | # RPerl::CompileUnit::Module::Class::create_symtab_entries_and_accessors_mutators(), | ||
| 80 | # so *__MODE_ID() subroutines are hard-coded here instead of auto-generated there | ||
| 81 | package main; | ||
| 82 | use strict; | ||
| 83 | use warnings; | ||
| 84 | sub Perl__Type__FileHandle__MODE_ID { return 0; } | ||
| 85 | |||
| 86 | 1; # end of class |