File: refaddr.t

package info (click to toggle)
libdata-dump-streamer-perl 2.42-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 828 kB
  • sloc: perl: 3,206; makefile: 3
file content (39 lines) | stat: -rw-r--r-- 793 bytes parent folder | download | duplicates (2)
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
use Data::Dump::Streamer qw(refaddr);
use vars                 qw($t $y $x *F $v $r);
use Symbol               qw(gensym);

# Ensure we do not trigger and tied methods
tie *F, 'MyTie';

print "1..13\n";

my $i= 1;
foreach $v (undef, 10, 'string') {
    print "not " if refaddr($v);
    print "ok ", $i++, "\n";
}

foreach $r ({}, \$t, [], \*F, sub { }) {
    my $addr= $r + 0;
    print "not " unless refaddr($r) == $addr;
    print "ok ", $i++, "\n";
    my $obj= bless $r, 'FooBar';
    print "not " unless refaddr($r) == $addr;
    print "ok ", $i++, "\n";
}

package FooBar;

use overload
    '0+' => sub { 10 },
    '+'  => sub { 10 + $_[1] };

package MyTie;

sub TIEHANDLE { bless {} }
sub DESTROY   { }

sub AUTOLOAD {
    warn "$AUTOLOAD called";
    exit 1;    # May be in an eval
}