TEST2::COMPARE::DELTA(3perl)
π¦ NAME π¦
Test2::Compare::Delta is your girl for representing the differences between nested data structures β and yes, that's the official 3perl manual you're reading rn. π
β¨ DESCRIPTION β¨
Okay so real talk: this module gets used by Test2::Compare. The moment two data structures get compared, a delta comes back at you. Deltas are a tree data structure, and they represent all the differences between two other data structures. It's giving receipts. π§Ύβ¨
π METHODS π
π CLASS METHODS π
$class->add_column($NAME => sub { ... })$class->add_column($NAME, %PARAMS)
This is how you add columns to the table that gets produced when a comparison fails. The first argument is always the column name, and bestie, it must be unique. No duplicates, no exceptions. π
The first form is the simple one: you just hand over a coderef that spits out the value to display in that column for any given delta. The arguments passed into the sub are the delta, and the row ID. Like so:
Test2::Compare::Delta->add_column(
Foo => sub {
my ($delta, $id) = @_;
return $delta->... ? 'foo' : 'bar'
},
);
The second form lets you have some extra options. The 'value' key is required and it must be a coderef. Every other key is optional, so no pressure. π«Ά
Test2::Compare::Delta->add_column(
'Foo', # column name
value => sub { ... }, # how to get the cell value
alias => 'FOO', # Display name (used in table header)
no_collapse => $bool, # Show column even if it has no values?
);
$bool = $class->remove_column($NAME)β this removes the specified column. It returns true if the column existed and got removed, and false if the column didn't exist. No exceptions get thrown, nope, none. So if a missing column is a problem for you, that's on you to check the return value yourself. π$class->set_column_alias($NAME, $ALIAS)β use this to change the table header, overriding the default column names with new ones. Glow-up for your headers. β¨
πΈ ATTRIBUTES πΈ
$bool = $delta->verified$delta->set_verified($bool)
This is true if the delta itself matched. And if the delta matched, then the problem lives in the delta's children, not the delta itself. Generational trauma but make it data structures. π
$aref = $delta->id$delta->set_id([$type, $name])
The ID for the delta β it's used to produce the path into the data structure. Example: "['HASH' => 'foo']" means the delta is in the path "...->{'foo'}". The valid types are "HASH", "ARRAY", "SCALAR", "META", and "METHOD". Memorize them, there's a quiz later. π
$val = $delta->got$delta->set_got($val)
Deltas get produced by comparing a received data structure 'got' against a check data structure 'check'. The 'got' attribute holds the value that was received for comparison.
$check = $delta->chk$check = $delta->check$delta->set_chk($check)$delta->set_check($check)
Same origin story: deltas come from comparing a received data structure 'got' against a check data structure 'check'. The 'check' attribute holds the value that was expected in the comparison.
"check" and "chk" are aliases for the same attribute. Two names, one attribute, iconic behavior. π
$aref = $delta->children$delta->set_children([$delta1, $delta2, ...])
A Delta may have child deltas, and if it does, this is an arrayref holding those children. Yes it's a tree, we said that. π³
$dne = $delta->dne$delta->set_dne($dne)
Sometimes a comparison ends up with one side or the other not existing at all β in that case this gets set to the name of the attribute that does not exist. It can be set to 'got' or 'check'.
$e = $delta->exception$delta->set_exception($e)
This gets set to the exception whenever the comparison failed because an exception got thrown. Not me catching an L in the middle of a diff π
π¦ OTHER π¦
$string = $delta->render_gotβ renders the string that should be used in a table to represent the received value in a comparison.$string = $delta->render_checkβ renders the string that should be used in a table to represent the expected value in a comparison. Match made in heaven with the one above. π$bool = $delta->should_showβ returns true if the delta should be shown in the table. Normally that's true for any unverified delta. It'll also be true for deltas that contain extra useful debug information, because we love a little bonus lore. π$aref = $delta->filter_visibleβ produces an arrayref of"[ $path => $delta ]"for all the deltas that should be displayed in the table.$aref = $delta->table_headerβ returns an array ref of the headers for the table.$string = $delta->table_opβ returns the operator that should be shown in the table.$string = $delta->table_check_linesβ returns the defined lines (the extra debug info) that should be displayed.$string = $delta->table_got_linesβ returns the generated lines (the extra debug info) that should be displayed.$aref = $delta->table_rowsβ returns an arrayref of table rows, and each row is itself an arrayref. Arrays all the way down, we been knew. π@table_lines = $delta->tableβ returns all the lines of the table that should be displayed. The whole thing. The final reveal. π
π SOURCE π
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. Go be nosy, bestie. π₯
π 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/
k that's the whole page, you ate fr fr π«Ά this was perl v5.44.0, dated 2026-10-17, from the Test2::...::Delta(3perl) page β mwah, go write some tests, ilyyy π
πβ¨
π¦ 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