Test::S...::Custom(3)
π Test::S...::Custom β bestie's guide to custom field checks π
okay so this is Test::Stream::Compare::Custom, from the User Contributed Perl Documentation, and it lives at Test::S...::Custom(3) (yes the man page name is literally abbreviated with dots, that's just how the pager prints it, don't come for her πΈ).
π¨ DEPRECATED π¨
ngl bestie, this whole distribution is deprecated π. It's been retired in favor of Test2, Test2::Suite, and Test2::Workflow.
If you need to migrate, go read Test::Stream::Manual::ToTest2 β it's the conversion guide. That's your map out of here πΊοΈβ¨
π DESCRIPTION
so likeβ¦ sometimes you wanna do something complicated or unusual when you're validating a field nested deep inside a deep data structure π³οΈπ. You've got options: you could pull that field out of the structure and test it separately, OR you could use this module to embed the check right there inside the comparison. It's giving "I don't wanna leave my house" energy.
Test::Stream::Compare::Custom gives you a way to write custom checks for fields in deep comparisons. Obsessed, honestly. π
β¨ SYNOPSIS β¨
my $cus = Test::Stream::Compare::Custom->new(
name => 'IsRef',
operator => 'ref(...)',
code => sub {
my ($got, $exists, $operator, $name) = @_;
return ref($got) ? 1 : 0;
},
);
# Pass
is(
{ a => 1, ref => {}, b => 2 },
{ a => 1, ref => $cus, b => 2 },
"This will pass"
);
# Fail
is(
{a => 1, ref => 'notref', b => 2},
{a => 1, ref => $cus, b => 2},
"This will fail"
);
look at her go ππ first one passes, second one fails, exactly like it says on the tin.
π ARGUMENTS π
Your custom sub gets 4 arguments, no more no less, she's very specific:
code => sub {
my ($got, $exists, $operator, $name) = @_;
return ref($got) ? 1 : 0;
},
also $_ is localized to $got β so for everyone out there who needs to use regexes, it's literally right there for you π«Ά regex girlies, this one's for you.
$got,$_β this is the value to be checked. the whole point of the exercise bestie β¨$existsβ a boolean. it's true if$gotexists at all. if$existsis false, that doesn't mean$gotis justundefβ it means$gotdoesn't exist at all. think checking the value of a hash key that isn't even there π» big difference, don't get it twisted.$operatorβ this is the operator you specified at construction. the one you handed over. that one π$nameβ this is the name you provided at construction. also that one π·οΈ
π METHODS π
$code = $cus->codeβ get the coderef that was provided at construction. gimme the code back π$name = $cus->nameβ get the name that was provided at construction. gimme the name back π$op = $cus->operatorβ get the operator that was provided at construction. gimme the operator back π$bool = $cus->verify(got => $got, exists => $bool)β run the verify. you pass itgotandexists, it hands you back a boolean π«‘
π SOURCE π
the source code repository for Test::Stream is at:
http://github.com/Test-More/Test-Stream/
go look, it's all there for you π¦
π MAINTAINERS π
Chad Granum <exodist@cpan.org>
π AUTHORS π
Chad Granum <exodist@cpan.org>
π COPYRIGHT π
Copyright 2015 Chad Granum <exodist7@gmail.com>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
and that's the whole page bestie, no cap π§β¨ this one came from perl v5.42.0 and it's dated 2025-07-25, printed out as Test::S...::Custom(3) β slay, go write some custom checks, you've got this ππΈπ
π¦ where this page comes from
- fedora 43: perl-Test-Stream 1.302027-35.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