foreach my $i (grep !exists $has_methods{$_}, keys %$methods) {
no warnings 'once';
- *{_getglob "${to}::${i}"} = $methods->{$i};
+ my $glob = _getglob "${to}::${i}";
+ *$glob = $methods->{$i};
+
+ # overloads using method names have the method stored in the scalar slot
+ next
+ unless $i =~ /^\(/
+ && defined &overload::nil
+ && $methods->{$i} == \&overload::nil;
+
+ my $overload = ${ *{_getglob "${role}::${i}"}{SCALAR} };
+ next
+ unless defined $overload;
+
+ *$glob = \$overload;
}
$me->_install_does($to);
--- /dev/null
+use strict;
+use warnings FATAL => 'all';
+use Test::More;
+
+BEGIN {
+ package MyRole;
+ use Role::Tiny;
+
+ sub as_string { "welp" }
+ sub as_num { 219 }
+ use overload
+ '""' => \&as_string,
+ '0+' => 'as_num',
+ bool => sub(){1},
+ fallback => 1;
+}
+
+BEGIN {
+ package MyClass;
+ use Role::Tiny::With;
+ with 'MyRole';
+ sub new { bless {}, shift }
+}
+
+my $o = MyClass->new;
+is "$o", 'welp', 'subref overload';
+is 0+$o, 219, 'method name overload';
+ok !!$o, 'anon subref overload';
+
+done_testing;