Test::Deep::Type(3pm)
π Test::Deep::Type β the perl manual page, but make it a group chat π
okay bestie, so this is Test::Deep::Type, a User Contributed Perl Documentation page (that's the manual name right there, mwah π
). It's a Test::Deep plugin, and it's about to be your new favorite thing, no cap.
β¨ NAME β¨
Test::Deep::Type β a Test::Deep plugin for validating type constraints. it's giving "your data better be the right shape or we're gonna have a Conversation" π«Ά
πΈ VERSION πΈ
version 0.008 β she's on 0.008, iconic behavior honestly
π SYNOPSIS π
look at this, look at her go:
use Test::More;
use Test::Deep;
use Test::Deep::Type;
use MooseX::Types::Moose 'Str';
cmp_deeply(
{
message => 'ack I am slain',
counter => 123,
},
{
message => is_type(Str),
counter => is_type(sub { die "not an integer" unless int($_[0]) eq $_[0] }),
},
'message is a plain string, counter is a number',
);
like?? message is a plain string, counter is a number, and the test literally says so. obsessed. π
π¦ DESCRIPTION π¦
so. this is a Test::Deep plugin that hands you the sub is_type, which is how you say "the data being tested MUST validate against the passed type" β emphasis on must, bestie, this is a vibe check with teeth.
important: this is an actual type object, not a string name. like, something you got from MooseX::Types, or a plain old coderef that returns a bool (the kind of thing you'd use in a Moo type constraint). actual object. not a string. i said what i said. β¨
π FUNCTIONS π
π is_type
Exported by default π β you're supposed to use her inside a Test::Deep comparison function like cmp_deeply.
And because this module is trying to be the solution for many popular type systems (she's a people pleaser, we love her for it), she tries to use the type in multiple ways:
MooseX::Types/Moose::Meta::TypeConstraint-style types
If the validate method exists, it gets invoked on the type object with the data as its parameter. and that should return undef on success, and the error message on failure. so basically: no news is good news, and bad news is a whole string. π«Ά
coderef/Moo-style types
If the type appears to be or act like a coderef β and by that i mean either a coderef, blessed or unblessed, or it possesses a coderef overload β then the type gets invoked as a sub, with the data as its parameter.
Its return value is treated as a boolean π₯. And if it also dies with a message describing the failure, that message gets used in the failure diagnostics. so when it goes wrong, you find out exactly how. slay.
Type::Tiny types fall into this category, and are fully supported. π―
π CAVEATS π
Regular strings describing a type under a particular system (e.g. Moose, Params::Validate) are not currently supported. so don't come in here with a string name and expect the plugin to read your mind. she can't. not yet. π
π SEE ALSO π
Test::DeepTest::TypeConstraintsTest::TypeTest::Deep::MatcherMooseX::TypesMoose::Meta::TypeConstraintMooType::Tiny
a whole friend group. iykyk π
π SUPPORT π
Bugs may be submitted through the RT bug tracker β that's <https://rt.cpan.org/Public/Dist/Display.html?Name=Test-Deep-Type> β or, if email is more your era, bug-Test-Deep-Type@rt.cpan.org <mailto:bug-Test-Deep-Type@rt.cpan.org>. tell them everything. π©
There's also a mailing list available for users of this distribution, at <http://lists.perl.org/list/perl-qa.html>. join the list, bestie.
There's also an irc channel available for users of this distribution, at #perl on irc.perl.org <irc://irc.perl.org/#perl-qa>. come hang out. πΈ
And the author is also usually active on irc, as 'ether' at irc.perl.org. so like, she's there. say hi. π
π AUTHOR π
Karen Etheridge <ether@cpan.org> β mother is mothering
π§ CONTRIBUTOR π§
Graham Knop <haarg@haarg.org> β thank you for your service π«‘
β COPYRIGHT AND LICENCE β
This software is copyright (c) 2013 by Karen Etheridge.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. free as in do whatever, just follow the Perl 5 terms. periodt. π
and that's the whole page, bestie π she was written for perl v5.34.0, dated 2022-06-17, and honestly? timeless. go validate some types. you're gonna eat. π
β¨
π¦ where this page comes from
- debian bookworm: libtest-deep-type-perl 0.008-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtest-deep-type-perl 0.008-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtest-deep-type-perl 0.008-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-deep-type-perl 0.008-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-deep-type-perl 0.008-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms