Test::Type(3pm)
β¨ Test::Type β¨
okay bestie, so this is Test::Type β a Perl module (you know, the .pm situation, shipped as a 3pm manpage) that hands you a lil squad of functions to validate data types in test files. that's it, that's the vibe. no cap. π«Ά
πΈ VERSION πΈ
Version 1.3.0 β we're living in the 1.3.0 era, iconic behavior. π
π SYNOPSIS π
here's how you actually use it, keep up bestie:
use Test::Type;
# Test strings.
ok_string( $variable );
ok_string(
$variable,
name => 'My variable',
);
# Test arrayrefs.
ok_arrayref( $variable );
ok_arrayref(
$variable,
name => 'My variable',
);
# Test hashrefs.
ok_hashref( $variable );
ok_hashref(
$variable,
name => 'Test variable',
);
# Test coderefs.
ok_coderef( $variable );
ok_coderef(
$variable,
name => 'Test variable',
);
# Test numbers.
ok_number( $variable );
ok_number(
$variable,
name => 'Test variable',
);
# Test instances.
ok_instance(
$variable,
class => $class,
);
ok_instance(
$variable,
name => 'Test variable',
class => $class,
);
# Test regular expressions.
ok_regex( $variable );
ok_regex(
$variable,
name => 'Test regular expression',
);
π¦ FUNCTIONS π¦
seven little icons, each one checking a different type. let's go one by one, no skipping, we don't do that here. π
π ok_string() π
checks if the thing you passed in is a string. fr fr.
ok_string(
$variable,
);
ok_string(
$variable,
name => 'My variable',
);
ok_string(
$variable,
name => 'My variable',
allow_empty => 1,
);
Parameters:
nameβ optional, it's the name of the variable you're testing. just a label so your test output doesn't look like a mystery. πallow_emptyβ boolean, default 1. this one decides whether the string is allowed to be empty or not.
π ok_arrayref() π
checks if your variable is an arrayref that can actually be dereferenced into an array. yes, actually dereferenceable, we're not doing vibes-only checks here.
ok_arrayref( $variable );
ok_arrayref(
$variable,
name => 'My variable',
);
ok_arrayref(
$variable,
allow_empty => 1,
no_blessing => 0,
);
# Check if the variable is an arrayref of hashrefs.
ok_arrayref(
$variable,
allow_empty => 1,
no_blessing => 0,
element_validate_type =>
sub
{
return Data::Validate::Type::is_hashref( $_[0] );
},
);
Parameters:
nameβ optional, the name of the variable being tested.allow_emptyβ boolean, default 1. allow the array to be empty or not.no_blessingβ boolean, default 0. require that the variable is not blessed. (yes, blessed objects need not apply π )element_validate_typeβ none by default. set it to a coderef and it'll validate the elements inside the array. that coderef gets the element to validate as its first parameter, and it must return a boolean saying whether that element was valid or not. simple as. β¨
π ok_hashref() π
checks if your variable is a hashref that can be dereferenced into a hash. dereferenceable or it didn't happen.
ok_hashref( $variable );
ok_hashref(
$variable,
name => 'Test variable',
);
ok_hashref(
$variable,
allow_empty => 1,
no_blessing => 0,
);
Parameters:
nameβ optional, the name of the variable being tested.allow_emptyβ boolean, default 1. allow the array to be empty or not.no_blessingβ boolean, default 0. require that the variable is not blessed.
π ok_coderef() π
checks if your variable is a coderef that can be dereferenced into a block of code. code that goes brrr, basically. π
ok_coderef( $variable );
ok_coderef(
$variable,
name => 'Test variable',
);
Parameters:
nameβ optional, the name of the variable being tested.
β ok_number() β
checks if your variable is a number. math girlies rise. π₯
ok_number( $variable );
ok_number(
$variable,
name => 'Test variable',
);
ok_number(
$variable,
positive => 1,
);
ok_number(
$variable,
strictly_positive => 1,
);
Parameters:
nameβ optional, the name of the variable being tested.strictly_positiveβ boolean, default 0. set it to1to check for a strictly positive number.positiveβ boolean, default 0. set it to1to check for a positive number.
π ok_instance() π
checks if your variable is an instance of the given class. main character energy check.
note: this handles inheritance properly, so it will succeed if the variable is an instance of a subclass of the class you gave it. family tree respected, periodt. π³
ok_instance(
$variable,
class => $class,
);
ok_instance(
$variable,
name => 'Test variable',
class => $class,
);
Parameters:
nameβ optional, the name of the variable being tested.classβ required, bestie, you must give this one. it's the name of the class to check the variable against.
π§ ok_regex() π§
checks if your variable is a regular expression. regex girlies, this one's for you. π
ok_regex( $variable );
π BUGS π
found a bug or got a feature request? please report it to bug-test-dist-versionsync at rt.cpan.org, or slide through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=test-type>. i will be notified, and then you'll automatically be notified of progress on your bug as i make changes. we love a feedback loop. π
π«Ά SUPPORT π«Ά
you can find the docs for this module with the perldoc command:
perldoc Test::Type
and you can also go looking for info at these spots:
- GitHub (report bugs there) β <https://github.com/guillaumeaubert/Test-Type/issues>
- AnnoCPAN: Annotated CPAN documentation β <http://annocpan.org/dist/test-type>
- CPAN Ratings β <http://cpanratings.perl.org/d/test-type>
- Search CPAN β <https://metacpan.org/release/Test-Type>
πΈ AUTHOR πΈ
Guillaume Aubert <https://metacpan.org/author/AUBERTG>, <aubertg at cpan.org>. the icon who made this. π
π COPYRIGHT & LICENSE π
Copyright 2012-2017 Guillaume Aubert.
This code is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE file for more details.
lowkey important: no warranty, bestie. it's giving "use at your own risk" but make it legal. π
and that's the whole page!! this was Test::Type, from perl v5.42.0, dated 2025-07-25 β go validate some data types, you absolute legend. slay, ate, left no crumbs. π¦β¨π
π¦ where this page comes from
- fedora 43: perl-Test-Type 1.3.0-27.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms