&& (Other = d)) )
+# define SM_OBJECT ( \
+ (sv_isobject(d) && (SvTYPE(SvRV(d)) != SVt_REGEXP)) \
+ || \
+ (sv_isobject(e) && (SvTYPE(SvRV(e)) != SVt_REGEXP)) ) \
+
# define SM_OTHER_REF(type) \
(SvROK(Other) && SvTYPE(SvRV(Other)) == SVt_##type)
if (SvGMAGICAL(e))
e = sv_mortalcopy(e);
+ if (SM_OBJECT)
+ Perl_croak(aTHX_ "Smart matching a non-overloaded object breaks encapsulation");
+
if (SM_CV_NEP) {
I32 c;
require './test.pl';
}
-plan tests => 5;
+plan tests => 11;
use strict;
use warnings;
+
+my @tests = ('$obj ~~ "key"', '"key" ~~ $obj', '$obj ~~ $obj');
+
{
package Test::Object::NoOverload;
sub new { bless { key => 1 } }
{
my $obj = Test::Object::NoOverload->new;
isa_ok($obj, 'Test::Object::NoOverload');
- my $r = eval { ($obj ~~ 'key') };
-
- local $::TODO = 'To be implemented';
-
- ok(
- ! defined $r,
- "we do not smart match against an object's underlying implementation",
- );
-
- like(
- $@,
- qr/overload/,
- "we die when smart matching an obj with no ~~ overload",
- );
+ for (@tests) {
+ my $r = eval;
+ ok(
+ ! defined $r,
+ "we do not smart match against an object's underlying implementation",
+ );
+ like(
+ $@,
+ qr/overload/,
+ "we die when smart matching an obj with no ~~ overload",
+ );
+ }
}
{
{
my $obj = Test::Object::CopyOverload->new;
isa_ok($obj, 'Test::Object::CopyOverload');
- ok($obj ~~ 'key', 'we are able to make an object ~~ overload');
+ ok(eval, 'we are able to make an object ~~ overload') for @tests;
}