Diff
NAME
Date::Dump::Tree::Diff - Renders two data structures in synch
SYNOPSIS
Data::Dump::Tree::Diff is a Role you can add to a Data::Dump::Tree object
The role add a dump_synched method to the object that can:
can display two data structures side by side
can display the difference between two data structures
INTERFACE
method get_synched_dump($s1, $s2, *%options)
Dumps of the synchronized structures on the terminal
USAGE
$d.dump_synched(
# data structures to dump
%df1,%df2,
#options to be used on both sides of the dump
does => (DDTR::MatchDetails,), color_glyphs => True,
#options specific to the synchronized dump
diff_glyphs => False, compact_width => True,
remove_eq => True, remove_eqv => True) ;
Output example
{8} @0 ~ {7} @0
|- A => {5} @1 === |- A => {5} @1
| |- a => 1 / "1".IntStr === | |- a => 1 / "1".IntStr
| |- b => 2 / "2".IntStr === | |- b => 2 / "2".IntStr
| |- c => 3 / "3".IntStr === | |- c => 3 / "3".IntStr
| |- d => {1} @2 === | |- d => {1} @2
| | `- x => {1} @3 === | | `- x => {1} @3
| | `- y => 1 / "1".IntStr === | | `- y => 1 / "1".IntStr
| `- e => 1.Int === | `- e => 1.Int
|- B => {3} @4 ~ |- B => {5} @4 = @1
| |- a => 1 / "1".IntStr eqv | |- a => 1 / "1".IntStr
| |- b => 2 / "2".IntStr eqv | |- b => 2 / "2".IntStr
| |- c => 3 / "3".IntStr eqv | |- c => 3 / "3".IntStr
| |- d (-) [r | |- d => {1} @5 = @2
| `- e (-) ! | `- e => 1.Int
|- C => {3} @5 eqv |- C => {3} @6
| |- a => 1 / "1".IntStr eqv | |- a => 1 / "1".IntStr
| |- b => 2 / "2".IntStr eqv | |- b => 2 / "2".IntStr
| `- c => 3 / "3".IntStr eqv | `- c => 3 / "3".IntStr
|- D => 0.3 (3/10).Rat ! |- D => hi.Str
|- E => 1.Int != |- E => 2.Int
|- F => 2.Int [r |- F => {3} @7
| [r | |- a => 1 / "1".IntStr
| [r | |- b => 2 / "2".IntStr
...
Configuration and Overrides
Check Data::Dump::Tree for the options that you can pass the dumper. The same options will be used on both sides of the dump. All the Data::Dump::Tree options are valid
title
You can eiter set the title for both sides simulteanously or for each side using:
lhs_title
rhs_title
Width
By default the terminal width will be divided in two, minus the room for the diff glyphs column. You can also set option width or use
compact_width
Put the two data structures as close to each other as possible
The default glyphs are:
same_object => '===',
same_type_same_value => 'eqv',
same_type_diff_value => '!= ',
different_type => ' ! ',
same_container => ' ~ ',
diff_container => '!~!',
container_left => ' [r',
container_right => 'l] ',
only_lhs => 'l ',
only_rhs => ' r' ;
diff_glyphs
You can set this option to False if you do not want the diff glyph column to be displayed.
Displaying only the difference between the data structures
Below is an example where only different elements are displayed; the diff glyphs column was also removed from the dump. The example can be found in examples/diff.
{8} @0 {7} @0
|- B => {3} @4 |- B => {5} @4 = @1
| |- d (-) | |- d => {1} @5 = @2
| `- e (-) | `- e => 1.Int
|- D => 0.3 (3/10).Rat |- D => hi.Str
|- E => 1.Int |- E => 2.Int
|- F => 2.Int |- F => {3} @7
| | |- a => 1 / "1".IntStr
| | |- b => 2 / "2".IntStr
| | `- c => 3 / "3".IntStr
|- G => {1} @6 |- G (-)
| `- a => 1 / "1".IntStr |
You can set
remove_eq
set if you want the to remove from the display the objects that are exactly the same in both data structures.
remove_eqv
set if you want the to remove from the display the objects that are equivalent in both data structures.
data structure filters
you can set header_filters, elements_filters, and footer_filters as described in Data::Dump::Tree documentation.
You can also specify filters that are specific to a side of the diff
rhs_header_filters and lhs_header_filters
rhs_elements_filters and lhs_elements_filters
rhs_footer_filters and lhs_footer_filters
diff synchronization filter
Data::Dump::Tree::Diff synchronizes Hashes, if you want to synch other type of data you can set
diff_synch_filter
Note that you will have to synch Hashes too if you want to keep them ordered properly.
AUTHOR
Nadim ibn hamouda el Khemir https://github.com/nkh
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl6 itself.
SEE-ALSO
Data::Dump::Tree
) ; }