fix overloads using method names in roles
[gitmo/Role-Tiny.git] / t / overload.t
CommitLineData
9256ec21 1use strict;
2use warnings FATAL => 'all';
3use Test::More;
4
5BEGIN {
6 package MyRole;
7 use Role::Tiny;
8
9 sub as_string { "welp" }
10 sub as_num { 219 }
11 use overload
12 '""' => \&as_string,
13 '0+' => 'as_num',
14 bool => sub(){1},
15 fallback => 1;
16}
17
18BEGIN {
19 package MyClass;
20 use Role::Tiny::With;
21 with 'MyRole';
22 sub new { bless {}, shift }
23}
24
25my $o = MyClass->new;
26is "$o", 'welp', 'subref overload';
27is 0+$o, 219, 'method name overload';
28ok !!$o, 'anon subref overload';
29
30done_testing;