test (!defined eval { $a->{b} });
test ($@ =~ /zap/);
-test (overload::StrVal(qr/a/) =~ /^Regexp=SCALAR\(0x[0-9a-f]+\)$/);
-
{
package t229;
use overload '=' => sub { 42 },
sub numify { ${$_[0]} }
}
+{
+ package perl31793;
+ use overload cmp => sub { 0 };
+ package perl31793_fb;
+ use overload cmp => sub { 0 }, fallback => 1;
+ package main;
+ my $o = bless [], 'perl31793';
+ my $of = bless [], 'perl31793_fb';
+ my $no = bless [], 'no_overload';
+ test (overload::StrVal(\"scalar") =~ /^SCALAR\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal([]) =~ /^ARRAY\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal({}) =~ /^HASH\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal(sub{1}) =~ /^CODE\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal(\*GLOB) =~ /^GLOB\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal(\$o) =~ /^REF\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal(qr/a/) =~ /^Regexp=SCALAR\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal($o) =~ /^perl31793=ARRAY\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal($of) =~ /^perl31793_fb=ARRAY\(0x[0-9a-f]+\)$/);
+ test (overload::StrVal($no) =~ /^no_overload=ARRAY\(0x[0-9a-f]+\)$/);
+}
+
# These are all check that overloaded values rather than reference addressess
# are what is getting tested.
my ($two, $one, $un, $deux) = map {new Numify $_} 2, 1, 1, 2;
}
}
}
+{
+ # check that overloading works in regexes
+ {
+ package Foo493;
+ use overload
+ '""' => sub { "^$_[0][0]\$" },
+ '.' => sub {
+ bless [
+ $_[2]
+ ? (ref $_[1] ? $_[1][0] : $_[1]) . ':' .$_[0][0]
+ : $_[0][0] . ':' . (ref $_[1] ? $_[1][0] : $_[1])
+ ], 'Foo493'
+ };
+ }
+
+ my $a = bless [ "a" ], 'Foo493';
+ test('a' =~ /$a/);
+ test('x:a' =~ /x$a/);
+ test('x:a:=' =~ /x$a=$/);
+ test('x:a:a:=' =~ /x$a$a=$/);
+
+}
+
+{
+ my $twenty_three = 23;
+ # Check that constant overloading propagates into evals
+ BEGIN { overload::constant integer => sub { 23 } }
+ test(eval "17", $twenty_three);
+}
+
+
# Last test is:
-sub last {484}
+sub last {498}