use strict;
use warnings;
-use Test::More tests => 30;
-use Test::Exception;
+use Test::More;
+use Test::Fatal;
use Class::MOP;
use Class::MOP::Method;
'... got the right return value from the wrapped method' );
$trace = '';
- lives_ok {
+ is( exception {
$wrapped->add_before_modifier( sub { $trace .= 'before -> ' } );
- }
- '... added the before modifier okay';
+ }, undef, '... added the before modifier okay' );
$wrapped->();
is( $trace, 'before -> primary',
);
$trace = '';
- lives_ok {
+ is( exception {
$wrapped->add_after_modifier( sub { $trace .= ' -> after' } );
- }
- '... added the after modifier okay';
+ }, undef, '... added the after modifier okay' );
$wrapped->();
is( $trace, 'before -> primary -> after',
is( $wrapped->(), 4, '... got the right value from the wrapped method' );
- lives_ok {
+ is( exception {
$wrapped->add_around_modifier( sub { ( 3, $_[0]->() ) } );
$wrapped->add_around_modifier( sub { ( 2, $_[0]->() ) } );
$wrapped->add_around_modifier( sub { ( 1, $_[0]->() ) } );
$wrapped->add_around_modifier( sub { ( 0, $_[0]->() ) } );
- }
- '... added the around modifier okay';
+ }, undef, '... added the around modifier okay' );
is_deeply(
[ $wrapped->() ],
isa_ok( $wrapped, 'Class::MOP::Method::Wrapped' );
isa_ok( $wrapped, 'Class::MOP::Method' );
- lives_ok {
+ is( exception {
$wrapped->add_before_modifier( sub { push @tracelog => 'before 1' } );
$wrapped->add_before_modifier( sub { push @tracelog => 'before 2' } );
$wrapped->add_before_modifier( sub { push @tracelog => 'before 3' } );
- }
- '... added the before modifier okay';
+ }, undef, '... added the before modifier okay' );
- lives_ok {
+ is( exception {
$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 3'; $_[0]->(); } );
- }
- '... added the around modifier okay';
+ }, undef, '... added the around modifier okay' );
- lives_ok {
+ is( exception {
$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 3' } );
- }
- '... added the after modifier okay';
+ }, undef, '... added the after modifier okay' );
$wrapped->();
is_deeply(
'check around_modifiers' );
}
-# unique names for each modifier
-{
- package Foo;
-
- sub orig1 {
- return (caller(1))[3];
- }
-
- sub orig2 {
- return (caller(1))[3];
- }
-
- my $meta = Class::MOP::Class->initialize(__PACKAGE__);
-
- $meta->add_around_method_modifier( 'orig1', sub { $_[0]->( $_[1] ) } );
- $meta->add_around_method_modifier( 'orig2', sub { $_[0]->( $_[1] ) } );
-}
-
-{
- is( Foo->orig1, 'Class::MOP::Class:::around-orig1', 'each modifier gets a unique name' );
- is( Foo->orig2, 'Class::MOP::Class:::around-orig2', 'each modifier gets a unique name' );
-}
+done_testing;