Bump to 0.03
[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 => (
13 is => 'ro',
14 isa => 'Str',
15 required => 1,
16 );
17
18 role {
19 my $p = shift;
20
21 before $p->method => sub {
22 push @calls, "calling " . $p->method
23 };
24
25 after $p->method => sub {
26 push @calls, "called " . $p->method
27 };
28
29 around $p->method => sub {
30 my $orig = shift;
31 my $start = 0; # time
32 $orig->(@_);
33 my $end = 0; # time
34
35 push @calls, "took " . ($end - $start) . " seconds";
36 };
37 };
38};
39
40do {
41 package MyClass;
42 use Moose;
43 with 'MyRole::LogMethod' => {
44 method => 'new',
45 };
46};
47
48is_deeply([splice @calls], [], "no calls yet");
49MyClass->new;
50is_deeply([splice @calls], ["calling new", "took 0 seconds", "called new"], "instrumented new");
51