File: Compare.pm

package info (click to toggle)
libsql-translator-perl 0.11024-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,572 kB
  • sloc: perl: 67,471; sql: 3,809; xml: 258; makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,268 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package SQL::Translator::Schema::Role::Compare;

=head1 NAME

SQL::Translator::Schema::Role::Compare - compare objects

=head1 SYNOPSIS

    package Foo;
    use Moo;
	with qw(SQL::Translator::Schema::Role::Compare);

	$obj->equals($other);

=head1 DESCRIPTION

This L<Moo::Role> provides a method to compare if two objects are the
same.

=cut

use Moo::Role;

=head1 METHODS

=head2 equals

Determines if this object is the same as another.

  my $isIdentical = $object1->equals( $object2 );

=cut

sub equals {
    my $self = shift;
    my $other = shift;

    return 0 unless $other;
    return 1 if overload::StrVal($self) eq overload::StrVal($other);
    return 0 unless $other->isa( ref($self) );
    return 1;
}

sub _compare_objects {
#   my ($self, $obj1, $obj2) = @_;

   my $result = (
      Data::Dumper->new([$_[1]])->Terse(1)->Indent(0)->Deparse(1)->Sortkeys(1)->Maxdepth(0)->Dump
        eq
      Data::Dumper->new([$_[2]])->Terse(1)->Indent(0)->Deparse(1)->Sortkeys(1)->Maxdepth(0)->Dump
   );
#  if ( !$result ) {
#     use Carp qw(cluck);
#     cluck("How did I get here?");
#     use Data::Dumper;
#     $Data::Dumper::Maxdepth = 1;
#     print "obj1: ", Dumper($obj1), "\n";
#     print "obj2: ", Dumper($obj2), "\n";
#  }
   return $result;
}

1;