From: Graham Knop Date: Mon, 24 Feb 2014 05:55:23 +0000 (-0500) Subject: tests for applying overloads to instances X-Git-Tag: v1.003003~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e5dcce87e83055911c14527b78d8958a598904f4;p=gitmo%2FRole-Tiny.git tests for applying overloads to instances --- diff --git a/t/overload.t b/t/overload.t index f4ce266..71ee3c7 100644 --- a/t/overload.t +++ b/t/overload.t @@ -35,6 +35,11 @@ BEGIN { sub class_string { 'yarp' } } +BEGIN { + package MyClass3; + sub new { bless {}, shift } +} + { my $o = MyClass->new; is "$o", 'welp', 'subref overload'; @@ -50,4 +55,19 @@ BEGIN { is sprintf('%d', $o), 42, 'subref overload not overwritten'; } +{ + my @o = (MyClass3->new) x 2; + my $copy = ''; + for my $o (@o) { + Role::Tiny->apply_roles_to_object($o, 'MyRole') + unless $copy; + local $TODO = 'magic not applied to all ref copies on perl < 5.8.9' + if $copy && $] < 5.008009; + is "$o", 'welp', 'subref overload applied to instance'.$copy; + is sprintf('%d', $o), 219, 'method name overload applied to instance'.$copy; + ok !$o, 'anon subref overload applied to instance'.$copy; + $copy ||= ' copy'; + } +} + done_testing;