The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Test::HexDump::Range - Compare binary data and displays a diff of two range dumps if they differ

SYNOPSIS

 use Test::HexDump::Range  qw(diff_range) ;
 
 my $range_description = 'magic cookie,5, bright_cyan:type,12:  bf, x5b5    :meta_data,15:  size,2: offset,7' ;
 
 my $expected_binary = '01234' . '567890123456' . '789012345678901' . '23' . '4567890' ;
 my $got_binary =      '01234' . '5XY890123456' . '789012345678901' . 'Z3' . '4567890' ;
 
 print diff_range($range_description, $expected_binary, $got_binary) ; # use default configuration
 
 # below is not implemented yet !
 
 my $dr = Test::HexDump::Range->new
                        (
                        DISPLAY_COLUMN_NAMES => 1,
                        DISPLAY_RULER => 1,
                        INTER_LINE => 0,
                        COLORS => ['bright_green', 'bright_yellow','bright_cyan', 'bright_red', 'bright_white'],
                        ...
                        ) ;
                        
 print $dr->diff($range_description, $expected_binary, $got_binary) ;
 
 is_range_ok($range; $expected_binary, $got_binary) ;

DESCRIPTION

Takes a range description and two data chunks and displayes a binary diff highlighted according to the range description. The dump is always in horizontal orientation.

DOCUMENTATION

This is a developer relase. the only thing working is the diff_range subroutine (which may be the only thing that you need) and only in the static configuration this module was built with, ANSI format, ...

Example of output:

00000000 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35  5:magic cookie, 12:type,  
         30 31 32 33 34 35 58 59 38 39 30 31 32 33 34 35  

00000010 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31  12:type, 15:meta_data,  
         36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31  


00000020 32 33 34 35 36 37 38 39 30                       2:size, 7:offset,  
         5a 33 34 35 36 37 38 39 30                       

SUBROUTINES/METHODS

[P] Setup()

Helper sub called by new.

[P] CheckOptionNames()

Verifies the named options passed to the members of this class. Calls {INTERACTION}{DIE} in case of error.

diff_range($range_description, $expected_binary, $got_binary)

Compares two binary chunks and displays a hexadecimal dump witht a line from $expected_binary followed by a line from $got_binary. The output is highlighted according to the range description. If a difference occures, the bytes are displayed with a different backgound color.

Arguments

  • $range_description - A range description according to Data::HexDump::Range

  • $expected_binary - A String

  • $got_binary - A String

Returns - A String containing the diff

Exceptions - Croaks on invalid input

BUGS AND LIMITATIONS

None so far.

AUTHOR

        Nadim ibn hamouda el Khemir
        CPAN ID: NKH
        mailto: nadim@cpan.org

COPYRIGHT AND LICENSE

Copyright Nadim Khemir 2010 .

This program is free software; you can redistribute it and/or modify it under the terms of either:

  • the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or

  • the Artistic License version 2.0.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Test::HexDump::Range

You can also look for information at:

SEE ALSO