summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/dist/Data-Dumper/t/overload.t
blob: 3ccd2a91c3fc7be4ef6ff2653f38d5682665b862 (plain) (blame)
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
#!./perl -w

BEGIN {
    if ($ENV{PERL_CORE}){
        require Config; import Config;
        no warnings 'once';
        if ($Config{'extensions'} !~ /\bData\/Dumper\b/) {
            print "1..0 # Skip: Data::Dumper was not built\n";
            exit 0;
        }
    }
}

use strict;
use Data::Dumper;

use Test::More tests => 4;

package Foo;
use overload '""' => 'as_string';

sub new { bless { foo => "bar" }, shift }
sub as_string { "%%%%" }

package main;

my $f = Foo->new;

isa_ok($f, 'Foo');
is("$f", '%%%%', 'String overloading works');

my $d = Dumper($f);

like($d, qr/bar/);
like($d, qr/Foo/);