1#!/usr/bin/env perl 2use strict; 3use warnings; 4use Test::More tests => 4; 5use Test::Exception; 6 7my @calls; 8my ($before, $after, $around); 9 10do { 11 package Role; 12 use Mouse::Role; 13 14 $before = sub { 15 push @calls, 'Role::foo:before'; 16 }; 17 before foo => $before; 18 19 $after = sub { 20 push @calls, 'Role::foo:after'; 21 }; 22 after foo => $after; 23 24 $around = sub { 25 my $orig = shift; 26 push @calls, 'Role::foo:around_before'; 27 $orig->(@_); 28 push @calls, 'Role::foo:around_after'; 29 }; 30 around foo => $around; 31 32 no Mouse::Role; 33}; 34 35is_deeply([Role->meta->get_before_method_modifiers('foo')], [$before]); 36is_deeply([Role->meta->get_after_method_modifiers('foo')], [$after]); 37is_deeply([Role->meta->get_around_method_modifiers('foo')], [$around]); 38 39do { 40 package Class; 41 use Mouse; 42 with 'Role'; 43 44 sub foo { 45 push @calls, 'Class::foo'; 46 } 47 48 no Mouse; 49}; 50 51Class->foo; 52is_deeply([splice @calls], [ 53 'Role::foo:before', 54 'Role::foo:around_before', 55 'Class::foo', 56 'Role::foo:around_after', 57 'Role::foo:after', 58]); 59 60