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