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