| 1 | package ScalarTypes::NumericTypes; | ||||||||||
| 2 | |||||||||||
| 3 | # Load the Perl pragmas. | ||||||||||
| 4 | 1 | ▶ | use 5.030000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # Set the package version. | ||||||||||
| 9 | 1 | our $VERSION = '0.11'; | |||||||||
| 10 | |||||||||||
| 11 | # Load the Perl pragma Exporter. | ||||||||||
| 12 | 1 | ▶ | use Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | # Base class of this module. | ||||||||||
| 15 | 1 | our @ISA = qw(Exporter); | |||||||||
| 16 | |||||||||||
| 17 | # Exporting the implemented subroutines. | ||||||||||
| 18 | 1 | our @EXPORT = qw( | |||||||||
| 19 | is_unsigned_sepdec | ||||||||||
| 20 | is_signed_sepdec | ||||||||||
| 21 | is_unsigned_float | ||||||||||
| 22 | is_signed_float | ||||||||||
| 23 | is_unsigned_int | ||||||||||
| 24 | is_signed_int | ||||||||||
| 25 | is_decimal | ||||||||||
| 26 | is_binary | ||||||||||
| 27 | is_octal | ||||||||||
| 28 | is_hex | ||||||||||
| 29 | is_upper_hex | ||||||||||
| 30 | is_lower_hex | ||||||||||
| 31 | is_roman | ||||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | #------------------------------------------------------------------------------# | ||||||||||
| 35 | # Subroutine is_unsigned_float # | ||||||||||
| 36 | # # | ||||||||||
| 37 | # Description: # | ||||||||||
| 38 | # A unsigned float in the context of this method consists of numbers from 0 to # | ||||||||||
| 39 | # 9 and a decimal dot as separator. Spaces before and after the number are not # | ||||||||||
| 40 | # allowed. # | ||||||||||
| 41 | #------------------------------------------------------------------------------# | ||||||||||
| 42 | 0 | ▶ | sub is_unsigned_float { | ||||||||
|
Subroutine
is_unsigned_float: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 43 | # Assign the subroutine argument to the local variable. | ||||||||||
| 44 | 0 | ▶ | my $arg = (defined $_[0] ? $_[0] : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | # Set regex pattern using digits match. | ||||||||||
| 46 | 0 | my $re = qr/^(([0-9]{1}|[1-9]{1}[0-9]+)[.][0-9]+)$/; | |||||||||
| 47 | # Check the argument with the regex pattern. | ||||||||||
| 48 | 0 | ▶ | my $is_unsigned_float = (($arg =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | # Return 0 (false) or 1 (true). | ||||||||||
| 50 | 0 | return $is_unsigned_float; | |||||||||
| 51 | }; | ||||||||||
| 52 | |||||||||||
| 53 | #------------------------------------------------------------------------------# | ||||||||||
| 54 | # Subroutine is_signed_float # | ||||||||||
| 55 | # # | ||||||||||
| 56 | # Description: # | ||||||||||
| 57 | # A signed float in the context of this method consists of numbers from 0 to 9 # | ||||||||||
| 58 | # and a decimal dot as separator. Spaces before and after the number are not # | ||||||||||
| 59 | # allowed. # | ||||||||||
| 60 | #------------------------------------------------------------------------------# | ||||||||||
| 61 | 0 | ▶ | sub is_signed_float { | ||||||||
|
Subroutine
is_signed_float: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 62 | # Assign the subroutine argument to the local variable. | ||||||||||
| 63 | 0 | ▶ | my $arg = (defined $_[0] ? $_[0] : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | # Set regex pattern using digits match. | ||||||||||
| 65 | 0 | my $re = qr/^([+-]([0-9]{1}|[1-9]{1}[0-9]+)[.][0-9]+)$/; | |||||||||
| 66 | # Check the argument with the regex pattern. | ||||||||||
| 67 | 0 | ▶ | my $is_signed_float = (($arg =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | # Return 0 (false) or 1 (true). | ||||||||||
| 69 | 0 | return $is_signed_float; | |||||||||
| 70 | }; | ||||||||||
| 71 | |||||||||||
| 72 | #------------------------------------------------------------------------------# | ||||||||||
| 73 | # Subroutine is_unsigned_int # | ||||||||||
| 74 | # # | ||||||||||
| 75 | # Description: # | ||||||||||
| 76 | # A unsigned int consists of numbers from 0-9. # | ||||||||||
| 77 | #------------------------------------------------------------------------------# | ||||||||||
| 78 | 0 | ▶ | sub is_unsigned_int { | ||||||||
|
Subroutine
is_unsigned_int: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 79 | # Assign the subroutine argument to the local variable. | ||||||||||
| 80 | 0 | ▶ | my $arg = (defined $_[0] ? $_[0] : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | # Set the Perl conform regex pattern. | ||||||||||
| 82 | 0 | my $re = qr/^(([1-9][0-9]*)|0)$/; | |||||||||
| 83 | # Check the argument with the regex pattern. | ||||||||||
| 84 | 0 | ▶ | my $is_unsigned_int = (($arg =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | # Return 0 (false) or 1 (true). | ||||||||||
| 86 | 0 | return $is_unsigned_int; | |||||||||
| 87 | }; | ||||||||||
| 88 | |||||||||||
| 89 | #------------------------------------------------------------------------------# | ||||||||||
| 90 | # Subroutine is_signed_int # | ||||||||||
| 91 | # # | ||||||||||
| 92 | # Description: # | ||||||||||
| 93 | # A signed int consists of numbers from 0-9 plus a sign. # | ||||||||||
| 94 | #------------------------------------------------------------------------------# | ||||||||||
| 95 | 0 | ▶ | sub is_signed_int { | ||||||||
|
Subroutine
is_signed_int: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 96 | # Assign the subroutine argument to the local variable. | ||||||||||
| 97 | 0 | ▶ | my $arg = (defined $_[0] ? $_[0] : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | # Set the Perl conform regex pattern. | ||||||||||
| 99 | 0 | my $re = qr/^([+-][1-9][0-9]*)$/; | |||||||||
| 100 | # Check the argument with the regex pattern. | ||||||||||
| 101 | 0 | ▶ | my $is_signed_int = (($arg =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | # Return 0 (false) or 1 (true). | ||||||||||
| 103 | 0 | return $is_signed_int; | |||||||||
| 104 | }; | ||||||||||
| 105 | |||||||||||
| 106 | #------------------------------------------------------------------------------# | ||||||||||
| 107 | # Subroutine is_hex # | ||||||||||
| 108 | # # | ||||||||||
| 109 | # Description: # | ||||||||||
| 110 | # The subroutine checks whether the specified argument is a valid hexadecimal # | ||||||||||
| 111 | # number. A hexadecimal number in the context of this method is a number # | ||||||||||
| 112 | # consisting of integers from 0-9, lower case characters from a-f or upper # | ||||||||||
| 113 | # case characters from A-F. Spaces before and after the number itself are not # | ||||||||||
| 114 | # allowed. The subroutine returns 1 (true) or 0 (false) based on the check. # | ||||||||||
| 115 | #------------------------------------------------------------------------------# | ||||||||||
| 116 | 0 | ▶ | sub is_hex { | ||||||||
|
Subroutine
is_hex: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 117 | # Assign the subroutine argument to the local variable. | ||||||||||
| 118 | 0 | ▶ | my $arg = (defined $_[0] ? $_[0] : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | # Define the Perl conform regex pattern. | ||||||||||
| 120 | 0 | my $re = qr/^([0-9a-fA-F]+)$/; | |||||||||
| 121 | # Check the argument with the regex pattern. | ||||||||||
| 122 | 0 | ▶ | my $is_hex = (($arg =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | # Return 0 (false) or 1 (true). | ||||||||||
| 124 | 0 | return $is_hex; | |||||||||
| 125 | }; | ||||||||||
| 126 | |||||||||||
| 127 | #------------------------------------------------------------------------------# | ||||||||||
| 128 | # Subroutine is_upper_hex # | ||||||||||
| 129 | # # | ||||||||||
| 130 | # Description: # | ||||||||||
| 131 | # The subroutine checks whether the specified argument is a valid hexadecimal # | ||||||||||
| 132 | # number. A hexadecimal number in the context of this method is a number # | ||||||||||
| 133 | # consisting of integers from 0-9 or upper case characters from A-F. Spaces # | ||||||||||
| 134 | # before and after the number itself are not allowed. The subroutine returns # | ||||||||||
| 135 | # 1 (true) or 0 (false) based on the check. # | ||||||||||
| 136 | #------------------------------------------------------------------------------# | ||||||||||
| 137 | 0 | ▶ | sub is_upper_hex { | ||||||||
|
Subroutine
is_upper_hex: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 138 | # Assign the subroutine argument to the local variable. | ||||||||||
| 139 | 0 | ▶ | my $arg = (defined $_[0] ? $_[0] : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 140 | # Define the Perl conform regex pattern. | ||||||||||
| 141 | 0 | my $re = qr/^([0-9A-F]+)$/; | |||||||||
| 142 | # Check the argument with the regex pattern. | ||||||||||
| 143 | 0 | ▶ | my $is_uc_hex = (($arg =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 144 | # Return 0 (false) or 1 (true). | ||||||||||
| 145 | 0 | return $is_uc_hex; | |||||||||
| 146 | }; | ||||||||||
| 147 | |||||||||||
| 148 | #------------------------------------------------------------------------------# | ||||||||||
| 149 | # Subroutine is_lower_hex # | ||||||||||
| 150 | # # | ||||||||||
| 151 | # Description: # | ||||||||||
| 152 | # The subroutine checks whether the specified argument is a valid hexadecimal # | ||||||||||
| 153 | # number. A hexadecimal number in the context of this method is a number # | ||||||||||
| 154 | # consisting of integers from 0-9 or lower case characters from a-f. Spaces # | ||||||||||
| 155 | # before and after the number itself are not allowed. The subroutine returns # | ||||||||||
| 156 | # 1 (true) or 0 (false) based on the check. # | ||||||||||
| 157 | #------------------------------------------------------------------------------# | ||||||||||
| 158 | 0 | ▶ | sub is_lower_hex { | ||||||||
|
Subroutine
is_lower_hex: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 159 | # Assign the subroutine argument to the local variable. | ||||||||||
| 160 | 0 | ▶ | my $arg = (defined $_[0] ? $_[0] : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 161 | # Define the Perl conform regex pattern. | ||||||||||
| 162 | 0 | my $re = qr/^([0-9a-f]+)$/; | |||||||||
| 163 | # Check the argument with the regex pattern. | ||||||||||
| 164 | 0 | ▶ | my $is_lc_hex = (($arg =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 165 | # Return 0 (false) or 1 (true). | ||||||||||
| 166 | 0 | return $is_lc_hex; | |||||||||
| 167 | }; | ||||||||||
| 168 | |||||||||||
| 169 | #------------------------------------------------------------------------------# | ||||||||||
| 170 | # Subroutine is_binary # | ||||||||||
| 171 | # # | ||||||||||
| 172 | # Description: # | ||||||||||
| 173 | # Binary numbers consist of the numbers 0 and 1. # | ||||||||||
| 174 | #------------------------------------------------------------------------------# | ||||||||||
| 175 | 0 | ▶ | sub is_binary { | ||||||||
|
Subroutine
is_binary: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 176 | # Assign the subroutine argument to the local variable. | ||||||||||
| 177 | 0 | ▶ | my $arg = (defined $_[0] ? $_[0] : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 178 | # Define the Perl conform regex pattern. | ||||||||||
| 179 | 0 | my $re = qr/^([01]+)$/; | |||||||||
| 180 | # Check the argument with the regex pattern. | ||||||||||
| 181 | 0 | ▶ | my $is_binary = (($arg =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 182 | # Return 0 (false) or 1 (true). | ||||||||||
| 183 | 0 | return $is_binary; | |||||||||
| 184 | }; | ||||||||||
| 185 | |||||||||||
| 186 | #------------------------------------------------------------------------------# | ||||||||||
| 187 | # Subroutine is_decimal # | ||||||||||
| 188 | # # | ||||||||||
| 189 | # The decimal numeral system is the standard system for denoting e.g. integer # | ||||||||||
| 190 | # numbers. In the context of this method numbers from 0 to 9 are allowed. A # | ||||||||||
| 191 | # leading 0 is also allowed. In the base 10 system, which the decimal system # | ||||||||||
| 192 | # is each digit is multiplied by a power of 10 according to its place and than # | ||||||||||
| 193 | # summed up. # | ||||||||||
| 194 | #------------------------------------------------------------------------------# | ||||||||||
| 195 | 0 | ▶ | sub is_decimal { | ||||||||
|
Subroutine
is_decimal: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 196 | # Assign the subroutine argument to the local variable. | ||||||||||
| 197 | 0 | ▶ | my $arg = (defined $_[0] ? $_[0] : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 198 | # Define the Perl conform regex pattern. | ||||||||||
| 199 | 0 | my $re = qr/^([0-9]+)$/; | |||||||||
| 200 | # Check the argument with the regex pattern. | ||||||||||
| 201 | 0 | ▶ | my $is_decimal = (($arg =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 202 | # Return 0 (false) or 1 (true). | ||||||||||
| 203 | 0 | return $is_decimal; | |||||||||
| 204 | }; | ||||||||||
| 205 | |||||||||||
| 206 | #------------------------------------------------------------------------------# | ||||||||||
| 207 | # Subroutine is_roman # | ||||||||||
| 208 | # # | ||||||||||
| 209 | # Description: # | ||||||||||
| 210 | # Roman numbers consist of the letters I, V, X, L, C, D, and M. # | ||||||||||
| 211 | #------------------------------------------------------------------------------# | ||||||||||
| 212 | 0 | ▶ | sub is_roman { | ||||||||
|
Subroutine
is_roman: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 213 | # Assign the subroutine argument to the local variable. | ||||||||||
| 214 | 0 | ▶ | my $arg = (defined $_[0] ? $_[0] : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 215 | # Define the Perl conform regex pattern. | ||||||||||
| 216 | 0 | my $re = qr/^([IVXLCDM]+)$/; | |||||||||
| 217 | # Check the argument with the regex pattern. | ||||||||||
| 218 | 0 | ▶ | my $is_binary = (($arg =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 219 | # Return 0 (false) or 1 (true). | ||||||||||
| 220 | 0 | return $is_binary; | |||||||||
| 221 | }; | ||||||||||
| 222 | |||||||||||
| 223 | #------------------------------------------------------------------------------# | ||||||||||
| 224 | # Subroutine is_octal # | ||||||||||
| 225 | # # | ||||||||||
| 226 | # Description: # | ||||||||||
| 227 | # Octal numbers consist of numbers from 0 to 7. # | ||||||||||
| 228 | #------------------------------------------------------------------------------# | ||||||||||
| 229 | 0 | ▶ | sub is_octal { | ||||||||
|
Subroutine
is_octal: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 230 | # Assign the subroutine argument to the local variable. | ||||||||||
| 231 | 0 | ▶ | my $arg = (defined $_[0] ? $_[0] : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 232 | # Define the Perl conform regex pattern. | ||||||||||
| 233 | 0 | my $re = qr/^([0-7]+)$/; | |||||||||
| 234 | # Check the argument with the regex pattern. | ||||||||||
| 235 | 0 | ▶ | my $is_octal = (($arg =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 236 | # Return 0 (false) or 1 (true). | ||||||||||
| 237 | 0 | return $is_octal; | |||||||||
| 238 | }; | ||||||||||
| 239 | |||||||||||
| 240 | #------------------------------------------------------------------------------# | ||||||||||
| 241 | # Subroutine is_unsigned_sepdec # | ||||||||||
| 242 | # # | ||||||||||
| 243 | # Description: # | ||||||||||
| 244 | # Comma or other separator instead of decimal point. # | ||||||||||
| 245 | #------------------------------------------------------------------------------# | ||||||||||
| 246 | 0 | ▶ | sub is_unsigned_sepdec { | ||||||||
|
Subroutine
is_unsigned_sepdec: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 247 | # Get the subroutine arguments. | ||||||||||
| 248 | 0 | my ($str, $sep) = @_; | |||||||||
| 249 | # Assign the subroutine arguments to the local variablea. | ||||||||||
| 250 | 0 | ▶ | $str = (defined $str ? $str : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 251 | 0 | ▶ | $sep = (defined $sep ? $sep : '.'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 252 | # Define the Perl conform regex pattern. | ||||||||||
| 253 | 0 | my $re = qr/^(([0-9]{1}|[1-9]{1}[0-9]+)[,][0-9]+)$/; | |||||||||
| 254 | # Check the argument with the regex pattern. | ||||||||||
| 255 | 0 | ▶ | my $is_float = (($str =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 256 | # Return 0 (false) or 1 (true). | ||||||||||
| 257 | 0 | return $is_float; | |||||||||
| 258 | }; | ||||||||||
| 259 | |||||||||||
| 260 | #------------------------------------------------------------------------------# | ||||||||||
| 261 | # Subroutine is_signed_sepdec # | ||||||||||
| 262 | # # | ||||||||||
| 263 | # Description: # | ||||||||||
| 264 | # Comma or other separator instead of decimal point. # | ||||||||||
| 265 | #------------------------------------------------------------------------------# | ||||||||||
| 266 | 0 | ▶ | sub is_signed_sepdec { | ||||||||
|
Subroutine
is_signed_sepdec: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 267 | # Get the subroutine arguments. | ||||||||||
| 268 | 0 | my ($str, $sep) = @_; | |||||||||
| 269 | # Assign the subroutine arguments to the local variablea. | ||||||||||
| 270 | 0 | ▶ | $str = (defined $str ? $str : ''); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 271 | 0 | ▶ | $sep = (defined $sep ? $sep : '.'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 272 | # Define the Perl conform regex pattern. | ||||||||||
| 273 | 0 | my $re = qr/^([+-]([0-9]{1}|[1-9]{1}[0-9]+)[$sep][0-9]+)$/; | |||||||||
| 274 | # Check the argument with the regex pattern. | ||||||||||
| 275 | 0 | ▶ | my $is_float = (($str =~ $re) ? 1 : 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 276 | # Return 0 (false) or 1 (true). | ||||||||||
| 277 | 0 | return $is_float; | |||||||||
| 278 | }; | ||||||||||
| 279 | |||||||||||
| 280 | 1 | 1; | |||||||||
| 281 | |||||||||||
| 282 | __END__ | ||||||||||