| 1 | # | ||||||||||
| 2 | # Copyright (c) 2014-2020 Christian Jaeger, copying@christianjaeger.ch | ||||||||||
| 3 | # | ||||||||||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||||||||||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||||||||||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||||||||||
| 7 | # bundled with this file. | ||||||||||
| 8 | # | ||||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | FP::DumperEqual - equality | ||||||||||
| 13 | |||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | use FP::DumperEqual; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | ok dumperequal [1, [2, 3]], [1, [1+1, 3]]; | ||||||||||
| 19 | ok not dumperequal [1, [2, 3]], [1, [1+2, 3]]; | ||||||||||
| 20 | |||||||||||
| 21 | my $s1 = "stringwithunicode"; | ||||||||||
| 22 | my $s2 = "stringwithunicode"; | ||||||||||
| 23 | utf8::decode($s2); | ||||||||||
| 24 | # ok not dumperequal $s1, $s2; | ||||||||||
| 25 | # ^-- hmm, it used to be the case that this gave false | ||||||||||
| 26 | ok dumperequal_utf8 $s1, $s2; | ||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||
| 30 | |||||||||||
| 31 | Deep structure equality comparison. | ||||||||||
| 32 | |||||||||||
| 33 | NOTE: using Data::Dumper and thus slow. | ||||||||||
| 34 | |||||||||||
| 35 | For a more proper solution, see FP::Equal | ||||||||||
| 36 | |||||||||||
| 37 | =head1 SEE ALSO | ||||||||||
| 38 | |||||||||||
| 39 | L<FP::Equal> | ||||||||||
| 40 | |||||||||||
| 41 | =head1 NOTE | ||||||||||
| 42 | |||||||||||
| 43 | This is alpha software! Read the status section in the package README | ||||||||||
| 44 | or on the L<website|http://functional-perl.org/>. | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | package FP::DumperEqual; | ||||||||||
| 49 | 26 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 26 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 51 | 26 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 52 | 26 | ▶ | use Exporter "import"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 53 | |||||||||||
| 54 | 26 | our @EXPORT = qw(dumperequal dumperequal_utf8); | |||||||||
| 55 | 26 | our @EXPORT_OK = qw(); | |||||||||
| 56 | 26 | our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |||||||||
| 57 | |||||||||||
| 58 | 26 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 59 | 26 | ▶ | use FP::Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 60 | |||||||||||
| 61 | # XX these are expensive, of course. Better solution? | ||||||||||
| 62 | |||||||||||
| 63 | 7 | ▶ | sub dumperequal { | ||||||||
|
Subroutine
dumperequal: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 64 | 7 | local $Data::Dumper::Sortkeys = 1; | |||||||||
| 65 | 7 | my $v0 = shift; | |||||||||
| 66 | 7 | my $a0 = Dumper($v0); | |||||||||
| 67 | 7 | for (@_) { | |||||||||
| 68 | 8 | ▶ | Dumper($_) eq $a0 or return ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | } | ||||||||||
| 70 | 1 | ||||||||||
| 71 | 5 | } | |||||||||
| 72 | |||||||||||
| 73 | 11 | ▶ | sub dumperequal_utf8 { | ||||||||
|
Subroutine
dumperequal_utf8: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||
| 74 | 11 | ▶ | @_ == 2 or fp_croak_arity 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 11 | local $Data::Dumper::Sortkeys = 1; | |||||||||
| 76 | |||||||||||
| 77 | # compare ignoring utf8 flags on strings | ||||||||||
| 78 | 11 | local $Data::Dumper::Useperl = 1; | |||||||||
| 79 | 11 | my $v0 = shift; | |||||||||
| 80 | 11 | my $a0 = Dumper($v0); | |||||||||
| 81 | 11 | for (@_) { | |||||||||
| 82 | 11 | ▶ | Dumper($_) eq $a0 or return ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | } | ||||||||||
| 84 | 1 | ||||||||||
| 85 | 11 | } | |||||||||
| 86 | |||||||||||
| 87 | 26 | 1 | |||||||||