added Test::Exception prereq, replaced eval's in tests
[gitmo/MooseX-Role-Parameterized.git] / t / 008-method-modifers.t
CommitLineData
03c4551d 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More tests => 2;
5
6my @calls;
7
8do {
9 package MyRole::LogMethod;
10 use MooseX::Role::Parameterized;
11
12 parameter method => (
03c4551d 13 isa => 'Str',
14 required => 1,
15 );
16
17 role {
18 my $p = shift;
19
20 before $p->method => sub {
21 push @calls, "calling " . $p->method
22 };
23
24 after $p->method => sub {
25 push @calls, "called " . $p->method
26 };
27
28 around $p->method => sub {
29 my $orig = shift;
30 my $start = 0; # time
31 $orig->(@_);
32 my $end = 0; # time
33
34 push @calls, "took " . ($end - $start) . " seconds";
35 };
36 };
37};
38
39do {
40 package MyClass;
41 use Moose;
42 with 'MyRole::LogMethod' => {
43 method => 'new',
44 };
45};
46
47is_deeply([splice @calls], [], "no calls yet");
48MyClass->new;
49is_deeply([splice @calls], ["calling new", "took 0 seconds", "called new"], "instrumented new");
50