Commit | Line | Data |
f50f7707 |
1 | #!perl |
2 | |
3 | ### MODULES |
4 | |
5 | { |
6 | package PlainParent; |
7 | sub new { bless {} => shift } |
8 | sub method { "P" } |
9 | } |
10 | { |
11 | package MooseParent; |
12 | use Moose; |
13 | sub method { "P" } |
14 | } |
15 | |
16 | { |
17 | package CMMChild::Before; |
18 | use Class::Method::Modifiers; |
19 | use base 'PlainParent'; |
20 | |
21 | before method => sub { "B" }; |
22 | } |
23 | { |
24 | package MooseBefore; |
25 | use Moose; |
2727db28 |
26 | extends 'MooseParent'; |
f50f7707 |
27 | |
28 | before method => sub { "B" }; |
29 | } |
30 | |
31 | { |
32 | package CMMChild::Around; |
33 | use Class::Method::Modifiers; |
34 | use base 'PlainParent'; |
35 | |
36 | around method => sub { shift->() . "A" }; |
37 | } |
38 | { |
39 | package MooseAround; |
40 | use Moose; |
2727db28 |
41 | extends 'MooseParent'; |
f50f7707 |
42 | |
43 | around method => sub { shift->() . "A" }; |
44 | } |
45 | |
46 | { |
47 | package CMMChild::AllThree; |
48 | use Class::Method::Modifiers; |
49 | use base 'PlainParent'; |
50 | |
51 | before method => sub { "B" }; |
52 | around method => sub { shift->() . "A" }; |
53 | after method => sub { "Z" }; |
54 | } |
55 | { |
56 | package MooseAllThree; |
57 | use Moose; |
2727db28 |
58 | extends 'MooseParent'; |
f50f7707 |
59 | |
60 | before method => sub { "B" }; |
61 | around method => sub { shift->() . "A" }; |
62 | after method => sub { "Z" }; |
63 | } |
64 | |
65 | use Benchmark qw(cmpthese); |
66 | use Benchmark ':hireswallclock'; |
67 | |
68 | my $rounds = -5; |
69 | |
70 | my $cmm_before = CMMChild::Before->new(); |
71 | my $cmm_around = CMMChild::Around->new(); |
72 | my $cmm_allthree = CMMChild::AllThree->new(); |
73 | |
74 | my $moose_before = MooseBefore->new(); |
75 | my $moose_around = MooseAround->new(); |
76 | my $moose_allthree = MooseAllThree->new(); |
77 | |
78 | print "\nBEFORE\n"; |
79 | cmpthese($rounds, { |
80 | Moose => sub { $moose_before->method() }, |
81 | ClassMethodModifiers => sub { $cmm_before->method() }, |
82 | }, 'noc'); |
83 | |
84 | print "\nAROUND\n"; |
85 | cmpthese($rounds, { |
86 | Moose => sub { $moose_around->method() }, |
87 | ClassMethodModifiers => sub { $cmm_around->method() }, |
88 | }, 'noc'); |
89 | |
90 | print "\nALL THREE\n"; |
91 | cmpthese($rounds, { |
92 | Moose => sub { $moose_allthree->method() }, |
93 | ClassMethodModifiers => sub { $cmm_allthree->method() }, |
94 | }, 'noc'); |
95 | |