Skip to content

Commit

Permalink
expanded tests for MSM to include all modifiers
Browse files Browse the repository at this point in the history
now checks: before, after, around, override, and augment
also found a failing case for requiring subname, so added that to MSM as well
  • Loading branch information
barefootcoder committed Apr 13, 2011
1 parent 7011bac commit 56eae9f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/Method/Signatures/Modifiers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package Method::Signatures::Modifiers;
use strict;
use warnings;

use Sub::Name;

This comment has been minimized.

Copy link
@schwern

schwern Jun 29, 2011

Missing dependency on Sub::Name.

Fixed bb50885

use constant BASE => 'Method::Signatures';
use base BASE;

Expand Down Expand Up @@ -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;
Expand Down
24 changes: 22 additions & 2 deletions t/lib/MS_MXD_Replace.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}


Expand Down
10 changes: 8 additions & 2 deletions t/mxd-replace.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 ($_)";
}

}

Expand Down

0 comments on commit 56eae9f

Please sign in to comment.