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 => ( |
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 | |
40 | do { |
41 | package MyClass; |
42 | use Moose; |
43 | with 'MyRole::LogMethod' => { |
44 | method => 'new', |
45 | }; |
46 | }; |
47 | |
48 | is_deeply([splice @calls], [], "no calls yet"); |
49 | MyClass->new; |
50 | is_deeply([splice @calls], ["calling new", "took 0 seconds", "called new"], "instrumented new"); |
51 | |