| 1 | # [[[ HEADER ]]] | ||||||||||
| 2 | package Perl::Type::Boolean; | ||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 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
| |||||||||||
| 6 | 5 | our $VERSION = 0.010_000; | |||||||||
| 7 | |||||||||||
| 8 | # [[[ OO INHERITANCE ]]] | ||||||||||
| 9 | 5 | ▶ | use parent qw(Perl::Type::Scalar); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 5 | ▶ | use Perl::Type::Scalar; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | # [[[ CRITICS ]]] | ||||||||||
| 13 | ## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator | ||||||||||
| 14 | ## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils | ||||||||||
| 15 | ## no critic qw(Capitalization ProhibitMultiplePackages ProhibitReusedNames) # SYSTEM DEFAULT 3: allow multiple & lower case package names | ||||||||||
| 16 | |||||||||||
| 17 | # [[[ SUB-TYPES ]]] | ||||||||||
| 18 | # a boolean is a binary boolean value, the only valid values are 0 (false) or 1 (true) | ||||||||||
| 19 | package boolean; | ||||||||||
| 20 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 5 | ▶ | use parent qw(Perl::Type::Boolean); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | # [[[ SWITCH CONTEXT BACK TO PRIMARY PACKAGE ]]] | ||||||||||
| 25 | package Perl::Type::Boolean; | ||||||||||
| 26 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | # [[[ EXPORTS ]]] | ||||||||||
| 30 | 5 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 5 | our @EXPORT = qw(boolean_CHECK boolean_CHECKTRACE boolean_to_nonsigned_integer boolean_to_integer boolean_to_number boolean_to_character boolean_to_string); | |||||||||
| 32 | 5 | our @EXPORT_OK = qw(boolean_typetest0 boolean_typetest1); | |||||||||
| 33 | |||||||||||
| 34 | # [[[ TYPE-CHECKING ]]] | ||||||||||
| 35 | 0 | ▶ | sub boolean_CHECK { | ||||||||
|
Subroutine
boolean_CHECK: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 36 | 0 | { my void $RETURN_TYPE }; | |||||||||
| 37 | 0 | ( my $possible_boolean ) = @ARG; | |||||||||
| 38 | 0 | ▶ | if ( not( defined $possible_boolean ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | # croak( "\nERROR EBV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nboolean value expected but undefined/null value found,\ncroaking" ); | ||||||||||
| 40 | 0 | die( "\nERROR EBV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nboolean value expected but undefined/null value found,\ndying\n" ); | |||||||||
| 41 | } | ||||||||||
| 42 | 0 | ▶ | if ( not( main::PerlTypes_SvBOKp($possible_boolean) ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | # croak( "\nERROR EBV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nboolean value expected but non-boolean value found,\ncroaking" ); | ||||||||||
| 44 | 0 | die( "\nERROR EBV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nboolean value expected but non-boolean value found,\ndying\n" ); | |||||||||
| 45 | } | ||||||||||
| 46 | 0 | return; | |||||||||
| 47 | } | ||||||||||
| 48 | 0 | ▶ | sub boolean_CHECKTRACE { | ||||||||
|
Subroutine
boolean_CHECKTRACE: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 49 | 0 | { my void $RETURN_TYPE }; | |||||||||
| 50 | 0 | ( my $possible_boolean, my $variable_name, my $subroutine_name ) = @ARG; | |||||||||
| 51 | 0 | ▶ | if ( not( defined $possible_boolean ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | # croak( "\nERROR EBV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nboolean value expected but undefined/null value found,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ncroaking" ); | ||||||||||
| 53 | 0 | die( "\nERROR EBV00, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nboolean value expected but undefined/null value found,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ndying\n" ); | |||||||||
| 54 | } | ||||||||||
| 55 | 0 | ▶ | if ( not( main::PerlTypes_SvBOKp($possible_boolean) ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | # croak( "\nERROR EBV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nboolean value expected but non-boolean value found,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ncroaking" ); | ||||||||||
| 57 | 0 | die( "\nERROR EBV01, TYPE-CHECKING MISMATCH, PERLOPS_PERLTYPES:\nboolean value expected but non-boolean value found,\nin variable " . $variable_name . " from subroutine " . $subroutine_name . ",\ndying\n" ); | |||||||||
| 58 | } | ||||||||||
| 59 | 0 | return; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | # [[[ UNSIGNED INTEGERIFY ]]] | ||||||||||
| 63 | 0 | ▶ | sub boolean_to_nonsigned_integer { | ||||||||
|
Subroutine
boolean_to_nonsigned_integer: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 64 | 0 | { my nonsigned_integer $RETURN_TYPE }; | |||||||||
| 65 | 0 | (my boolean $input_boolean) = @ARG; | |||||||||
| 66 | # boolean_CHECK($input_boolean); | ||||||||||
| 67 | 0 | boolean_CHECKTRACE( $input_boolean, '$input_boolean', 'boolean_to_nonsigned_integer()' ); | |||||||||
| 68 | 0 | return $input_boolean; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | # [[[ INTEGERIFY ]]] | ||||||||||
| 72 | 0 | ▶ | sub boolean_to_integer { | ||||||||
|
Subroutine
boolean_to_integer: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 73 | 0 | { my integer $RETURN_TYPE }; | |||||||||
| 74 | 0 | (my boolean $input_boolean) = @ARG; | |||||||||
| 75 | # boolean_CHECK($input_boolean); | ||||||||||
| 76 | 0 | boolean_CHECKTRACE( $input_boolean, '$input_boolean', 'boolean_to_integer()' ); | |||||||||
| 77 | 0 | return $input_boolean; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | # [[[ NUMBERIFY ]]] | ||||||||||
| 81 | 0 | ▶ | sub boolean_to_number { | ||||||||
|
Subroutine
boolean_to_number: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 82 | 0 | { my number $RETURN_TYPE }; | |||||||||
| 83 | 0 | (my boolean $input_boolean) = @ARG; | |||||||||
| 84 | # boolean_CHECK($input_boolean); | ||||||||||
| 85 | 0 | boolean_CHECKTRACE( $input_boolean, '$input_boolean', 'boolean_to_number()' ); | |||||||||
| 86 | 0 | return ($input_boolean * 1.0); | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | # [[[ CHARACTERIFY ]]] | ||||||||||
| 90 | 0 | ▶ | sub boolean_to_character { | ||||||||
|
Subroutine
boolean_to_character: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 91 | 0 | { my character $RETURN_TYPE }; | |||||||||
| 92 | 0 | (my boolean $input_boolean) = @ARG; | |||||||||
| 93 | # boolean_CHECK($input_boolean); | ||||||||||
| 94 | 0 | boolean_CHECKTRACE( $input_boolean, '$input_boolean', 'boolean_to_character()' ); | |||||||||
| 95 | 0 | my string $tmp_string = boolean_to_string($input_boolean); | |||||||||
| 96 | 0 | return (substr $tmp_string, 0, 1); | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | # [[[ STRINGIFY ]]] | ||||||||||
| 100 | 0 | ▶ | sub boolean_to_string { | ||||||||
|
Subroutine
boolean_to_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 101 | 0 | { my string $RETURN_TYPE }; | |||||||||
| 102 | 0 | ( my $input_boolean ) = @ARG; | |||||||||
| 103 | # boolean_CHECK($input_boolean); | ||||||||||
| 104 | 0 | boolean_CHECKTRACE( $input_boolean, '$input_boolean', 'boolean_to_string()' ); | |||||||||
| 105 | 0 | return "$input_boolean"; | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | # [[[ TYPE TESTING ]]] | ||||||||||
| 109 | 0 | ▶ | sub boolean_typetest0 { | ||||||||
|
Subroutine
boolean_typetest0: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 110 | 0 | { my boolean $RETURN_TYPE }; | |||||||||
| 111 | # DEV NOTE: maintain independence from Integer data type, re-implement integer_to_boolean() here | ||||||||||
| 112 | # my boolean $retval = integer_to_boolean(main::Perl__Type__Boolean__MODE_ID()); | ||||||||||
| 113 | 0 | my boolean $retval = 1; | |||||||||
| 114 | 0 | ▶ | if (main::Perl__Type__Boolean__MODE_ID() == 0) { $retval = 0; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | # Perl::diag("in PERLOPS_PERLTYPES boolean_typetest0(), have \$retval = $retval\n"); | ||||||||||
| 116 | 0 | return $retval; | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 0 | ▶ | sub boolean_typetest1 { | ||||||||
|
Subroutine
boolean_typetest1: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 120 | 0 | { my boolean $RETURN_TYPE }; | |||||||||
| 121 | 0 | ( my boolean $lucky_boolean ) = @ARG; | |||||||||
| 122 | # boolean_CHECK($lucky_boolean); | ||||||||||
| 123 | 0 | boolean_CHECKTRACE( $lucky_boolean, '$lucky_boolean', 'boolean_typetest1()' ); | |||||||||
| 124 | # Perl::diag('in PERLOPS_PERLTYPES boolean_typetest1(), received $lucky_boolean = ' . boolean_to_string($lucky_boolean) . "\n"); | ||||||||||
| 125 | # DEV NOTE: maintain independence from Integer data type, re-implement integer_to_boolean() here | ||||||||||
| 126 | 0 | my boolean $retval = 1; | |||||||||
| 127 | 0 | ▶ | if (($lucky_boolean + main::Perl__Type__Boolean__MODE_ID()) == 0) { $retval = 0; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 128 | # Perl::diag("in PERLOPS_PERLTYPES boolean_typetest1(), have \$retval = $retval\n"); | ||||||||||
| 129 | 0 | return $retval; | |||||||||
| 130 | # return integer_to_boolean( $lucky_boolean + main::Perl__Type__Boolean__MODE_ID() ); | ||||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | # DEV NOTE, CORRELATION #rp018: Perl::Type::*.pm files do not 'use RPerl;' and thus do not trigger the pseudo-source-filter contained in | ||||||||||
| 134 | # RPerl::CompileUnit::Module::Class::create_symtab_entries_and_accessors_mutators(), | ||||||||||
| 135 | # so *__MODE_ID() subroutines are hard-coded here instead of auto-generated there | ||||||||||
| 136 | package main; | ||||||||||
| 137 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 138 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 139 | 0 | ▶ | sub Perl__Type__Boolean__MODE_ID { return 0; } | ||||||||
|
Subroutine
Perl__Type__Boolean__MODE_ID: not called CC=1 SCAR=6.9
| |||||||||||
| 140 | |||||||||||
| 141 | 5 | 1; # end of class | |||||||||