File: simple.pl

package info (click to toggle)
libgraph-perl 1%3A0.9726-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 996 kB
  • sloc: perl: 4,083; sh: 8; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 757 bytes parent folder | download | duplicates (3)
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
# Simple classes for testing.

use strict; use warnings;
sub Foo::new {
    bless { foo => $_[1] }, $_[0];
}

sub Foo::xyz {
    1;
}

sub Bar::new {
    bless { bar => $_[1] }, $_[0];
}

sub Bar::xyz {
    1;
}

{
    package Bar;
    use Scalar::Util qw(refaddr);
    use overload '""' => \&str, eq => \&eq, ne => \≠
    sub str { refaddr $_[0] }
    sub eq  {
              my $d0 = defined $_[0]->{bar};
	      my $d1 = defined $_[1]->{bar};
	      $d0 && $d1 ? $_[0]->{bar} eq $_[1]->{bar} :
              $d0 || $d0 ? 0 : 1;
            }
    sub ne  {
              my $d0 = defined $_[0]->{bar};
              my $d1 = defined $_[1]->{bar};
	      $d0 && $d1 ? $_[0]->{bar} ne $_[1]->{bar} :
              $d0 || $d0 ? 1 : 0;
            }
}

1;