Commit | Line | Data |
03c4551d |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
4 | use Test::More tests => 2; |
5 | |
6 | my @calls; |
7 | |
8 | do { |
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 | |
39 | do { |
40 | package MyClass; |
41 | use Moose; |
42 | with 'MyRole::LogMethod' => { |
43 | method => 'new', |
44 | }; |
45 | }; |
46 | |
47 | is_deeply([splice @calls], [], "no calls yet"); |
48 | MyClass->new; |
49 | is_deeply([splice @calls], ["calling new", "took 0 seconds", "called new"], "instrumented new"); |
50 | |