Test::S...::Custom(3)

πŸ“¦
version 1.302027 Β· 2 versions
, in fedora 43

πŸ’– 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 $got exists at all. if $exists is false, that doesn't mean $got is just undef β€” it means $got doesn'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 it got and exists, 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 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