File Coverage

File:local/lib/perl5/Test/Deep/Cmp.pm
Coverage:37.2%

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