| 1 | package Test2::Tools::Type::Extras; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Scalar::Util qw(blessed reftype); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | our $VERSION = '1.0.1'; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | our @EXPORT = ('regex_supported'); | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | my @targets = map { $_.'::' } @_; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | while(my($k, $v) = each(%{__PACKAGE__.'::'})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | push @EXPORT, $k if( | ||||||||||||||||||||||||||||||||||||||||||
| 22 | $k =~ /^is_/ && | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ref($v) ne 'SCALAR' && | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 23 | ▶ | defined(&{$v}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$k =~ /^is_/ and ref $v ne "SCALAR" and defined &{$v;}
$k =~ /^is_/ and ref $v ne "SCALAR"
MC/DC33%1/3
$k =~ /^is_/ and ref $v ne "SCALAR" and defined &{$v;}
$k =~ /^is_/
ref $v ne "SCALAR"
defined &{$v;}
Truth table50%2/4
A and B and C
A= $k =~ /^is_/B= ref $v ne "SCALAR"C= defined &{$v;}
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | *_checker = \&Test2::Tools::Type::_checker; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 11 | ▶ | sub is_positive { _checker(sub { $_[0] > 0 }, @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
is_positive: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 9 | ▶ | sub is_negative { _checker(sub { $_[0] < 0 }, @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
is_negative: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | ▶ | sub is_zero { _checker(sub { $_[0] == 0; }, @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
is_zero: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # There are tests that is_ref, is_object and is_hashref don't screw with | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # the argument's type. That covers the implementations that use | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # ref/blessed/reftype. If you add more checks with different innards, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # add tests for that as well as that they return what you expect. | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | ▶ | sub is_ref { _checker(sub { ref($_[0]); }, @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
is_ref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | ▶ | sub is_object { _checker(sub { blessed($_[0]); }, @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
is_object: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 7 | ▶ | sub is_hashref { _checker(sub { reftype($_[0]) && reftype($_[0]) eq 'HASH' }, @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Subroutine
is_hashref: called CC=1 SCAR=0.0
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | sub is_arrayref { _checker(sub { reftype($_[0]) && reftype($_[0]) eq 'ARRAY' }, @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Subroutine
is_arrayref: called CC=1 SCAR=0.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | sub is_scalarref { _checker(sub { reftype($_[0]) && reftype($_[0]) eq 'SCALAR' }, @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Subroutine
is_scalarref: called CC=1 SCAR=0.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | sub is_coderef { _checker(sub { reftype($_[0]) && reftype($_[0]) eq 'CODE' }, @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Subroutine
is_coderef: called CC=1 SCAR=0.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | sub is_globref { _checker(sub { reftype($_[0]) && reftype($_[0]) eq 'GLOB' }, @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Subroutine
is_globref: called CC=1 SCAR=0.0
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | sub is_refref { _checker(sub { reftype($_[0]) && reftype($_[0]) eq 'REF' }, @_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Subroutine
is_refref: called CC=1 SCAR=0.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | ▶ | sub is_regex { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_regex: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | croak("You need perl 5.12 or higher to use is_regex") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | unless(regex_supported()); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | _checker(sub { reftype($_[0]) && reftype($_[0]) eq 'REGEXP' }, @_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | ▶ | sub regex_supported { $] >= 5.012 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
regex_supported: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | Test2::Tools::Type::Extras - Extra tools for checking data types | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | use Test2::V0; | ||||||||||||||||||||||||||||||||||||||||||
| 65 | use Test2::Tools::Type qw(:extras); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | This provides extra testing functions for Test2::Tools::Type. They | ||||||||||||||||||||||||||||||||||||||||||
| 70 | can all be used stand-alone or with Test2::Tools::Type's C<type> method. | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | This module is not intended for you to use it directly. | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | If you find any bugs please report them on Github, preferably with a test case. | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | I welcome feedback about my code, especially constructive criticism. | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | =head1 AUTHOR, COPYRIGHT and LICENCE | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | Copyright 2024 David Cantrell E<lt>F<david@cantrell.org.uk>E<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | This software is free-as-in-speech software, and may be used, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | distributed, and modified under the terms of either the GNU | ||||||||||||||||||||||||||||||||||||||||||
| 88 | General Public Licence version 2 or the Artistic Licence. It's | ||||||||||||||||||||||||||||||||||||||||||
| 89 | up to you which one you use. The full text of the licences can | ||||||||||||||||||||||||||||||||||||||||||
| 90 | be found in the files GPL2.txt and ARTISTIC.txt, respectively. | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | =head1 CONSPIRACY | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | This module is also free-as-in-mason software. | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||||||||||||||||