++ed by:
JEFFOBER PETDANCE DEMIAN POTATOGIM EXODIST

11 PAUSE users
7 non-PAUSE users.

Chad Granum

NAME

Test2::Compare::Delta - Representation of differences between nested data structures.

DESCRIPTION

This is used by Test2::Compare. When data structures are compared a delta will be returned. Deltas are a tree data structure that represent all the differences between two other data structures.

METHODS

CLASS METHODS

$class->add_column($NAME => sub { ... })
$class->add_column($NAME, %PARAMS)

This can be used to add columns to the table that it produced when a comparison fails. The first argument should always be the column name, which must be unique.

The first form simply takes a coderef that produces the value that should be displayed in the column for any given delta. The arguments passed into the sub are the delta, and the row ID.

    Test2::Compare::Delta->add_column(
        Foo => sub {
            my ($delta, $id) = @_;
            return $delta->... ? 'foo' : 'bar'
        },
    );

The second form allows you some extra options. The 'value' key is required, and must be a coderef. All other keys are optional.

    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 will remove the specified column. This will return true if the column existed and was removed. This will return false if the column did not exist. No exceptions are thrown. If a missing column is a problem then you need to check the return yourself.

$class->set_column_alias($NAME, $ALIAS)

This can be used to change the table header, overriding the default column names with new ones.

ATTRIBUTES

$bool = $delta->verified
$delta->set_verified($bool)

This will be true if the delta itself matched, if the delta matched then the problem is in the delta's children, not the delta itself.

$aref = $delta->id
$delta->set_id([$type, $name])

ID for the delta, used to produce the path into the data structure. An example is ['HASH' => 'foo'] which means the delta is in the path ...->{'foo'}. Valid types are HASH, ARRAY, SCALAR, META, and METHOD.

$val = $delta->got
$delta->set_got($val)

Deltas are produced by comparing a received data structure 'got' against a check data structure 'check'. The 'got' attribute contains the value that was received for comparison.

$check = $delta->chk
$check = $delta->check
$delta->set_chk($check)
$delta->set_check($check)

Deltas are produced by comparing a received data structure 'got' against a check data structure 'check'. The 'check' attribute contains the value that was expected in the comparison.

check and chk are aliases for the same attribute.

$aref = $delta->children
$delta->set_children([$delta1, $delta2, ...])

A Delta may have child deltas. If it does then this is an arrayref with those children.

$dne = $delta->dne
$delta->set_dne($dne)

Sometimes a comparison results in one side or the other not existing at all, in which case this is set to the name of the attribute that does not exist. This can be set to 'got' or 'check'.

$e = $delta->exception
$delta->set_exception($e)

This will be set to the exception in cases where the comparison failed due to an exception being thrown.

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.

$bool = $delta->should_show

This will return true if the delta should be shown in the table. This is normally true for any unverified delta. This will also be true for deltas that contain extra useful debug information.

$aref = $delta->filter_visible

This will produce an arrayref of [ $path => $delta ] for all deltas that should be displayed in the table.

$aref = $delta->table_header

This returns an array ref of the headers for the table.

$string = $delta->table_op

This returns the operator that should be shown in the table.

$string = $delta->table_check_lines

This returns the defined lines (extra debug info) that should be displayed.

$string = $delta->table_got_lines

This returns the generated lines (extra debug info) that should be displayed.

$aref = $delta->table_rows

This returns an arrayref of table rows, each row is itself an arrayref.

@table_lines = $delta->table

Returns all the lines of the table that should be displayed.

SOURCE

The source code repository for Test2-Suite can be found at https://github.com/Test-More/Test2-Suite/.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright 2018 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/