Test2:...Object(3perl)
π Test2::Compare::Object β the manual page, bestie edition π
okay so real quick, this is the Perl Programmers Reference Guide page for Test2::Compare::Object, coming to you from the 3perl section of the manual. buckle up π
β¨ NAME β¨
Test2::Compare::Object β literally just the representation of an object during deep comparison. that's it, that's the vibe π
π¦ DESCRIPTION π¦
so this class lets you specify an expected object in a deep comparison, which sounds boring but is actually kind of iconic. you can:
- check the fields/elements of the underlying reference π
- call methods to verify results π₯
- do meta checks for object type AND ref type π
it's giving "i know exactly what this object should look like and i will not be gaslit." periodt. π
πΈ METHODS πΈ
$class = $obj->meta_class
The meta-class that gets used when checking the object type. it's mainly listed here because it's useful to override for specialized object subclasses (iykyk π§).
normally this just returns Test2::Compare::Meta. no cap.
$class = $obj->object_base
The base-class to be expected when checking the object type. again, mainly listed because it's handy to override for specialized object subclasses β¨.
normally this just returns 'UNIVERSAL'. yes bestie, UNIVERSAL, the mother of all classes π.
$obj->add_prop(...)
Add a meta-property to check β see Test2::Compare::Meta. this method just delegates, it's a whole middleman situation π.
$obj->add_field(...)
Add a hash-field to check β see Test2::Compare::Hash. also just delegates fr fr π«.
$obj->add_item(...)
Add an array item to check β see Test2::Compare::Array. yep, delegates again, consistent queen π.
$obj->add_call($method, $check)
$obj->add_call($method, $check, $name)
$obj->add_call($method, $check, $name, $context)
Add a method call check π«Ά. this will call the specified method on your object and verify the result. $method can be a method name, an array ref, or a coderef β versatile icon behavior π
.
- If it's an arrayref, the first element must be the method name, and everything after that is arguments that get passed to it. like,
[$method_name, @args], you know the drill π. - In the case of a coderef it can be helpful to provide an alternate name. when no name is provided, the name is either
$methodor the string'\&CODE'π. - If
$contextis'list', the method will be invoked in list context, and the result will be an arrayref π. - If
$contextis'hash', the method will be invoked in list context, and the result will be a hashref. heads up bestie, this will warn if the method returns an odd number of values β οΈ (hashrefs need even pairs, that's just math π).
π SOURCE π
The source code repository for Test2-Suite can be found at:
https://github.com/Test-More/test-more/
go star it, it's free π
π§ MAINTAINERS π§
Chad Granum <exodist@cpan.org>
π AUTHORS π
Chad Granum <exodist@cpan.org>
π 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/
that's the whole page bestie, every option, every signature, every delegation, not one detail dropped πβ¨πΈπ¦
signing off from perl v5.44.0 on 2026-10-17 β stay comparing, stay slaying π
π
π¦ 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