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