From 56eae9fb3e7a2bfc8afd5c4ac4cd36b68747d8b5 Mon Sep 17 00:00:00 2001 From: Buddy Burden Date: Tue, 12 Apr 2011 17:26:17 -0700 Subject: [PATCH] expanded tests for MSM to include all modifiers now checks: before, after, around, override, and augment also found a failing case for requiring subname, so added that to MSM as well --- lib/Method/Signatures/Modifiers.pm | 5 ++++- t/lib/MS_MXD_Replace.pm | 24 ++++++++++++++++++++++-- t/mxd-replace.t | 10 ++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/Method/Signatures/Modifiers.pm b/lib/Method/Signatures/Modifiers.pm index 00d002f..d4a09dc 100644 --- a/lib/Method/Signatures/Modifiers.pm +++ b/lib/Method/Signatures/Modifiers.pm @@ -3,6 +3,8 @@ package Method::Signatures::Modifiers; use strict; use warnings; +use Sub::Name; + use constant BASE => 'Method::Signatures'; use base BASE; @@ -109,7 +111,8 @@ sub code_for unless $class->can($name); no strict 'refs'; - $meta->$add($name => shift); + my $code = subname "${class}::$name" => shift; + $meta->$add($name => $code); }; return $code; diff --git a/t/lib/MS_MXD_Replace.pm b/t/lib/MS_MXD_Replace.pm index 7a31c20..e0fea22 100644 --- a/t/lib/MS_MXD_Replace.pm +++ b/t/lib/MS_MXD_Replace.pm @@ -4,14 +4,34 @@ use Method::Signatures::Modifiers; class Foo { - method foo (Num $num) {} + method test_before (Num $num) {} + method test_around (Num $num) {} + method test_after (Num $num) {} + method test_override (Num $num) {} + method test_augment (Num $num) { inner($num); } } +# Obviously, it's not a very good idea to change the parameter types for before, after, or augment +# modifiers. (Changing the parameter type for around is okay, and changing it for override is more +# of an academic/philosophical point.) However, doing this allows us to test that MXMS is being +# replaced by MSM by looking at the error messages. class Foo::Bar extends Foo { - around foo (Int $num) { + before test_before (Int $num) {} + + around test_around (Int $num) + { $self->$orig($num / 2); } + + after test_after (Int $num) {} + + after test_override (Int $num) + { + return super; + } + + augment test_augment (Int $num) {} } diff --git a/t/mxd-replace.t b/t/mxd-replace.t index 30958d6..f491dae 100644 --- a/t/mxd-replace.t +++ b/t/mxd-replace.t @@ -16,8 +16,14 @@ SKIP: my $foo = Foo->new; my $foobar = Foo::Bar->new; - throws_ok { $foo->foo('bmoogle') } badval_error($foo, num => Num => 'bmoogle' => 'foo'), 'MXD using MS for method'; - throws_ok { $foobar->foo(.5) } badval_error($foobar, num => Int => .5 => 'foo'), 'MXD using MS for around'; + foreach ( qw< before after around override augment > ) + { + my $method = "test_$_"; + throws_ok { $foo->$method('bmoogle') } badval_error($foo, num => Num => 'bmoogle' => $method), + "MXD using MS for method ($_)"; + throws_ok { $foobar->$method(.5) } badval_error($foobar, num => Int => .5 => $method), + "MXD using MSM for modifier ($_)"; + } }