TEST2::COMPARE::NEGATABLE(3perl)

✨ Test2::Compare::Negatable ✨

okay bestie, welcome to Test2::Compare::Negatable(3perl) β€” this is the part of the Perl Programmers Reference Guide where we talk about a poor man's 'role' for compare objects that can be negated πŸ’…


🌸 NAME 🌸

Test2::Compare::Negatable β€” a poor mans 'role' for compare objects that can be negated. no cap, that's literally the whole job 🫢


πŸ’– DESCRIPTION πŸ’–

so if you use this package inside a Test2::Compare::Base subclass, it's gonna do two things for you:

  • overload !$obj (yes, the actual bang operator)
  • import clone_negate() and toggle_negate() into your class

that's it. that's the vibe. you get negation powers and you didn't even have to write them yourself ✨


πŸ¦‹ WHY? πŸ¦‹

okay so here's the lore πŸ“–. until perl 5.18, the 'fallback' parameter to overload would not be inherited. like, it just wouldn't come down the family tree. so we cannot use inheritance for the behavior we actually want 😭.

this module works around that whole situation by emulating the use overload call we want, for each consumer class individually. sneaky? a little. effective? absolutely πŸ’€


πŸ‘‘ ATTRIBUTES πŸ‘‘

here's the list, bestie, every single one:

  • $bool = $obj->negate β€” getter for the negate flag, hands you back a boolean πŸ’œ
  • $obj->set_negate($bool) β€” setter, you give it a $bool and it sets the thing
  • $attr = NEGATE() β€” the NEGATE attribute, which will be added via Test2::Util::HashBase

πŸŽ€ METHODS πŸŽ€

the methods, served fresh:

  • $clone = $obj->clone_negate() β€” creates a shallow copy of the object, and calls "toggle_negate" on it. shallow copy, so it's giving "same vibes, new wrapper" 🌈
  • $obj->toggle_negate() β€” toggles the negate attribute. if the attribute was on it will now be off, if it was off it will now be on. that's the flip, periodt πŸ”₯

πŸ”₯ SOURCE πŸ”₯

if you wanna go read the actual code (iconic behavior, honestly), the source code repository for Test2-Suite lives at:

https://github.com/Test-More/test-more/

πŸ’« MAINTAINERS πŸ’«

  • Chad Granum <exodist@cpan.org>

⭐ AUTHORS ⭐

  • Chad Granum <exodist@cpan.org>

Copyright Chad Granum <exodist@cpan.org>.

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/


fr fr, that's the whole page. go negate something, bestie 🫢✨

perl v5.44.0 Β· 2026-10-17 Β· Test2::Compare::Negatable(3perl) β€” mwah, ily, bye πŸ‘‘πŸŒΈ

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND 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