The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Stream::Delta - Representation of differences between nested data structures.

EXPERIMENTAL CODE WARNING

This is an experimental release! Test-Stream, and all its components are still in an experimental phase. This dist has been released to cpan in order to allow testers and early adopters the chance to write experimental new tools with it, or to add experimental support for it into old tools.

PLEASE DO NOT COMPLETELY CONVERT OLD TOOLS YET. This experimental release is very likely to see a lot of code churn. API's may break at any time. Test-Stream should NOT be depended on by any toolchain level tools until the experimental phase is over.

DESCRIPTION

This is used by Test::Stream::Compare. When data structures are compared a delta will be returned. Deltas are a tree datastructure that represent all the differences between 2 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.

    Test::Stream::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.

    Test::Stream::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.

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 deltas children, not the delta itself.

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

Id for the delta, this is 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 recieved data structure 'got' against a check data structure 'check'. The 'got' attribute contains the value that was recieved for comparison.

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

Deltas are produced by comparing a recieved 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 recieved 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 Test::Stream can be found at http://github.com/Test-More/Test-Stream/.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright 2015 Chad Granum <exodist7@gmail.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html