Test2::...:Object(3pm)
π NAME π
ok so this is Test2::Compare::Object β the whole vibe is: it's the representation of an object during deep comparison. periodt.
(also just fyi, the manual name up top shows as Test2::...:Object(3pm) in your terminal because it got cut off β it's giving β¨mysteriousβ¨ but it's really Test2::Compare::Object, part of the Perl Programmers Reference Guide π)
π¦ DESCRIPTION π¦
Bestie. Listen. This class is how you say "I expect THIS object" in a deep comparison. That's the whole assignment and she ate π
With it you can:
- check the fields/elements of the underlying reference π
- call methods on it to verify the results π―
- do meta checks for the object type and the ref type β¨
no cap, it's lowkey the main character of object comparison π
πΈ METHODS πΈ
β $class = $obj->meta_class
So this is the meta-class that gets used when checking the object type. It's mostly here in the docs because it's genuinely useful to override when you're dealing with specialized object subclasses β like, that's the whole point, iykyk π«Ά
Normally? It just returns Test2::Compare::Meta.
β $class = $obj->object_base
Same situation, different flavor: this is the base-class you expect when checking the object type. Also mainly documented because overriding it for specialized object subclasses is the move π
Normally it just returns 'UNIVERSAL'.
β $obj->add_prop(...)
Adds a meta-property to check β go look at Test2::Compare::Meta for the deets. This method just delegates. literally just passing the message along, no notes π
β $obj->add_field(...)
Adds a hash-field to check, see Test2::Compare::Hash. Also just delegates. she's a middlewoman and she's thriving π
β $obj->add_item(...)
Adds an array item to check, see Test2::Compare::Array. Yep β delegates. again. iconic behavior honestly π
β $obj->add_call($method, $check)
β $obj->add_call($method, $check, $name)
β $obj->add_call($method, $check, $name, $context)
ok THIS one's the big one bestie π₯ this adds a method call check. What happens: it calls the method you specify on your object, then verifies the result. slay.
$method can be any of these three things:
- a method name π
- an array ref π§
- a coderef π¦
Now let's break these down, because the details matter:
- If
$methodis an arrayref β the first element must be the method name, and everything after it is the arguments that get passed to it. no skipping the first slot, that's the rules π - If
$methodis a coderef β it's helpful to give an alternate name. When you don't provide a name, the name ends up being either$methodor the string'\&CODE'. that's the fallback, that's the vibe β
And then the $context situation:
- If
$contextis'list'β the method gets invoked in list context, and the result will be an arrayref. - If
$contextis'hash'β the method gets invoked in list context, and the result will be a hashref. β οΈ heads up: this one warns if the method returns an odd number of values β so don't be out here returning an odd list and acting surprised π that's on you.
π SOURCE π
The source code repository for Test2-Suite lives right here, bestie:
https://github.com/Test-More/test-more/
go star it, it's giving open source royalty π
π«Ά MAINTAINERS π«Ά
Chad Granum <exodist@cpan.org>
β¨ AUTHORS β¨
Chad Granum <exodist@cpan.org>
(yes same person, he's carrying the whole thing, main character energy fr fr π)
π COPYRIGHT π
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/
π cute lil sign-off: this page came from perl v5.42.3, dated 2026-11-03. drink some water, go call your Test2::Compare::Object a good girl, and remember β deep comparison is self care π
β¨π
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms