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
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 6;
package Blorp; {
use namespace::sweep;
use overload '+' => \&_plus, '*' => \&_times, 'bool' => sub { 1 };
use Scalar::Util 'reftype';
sub method { return 1 }
sub _plus { return 42 }
sub _times { return "wh00p wh00p" }
}
package main;
my $o = bless { }, 'Blorp';
ok $o;
isa_ok $o, 'Blorp';
ok $o->method;
eval { $o->reftype };
like $@, qr{^Can't locate object method "reftype"};
is $o + $o, 42;
is $o * $o, 'wh00p wh00p';
|