summaryrefslogtreecommitdiff
path: root/cpan/List-Util/t/blessed.t
blob: 1d448afbf73530600af7ba6e3fd8d564c9c9d413 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!./perl

BEGIN {
    unless (-d 'blib') {
	chdir 't' if -d 't';
	@INC = '../lib';
	require Config; import Config;
	keys %Config; # Silence warning
	if ($Config{extensions} !~ /\bList\/Util\b/) {
	    print "1..0 # Skip: List::Util was not built\n";
	    exit 0;
	}
    }
}

use Test::More tests => 11;
use Scalar::Util qw(blessed);
use vars qw($t $x);

ok(!blessed(undef),	'undef is not blessed');
ok(!blessed(1),		'Numbers are not blessed');
ok(!blessed('A'),	'Strings are not blessed');
ok(!blessed({}),	'Unblessed HASH-ref');
ok(!blessed([]),	'Unblessed ARRAY-ref');
ok(!blessed(\$t),	'Unblessed SCALAR-ref');

$x = bless [], "ABC";
is(blessed($x), "ABC",	'blessed ARRAY-ref');

$x = bless {}, "DEF";
is(blessed($x), "DEF",	'blessed HASH-ref');

$x = bless {}, "0";
cmp_ok(blessed($x), "eq", "0",	'blessed HASH-ref');

{
  my $blessed = do {
    my $depth;
    no warnings 'redefine';
    local *UNIVERSAL::can = sub { die "Burp!" if ++$depth > 2; blessed(shift) };
    $x = bless {}, "DEF";
    blessed($x);
  };
  is($blessed, "DEF", 'recursion of UNIVERSAL::can');
}

{
  package Broken;
  sub isa { die };
  sub can { die };

  my $obj = bless [], __PACKAGE__;
  ::is( ::blessed($obj), __PACKAGE__, "blessed on broken isa() and can()" );
}