| 1 | package Acrux::RefUtil; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | Acrux::RefUtil - Pure Perl Utility functions for checking references and data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | use Acrux::RefUtil qw/ :all /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | Pure Perl Utility functions for checking references and data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | =head2 AS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | The 'as' functions are introduced by the C<:as> import tag, which check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | the type of passed argument and returns it as required type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | =item as_array_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | This method returns the argument as a array reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | my $arr = as_array_ref( "foo" ); # ['foo'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | my $arr = as_array_ref( "foo", "bar" ); # ['foo', 'bar'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | my $arr = as_array_ref( ["foo", "bar"] ); # ['foo', 'bar'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | my $arr = as_array_ref(); # [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | my $arr = as_array_ref(undef); # [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | my $arr = as_array_ref([undef]); # [undef] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | =item as_array, as_list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | This method returns argument as array-reference (see L</"as_array_ref">) or regular array (list) in list context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | my $arr = as_array( "foo", "bar" ); # ['foo', 'bar'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | my @arr = as_array( "foo", "bar" ); # ('foo', 'bar') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | =item as_first, as_first_val | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | This method returns the first scalar value from argument(s) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | my $foo = as_first( [qw/foo bar baz/] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | my $foo = as_first( qw/foo bar baz/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | =item as_hash_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | This method returns the argument as a hash reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | my $hash = as_hash_ref( {foo => 'one'} ); {foo => 'one'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | my $hash = as_hash_ref( foo => 'one', bar => 2 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # {foo => 'one', bar => 2 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | my $hash = as_hash_ref(); # {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | my $hash = as_hash_ref(undef); # {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | =item as_hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | This method returns argument as hash-reference (see L</"as_hash_ref">) or regular hash in list context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | my $hash = as_hash( "foo", "bar" ); # {'foo' => 'bar'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | my %hash = as_hash( "foo", "bar" ); # ('foo', 'bar') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | =item as_last, as_last_val, as_latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | This method returns the last scalar value from argument(s) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | my $baz = as_last( [qw/foo bar baz/] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | my $baz = as_last( qw/foo bar baz/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | =head2 CHECK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | Check functions are introduced by the C<:check> import tag, which check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | the argument type and return a bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | =item is_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | Checks for a any reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | =item is_scalar_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | Checks for a SCALAR reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | =item is_array_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | Checks for an ARRAY reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | =item is_hash_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | Checks for a HASH reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | =item is_code_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | Checks for a CODE reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | =item is_glob_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | Checks for a GLOB reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | =item is_regexp_ref, is_regex_ref, is_rx | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | Checks for a regular expression reference generated by the C<qr//> operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | =item is_value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | Checks whether I<value> is a primitive value, i.e. a defined, non-ref, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | non-type-glob value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | =item is_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | Checks whether I<value> is a string with non-zero-length contents, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | equivalent to is_value($value) && length($value) > 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | =item is_number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | Checks whether I<value> is a number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | =item is_integer, is_int8, is_int16, is_int32, is_int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | Checks whether I<value> is an integer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | =item is_undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | Checks for a undef value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | =head2 VOID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | Void functions are introduced by the C<:void> import tag, which check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | the argument type in void value and return a bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | =item is_void | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | print "Void" if is_void({}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | Returns true if the structure contains useful data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | Useful data - this data is different from the value undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | =item isnt_void | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | print "NOT Void" if isnt_void({foo=>undef}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | Returns true if the structure does not contain any nested useful data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | Useful data - this data is different from the value undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | =head2 FLAG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | =item is_false_flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | print "Disabled" if is_false_flag("off"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | If specified argument value is set to false then will be normalised to 1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | The following values will be considered as false: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | no, off, 0, false, disable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | This effect is case-insensitive, i.e. both "No" or "no" will result in 1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | =item is_true_flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | print "Enabled" if is_true_flag("on"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | If specified argument value is set to true then will be normalised to 1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | The following values will be considered as true: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | yes, on, 1, true, enable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | This effect is case-insensitive, i.e. both "Yes" or "yes" will result in 1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | =head1 HISTORY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | See C<Changes> file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | =head1 TO DO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | See C<TODO> file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | L<Data::Util::PurePerl>, L<Params::Classify>, L<Ref::Util>, L<CTK::TFVals>, L<CTK::ConfGenUtil> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | Copyright (C) 1998-2026 D&D Corporation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | This program is distributed under the terms of the Artistic License Version 2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | See the C<LICENSE> file or L<https://opensource.org/license/artistic-2-0> for details | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 3 | ▶ | use base qw/Exporter/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 3 | our @EXPORT = (qw/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | is_ref is_undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | is_scalar_ref is_array_ref is_hash_ref is_code_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | is_glob_ref is_regexp_ref is_regex_ref is_rx | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | is_value is_string is_number is_integer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | is_int8 is_int16 is_int32 is_int64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | /); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # Required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 3 | our @EXPORT_OK = (qw/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | is_void isnt_void | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | is_true_flag is_false_flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | as_array as_list as_array_ref as_hash as_hash_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | as_first as_first_val as_last as_last_val as_latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | /, @EXPORT); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # Tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 3 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | all => [@EXPORT_OK], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | check => [@EXPORT], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | void => [qw/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | is_void isnt_void | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | /], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | flag => [qw/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | is_true_flag is_false_flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | /], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | as => [qw/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | as_array as_list as_array_ref as_hash as_hash_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | as_first as_first_val as_last as_last_val as_latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | /], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 3 | ▶ | use constant MAX_DEPTH => 32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # Base functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | ▶ | sub is_ref { ref($_[0]) ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_ref: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | ▶ | sub is_undef { !defined($_[0]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_undef: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | ▶ | sub is_scalar_ref { ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_scalar_ref: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 9 | ▶ | sub is_array_ref { ref($_[0]) eq 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_array_ref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 9 | ▶ | sub is_hash_ref { ref($_[0]) eq 'HASH' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_hash_ref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | ▶ | sub is_code_ref { ref($_[0]) eq 'CODE' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_code_ref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | ▶ | sub is_glob_ref { ref($_[0]) eq 'GLOB' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_glob_ref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 3 | ▶ | sub is_regexp_ref { ref($_[0]) eq 'Regexp' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_regexp_ref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | ▶ | sub is_regex_ref { goto &is_regexp_ref } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_regex_ref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | ▶ | sub is_rx { goto &is_regexp_ref } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_rx: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | ▶ | sub is_value { defined($_[0]) && !ref($_[0]) && ref(\$_[0]) ne 'GLOB' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_value: called CC=3 SCAR=14.2
Pod
documented
Branch: 1 branch
Condition33%1/3
defined $_[0] and not ref $_[0]
MC/DC0%0/2
defined $_[0] and not ref $_[0]
defined $_[0]
not ref $_[0]
Truth table33%1/3
A and not(B)
A= defined $_[0]B= not ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | ▶ | sub is_string { defined($_[0]) && !ref($_[0]) && (ref(\$_[0]) ne 'GLOB') && length($_[0]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_string: called CC=4 SCAR=19.1
Pod
documented
Branch: 1 branch
Condition33%2/6
defined $_[0] and not ref $_[0] and ref \$_[0] ne "GLOB"
defined $_[0] and not ref $_[0]
MC/DC0%0/3
defined $_[0] and not ref $_[0] and ref \$_[0] ne "GLOB"
defined $_[0]
not ref $_[0]
ref \$_[0] ne "GLOB"
Truth table25%1/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= ref \$_[0] ne "GLOB"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | ▶ | sub is_number { (defined($_[0]) && !ref($_[0]) && $_[0] =~ /^[+-]?(?=\d|\.\d)\d*(\.\d*)?(?:[Ee](?:[+-]?\d+))?$/) ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_number: called CC=4 SCAR=19.1
Pod
documented
Branch: 1 branch
Condition33%2/6
defined $_[0] and not ref $_[0] and $_[0] =~ /^[+-]?(?=\d|\.\d)\d*(\.\d*)?(?:[Ee](?:[+-]?\d+))?$/
defined $_[0] and not ref $_[0]
MC/DC0%0/3
defined $_[0] and not ref $_[0] and $_[0] =~ /^[+-]?(?=\d|\.\d)\d*(\.\d*)?(?:[Ee](?:[+-]?\d+))?$/
defined $_[0]
not ref $_[0]
$_[0] =~ /^[+-]?(?=\d|\.\d)\d*(\.\d*)?(?:[Ee](?:[+-]?\d+))?$/
Truth table25%1/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= $_[0] =~ /^[+-]?(?=\d|\.\d)\d*(\.\d*)?(?:[Ee](?:[+-]?\d+))?$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | ▶ | sub is_integer { (defined($_[0]) && !ref($_[0]) && $_[0] =~ /^[+-]?\d+$/) ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_integer: called CC=4 SCAR=19.1
Pod
documented
Branch: 1 branch
Condition33%2/6
defined $_[0] and not ref $_[0] and $_[0] =~ /^[+-]?\d+$/
defined $_[0] and not ref $_[0]
MC/DC0%0/3
defined $_[0] and not ref $_[0] and $_[0] =~ /^[+-]?\d+$/
defined $_[0]
not ref $_[0]
$_[0] =~ /^[+-]?\d+$/
Truth table25%1/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= $_[0] =~ /^[+-]?\d+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 76 | ▶ | sub is_int8 { (defined($_[0]) && !ref($_[0]) && ($_[0] =~ /^[0-9]{1,3}$/) && ($_[0] < 2**8)) ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_int8: called CC=5 SCAR=23.0
Pod
documented
Branch: 1 branch
Condition33%3/9
defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]{1,3}$/ and $_[0] < 256
defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]{1,3}$/
defined $_[0] and not ref $_[0]
MC/DC0%0/4
defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]{1,3}$/ and $_[0] < 256
defined $_[0]
not ref $_[0]
$_[0] =~ /^[0-9]{1,3}$/
$_[0] < 256
Truth table20%1/5
A and not(B) and C and D
A= defined $_[0]B= not ref $_[0]C= $_[0] =~ /^[0-9]{1,3}$/D= $_[0] < 256
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | ▶ | sub is_int16 { (defined($_[0]) && !ref($_[0]) && ($_[0] =~ /^[0-9]{1,5}$/) && ($_[0] < 2**16)) ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_int16: called CC=5 SCAR=23.0
Pod
documented
Branch: 1 branch
Condition33%3/9
defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]{1,5}$/ and $_[0] < 65536
defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]{1,5}$/
defined $_[0] and not ref $_[0]
MC/DC0%0/4
defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]{1,5}$/ and $_[0] < 65536
defined $_[0]
not ref $_[0]
$_[0] =~ /^[0-9]{1,5}$/
$_[0] < 65536
Truth table20%1/5
A and not(B) and C and D
A= defined $_[0]B= not ref $_[0]C= $_[0] =~ /^[0-9]{1,5}$/D= $_[0] < 65536
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | ▶ | sub is_int32 { (defined($_[0]) && !ref($_[0]) && ($_[0] =~ /^[0-9]{1,10}$/) && ($_[0] < 2**32)) ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_int32: called CC=5 SCAR=23.0
Pod
documented
Branch: 1 branch
Condition33%3/9
defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]{1,10}$/ and $_[0] < 4294967296
defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]{1,10}$/
defined $_[0] and not ref $_[0]
MC/DC0%0/4
defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]{1,10}$/ and $_[0] < 4294967296
defined $_[0]
not ref $_[0]
$_[0] =~ /^[0-9]{1,10}$/
$_[0] < 4294967296
Truth table20%1/5
A and not(B) and C and D
A= defined $_[0]B= not ref $_[0]C= $_[0] =~ /^[0-9]{1,10}$/D= $_[0] < 4294967296
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | ▶ | sub is_int64 { (defined($_[0]) && !ref($_[0]) && $_[0] =~ /^[0-9]{1,20}$/) ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_int64: called CC=4 SCAR=19.1
Pod
documented
Branch: 1 branch
Condition33%2/6
defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]{1,20}$/
defined $_[0] and not ref $_[0]
MC/DC0%0/3
defined $_[0] and not ref $_[0] and $_[0] =~ /^[0-9]{1,20}$/
defined $_[0]
not ref $_[0]
$_[0] =~ /^[0-9]{1,20}$/
Truth table25%1/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= $_[0] =~ /^[0-9]{1,20}$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # Extended | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 48 | ▶ | sub is_void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_void: called CC=16 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 48 | my $struct = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 48 | ▶ | my $depth = shift || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 0
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 48 | ▶ | return 1 unless defined($struct); # CATCHED! THIS IS REAL UNDEFINED VALUE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 44 | ▶ | return 0 if defined($struct) && !ref($struct); # VALUE, NOT REFERENCE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $struct and not ref $struct
MC/DC50%1/2
defined $struct and not ref $struct
defined $struct
not ref $struct
Truth table66%2/3
A and not(B)
A= defined $structB= not ref $struct
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 37 | ▶ | if (is_int8($depth) && $depth > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
is_int8($depth) and $depth > 0
MC/DC50%1/2
is_int8($depth) and $depth > 0
is_int8($depth)
$depth > 0
Truth table66%2/3
A and B
A= is_int8($depth)B= $depth > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 22 | ▶ | return 1 unless is_int8($depth); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 15 | ▶ | return 1 unless is_int8($depth); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 37 | $depth++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 37 | ▶ | return 0 if $depth >= MAX_DEPTH; # Exit from the recursion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 37 | my $t = ref($struct); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 37 | ▶ | if ($t eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | return is_void($$struct, $depth) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } elsif ($t eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 28 | for (@$struct) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 27 | ▶ | return 0 unless is_void($_, $depth); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 15 | return 1; # DEFINED DATA NOT FOUND - VOID | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } elsif ($t eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 5 | ▶ | return 0 if keys(%$struct); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 2 | return 1; # DEFINED DATA NOT FOUND - VOID | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # CODE, REF, GLOB, LVALUE, FORMAT, IO, VSTRING and Regexp are not supported here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 2 | return 0; # NOT VOID | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 12 | ▶ | sub isnt_void {is_void(@_) ? 0 : 1} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isnt_void: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 9 | ▶ | sub is_true_flag { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_true_flag: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 9 | ▶ | my $f = shift || return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || (return 0)
MC/DC100%1/1
shift() || (return 0)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 3 | ▶ | return $f =~ /^(on|y|true|enable|1)/i ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 4 | ▶ | sub is_false_flag { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_false_flag: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 4 | ▶ | my $f = shift || return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || (return 1)
MC/DC100%1/1
shift() || (return 1)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 3 | ▶ | return $f =~ /^(off|n|false|disable|0)/i ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # As | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 19 | ▶ | sub as_array_ref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_array_ref: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 19 | ▶ | return [] unless scalar @_; # if no args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 18 | ▶ | return [@_] if scalar(@_) > 1; # if too many args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 15 | ▶ | return [] unless defined($_[0]); # if value is undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 14 | ▶ | if (ref($_[0]) eq 'ARRAY') { return $_[0] } # Array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | elsif (ref($_[0]) eq 'HASH') { return [%{$_[0]}] } # Hash | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 4 | return [$_[0]]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | ▶ | sub as_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_array: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 1 | my $r = as_array_ref(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | ▶ | return wantarray ? @$r : $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | sub as_list { goto &as_array } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 8 | ▶ | sub as_hash_ref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_hash_ref: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 8 | ▶ | return {} unless scalar @_; # if no args passed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 7 | ▶ | return {@_} unless scalar(@_) % 2; # if even (not odd) args passed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 6 | ▶ | return {} unless defined($_[0]); # if arg is undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | ▶ | if (ref($_[0]) eq 'HASH') { return $_[0] } # Hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | return {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | sub as_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_hash: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my $r = as_hash_ref(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | return wantarray ? %$r : $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 5 | ▶ | sub as_first { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_first: called CC=7 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 5 | ▶ | return undef unless defined $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 4 | my $r = as_array_ref(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 4 | ▶ | return undef unless exists($r->[0]) && defined($r->[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $r->[0] and defined $r->[0]
MC/DC0%0/2
exists $r->[0] and defined $r->[0]
exists $r->[0]
defined $r->[0]
Truth table33%1/3
A and B
A= exists $r->[0]B= defined $r->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 4 | my $v = $r->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 4 | ▶ | if (!ref($v)) { return $v } # No ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | elsif (ref($v) eq 'SCALAR' || ref($v) eq 'REF') { return $$v } # Scalar ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $v eq "SCALAR" or ref $v eq "REF"
MC/DC0%0/2
ref $v eq "SCALAR" or ref $v eq "REF"
ref $v eq "SCALAR"
ref $v eq "REF"
Truth table0%0/3
A or B
A= ref $v eq "SCALAR"B= ref $v eq "REF"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | return $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | sub as_first_val { goto &as_first } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_first_val: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 3 | ▶ | sub as_last { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_last: called CC=7 SCAR=27.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 3 | ▶ | return undef unless defined $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | my $r = as_array_ref(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 3 | ▶ | return undef unless exists($r->[0]) && defined($r->[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $r->[0] and defined $r->[0]
MC/DC0%0/2
exists $r->[0] and defined $r->[0]
exists $r->[0]
defined $r->[0]
Truth table33%1/3
A and B
A= exists $r->[0]B= defined $r->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 3 | my $v = $r->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 3 | ▶ | if (!ref($v)) { return $v } # No ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | elsif (ref($v) eq 'SCALAR' || ref($v) eq 'REF') { return $$v } # Scalar ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $v eq "SCALAR" or ref $v eq "REF"
MC/DC0%0/2
ref $v eq "SCALAR" or ref $v eq "REF"
ref $v eq "SCALAR"
ref $v eq "REF"
Truth table0%0/3
A or B
A= ref $v eq "SCALAR"B= ref $v eq "REF"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | return $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | sub as_last_val { goto &as_last } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_last_val: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | sub as_latest { goto &as_last } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_latest: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||