foo
[gitmo/Class-MOP.git] / t / 031_method_modifiers.t
index a1d019e..73c915a 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 23;
+use Test::More tests => 26;
 use Test::Exception;
 
 BEGIN {
@@ -15,14 +15,15 @@ BEGIN {
 {
        my $trace = '';
 
-       my $method = Class::MOP::Method->new(sub { $trace .= 'primary' });
+       my $method = Class::MOP::Method->wrap(sub { $trace .= 'primary' });
        isa_ok($method, 'Class::MOP::Method');
 
        $method->();
        is($trace, 'primary', '... got the right return value from method');
        $trace = '';
 
-       my $wrapped = $method->wrap();
+       my $wrapped = Class::MOP::Method::Wrapped->wrap($method);
+       isa_ok($wrapped, 'Class::MOP::Method::Wrapped');
        isa_ok($wrapped, 'Class::MOP::Method');
 
        $wrapped->();
@@ -48,12 +49,13 @@ BEGIN {
 
 # test around method
 {
-       my $method = Class::MOP::Method->new(sub { 4 });
+       my $method = Class::MOP::Method->wrap(sub { 4 });
        isa_ok($method, 'Class::MOP::Method');
        
        is($method->(), 4, '... got the right value from the wrapped method');  
 
-       my $wrapped = $method->wrap;
+       my $wrapped = Class::MOP::Method::Wrapped->wrap($method);
+       isa_ok($wrapped, 'Class::MOP::Method::Wrapped');
        isa_ok($wrapped, 'Class::MOP::Method');
 
        is($wrapped->(), 4, '... got the right value from the wrapped method');
@@ -76,10 +78,11 @@ BEGIN {
 {
        my @tracelog;
        
-       my $method = Class::MOP::Method->new(sub { push @tracelog => 'primary' });
+       my $method = Class::MOP::Method->wrap(sub { push @tracelog => 'primary' });
        isa_ok($method, 'Class::MOP::Method');
        
-       my $wrapped = $method->wrap();
+       my $wrapped = Class::MOP::Method::Wrapped->wrap($method);
+       isa_ok($wrapped, 'Class::MOP::Method::Wrapped');
        isa_ok($wrapped, 'Class::MOP::Method'); 
        
        lives_ok {
@@ -89,15 +92,15 @@ BEGIN {
        } '... added the before modifier okay';
        
        lives_ok {
-               $wrapped->add_around_modifier(sub { push @tracelog => 'around 3'; $_[0]->(); });                
+               $wrapped->add_around_modifier(sub { push @tracelog => 'around 1'; $_[0]->(); });                
                $wrapped->add_around_modifier(sub { push @tracelog => 'around 2'; $_[0]->(); });
-               $wrapped->add_around_modifier(sub { push @tracelog => 'around 1'; $_[0]->(); });                                                
+               $wrapped->add_around_modifier(sub { push @tracelog => 'around 3'; $_[0]->(); });                                                
        } '... added the around modifier okay'; 
        
        lives_ok {
-               $wrapped->add_after_modifier(sub { push @tracelog => 'after 3' });
+               $wrapped->add_after_modifier(sub { push @tracelog => 'after 1' });
                $wrapped->add_after_modifier(sub { push @tracelog => 'after 2' });
-               $wrapped->add_after_modifier(sub { push @tracelog => 'after 1' });                              
+               $wrapped->add_after_modifier(sub { push @tracelog => 'after 3' });                              
        } '... added the after modifier okay';  
        
        $wrapped->();
@@ -105,9 +108,9 @@ BEGIN {
                \@tracelog,
                [ 
                  'before 3', 'before 2', 'before 1',  # last-in-first-out order
-                 'around 1', 'around 2', 'around 3',  # last-in-first-out order
+                 'around 3', 'around 2', 'around 1',  # last-in-first-out order
                  'primary',
-                 'after 3', 'after 2', 'after 1',     # first-in-first-out order
+                 'after 1', 'after 2', 'after 3',     # first-in-first-out order
                ],
                '... got the right tracelog from all our before/around/after methods');
 }