fix overloads using method names in roles
[gitmo/Role-Tiny.git] / t / overload.t
diff --git a/t/overload.t b/t/overload.t
new file mode 100644 (file)
index 0000000..9e83c55
--- /dev/null
@@ -0,0 +1,30 @@
+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;