Permalink
Browse files

Detects usage of old API and retro-compatibilizes.

  • Loading branch information...
1 parent 4ec337a commit de7103316c576f1d4985c2324aaa0776b60b8e06 @ruoso ruoso committed Jun 7, 2010
Showing with 42 additions and 3 deletions.
  1. +3 −0 Changes
  2. +3 −1 lib/MooseX/Method/Signatures.pm
  3. +7 −1 lib/MooseX/Method/Signatures/Meta/Method.pm
  4. +29 −1 t/meta.t
View
@@ -1,5 +1,8 @@
Version history for MooseX::Method::Signatures
+0.32 Thu, 01 Jun 2010 13:47:34 -0300
+ * Detect usage of old MXMS::Meta::Method API and retro-compatibilize.
+
0.31 Thu, 01 Jun 2010 13:47:34 -0300
* Add support for "does" as a trait declarator
* Compatibilize MXMS::Meta::Method signature with Class::MOP::Method
@@ -19,7 +19,7 @@ use aliased 'Devel::Declare::Context::Simple', 'ContextSimple';
use namespace::autoclean;
-our $VERSION = '0.31';
+our $VERSION = '0.32';
has package => (
is => 'ro',
@@ -626,6 +626,8 @@ With contributions from:
=item Cory Watson E<lt>gphat@cpan.orgE<gt>
+=item Daniel Ruoso E<lt>daniel@ruoso.comE<gt>
+
=item Hakim Cassimally E<lt>hakim.cassimally@gmail.comE<gt>
=item Jonathan Scott Duff E<lt>duff@pobox.comE<gt>
@@ -152,7 +152,13 @@ sub _wrapped_body {
around wrap => sub {
my $orig = shift;
my $self;
- my ($class, $code, %args) = @_;
+ my ($class, $code, %args);
+ if (ref $_[1]) {
+ ($class, $code, %args) = @_;
+ } else {
+ ($class, %args) = @_;
+ $code = delete $args{body};
+ }
my $wrapped = $class->_wrapped_body(\$self, %args);
$self = $class->$orig($wrapped, %args, actual_body => $code);
View
@@ -1,6 +1,6 @@
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::More tests => 6;
use Test::Exception;
use MooseX::Method::Signatures::Meta::Method;
@@ -30,3 +30,31 @@ lives_and(sub {
dies_ok(sub {
Foo->bar(foo => 'moo', bar => 'baz');
});
+
+# Makes sure we still support the old API.
+
+{
+ package Bar;
+ use metaclass;
+
+ my $method = MooseX::Method::Signatures::Meta::Method->wrap(
+ signature => '($class: Int :$foo, Str :$bar)',
+ package_name => __PACKAGE__,
+ name => 'bar',
+ body => sub {
+ my ($class, $foo, $bar) = @_;
+ return $bar x $foo;
+ },
+ );
+ ::isa_ok($method, 'Moose::Meta::Method');
+
+ Bar->meta->add_method(bar => $method);
+}
+
+lives_and(sub {
+ is(Bar->bar(foo => 3, bar => 'baz'), 'bazbazbaz');
+});
+
+dies_ok(sub {
+ Bar->bar(foo => 'moo', bar => 'baz');
+});

0 comments on commit de71033

Please sign in to comment.