1use strict;
2use warnings;
3
4package Test::Deep::Cmp;
5
6use overload
7	'&' => \&make_all,
8	'|' => \&make_any,
9	'""' => \&string,
10	fallback => 1,
11;
12
13sub import
14{
15	my $pkg = shift;
16
17	my $callpkg = caller();
18	if ($callpkg =~ /^Test::Deep::/)
19	{
20		no strict 'refs';
21
22		push @{$callpkg."::ISA"}, $pkg;
23	}
24}
25
26sub new
27{
28	my $pkg = shift;
29
30	my $self = bless {}, $pkg;
31
32	$self->init(@_);
33	return $self;
34}
35
36sub init
37{
38}
39
40sub make_all
41{
42	my ($e1, $e2) = @_;
43
44	if (UNIVERSAL::isa($e1, "Test::Deep::All"))
45	{
46		$e1->add($e2);
47		return $e1;
48	}
49	elsif(UNIVERSAL::isa($e2, "Test::Deep::All"))
50	{
51		$e2->add($e1);
52		return $e2;
53	}
54	else
55	{
56		return Test::Deep::all($e1, $e2);
57	}
58}
59
60sub make_any
61{
62	my ($e1, $e2) = @_;
63
64	if (UNIVERSAL::isa($e1, "Test::Deep::Any"))
65	{
66		$e1->add($e2);
67		return $e1;
68	}
69	elsif(UNIVERSAL::isa($e2, "Test::Deep::Any"))
70	{
71		$e2->add($e1);
72		return $e2;
73	}
74	else
75	{
76		return Test::Deep::any($e1, $e2);
77	}
78}
79
80sub cmp
81{
82	my ($a1, $a2, $rev) = @_;
83
84	($a1, $a2) = ($a2, $a1) if $rev;
85
86	return (overload::StrVal($a1) cmp overload::StrVal($a2));
87}
88
89sub string
90{
91	my $self = shift;
92
93	return overload::StrVal($self);
94}
95
96sub render_stack
97{
98	my $self = shift;
99	my $var = shift;
100
101	return $var;
102}
103
104sub renderExp
105{
106	my $self = shift;
107
108	return $self->renderGot($self->{val});
109}
110
111sub renderGot
112{
113	my $self = shift;
114
115	return Test::Deep::render_val(@_);
116}
117
118sub reset_arrow
119{
120	return 1;
121}
122
123sub data
124{
125	my $self = shift;
126
127	return $Test::Deep::Stack->getLast;
128}
129
1301;
131