1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Test::Exception;
{
package Dog;
use Moose;
sub bark_once {
my $self = shift;
return 'bark';
}
sub bark_twice {
return 'barkbark';
}
around qr/bark.*/ => sub {
'Dog::around(' . $_[0]->() . ')';
};
}
my $dog = Dog->new;
is( $dog->bark_once, 'Dog::around(bark)', 'around modifier is called' );
is( $dog->bark_twice, 'Dog::around(barkbark)', 'around modifier is called' );
{
package Cat;
use Moose;
our $BEFORE_BARK_COUNTER = 0;
our $AFTER_BARK_COUNTER = 0;
sub bark_once {
my $self = shift;
return 'bark';
}
sub bark_twice {
return 'barkbark';
}
before qr/bark.*/ => sub {
$BEFORE_BARK_COUNTER++;
};
after qr/bark.*/ => sub {
$AFTER_BARK_COUNTER++;
};
}
my $cat = Cat->new;
$cat->bark_once;
is( $Cat::BEFORE_BARK_COUNTER, 1, 'before modifier is called once' );
is( $Cat::AFTER_BARK_COUNTER, 1, 'after modifier is called once' );
$cat->bark_twice;
is( $Cat::BEFORE_BARK_COUNTER, 2, 'before modifier is called twice' );
is( $Cat::AFTER_BARK_COUNTER, 2, 'after modifier is called twice' );
{
package Dog::Role;
use Moose::Role;
::dies_ok {
before qr/bark.*/ => sub {};
} '... this is not currently supported';
::dies_ok {
around qr/bark.*/ => sub {};
} '... this is not currently supported';
::dies_ok {
after qr/bark.*/ => sub {};
} '... this is not currently supported';
}
done_testing;
|