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'; |
d03bd989 |
20 | |
f50f7707 |
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'; |
d03bd989 |
35 | |
f50f7707 |
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'; |
d03bd989 |
50 | |
f50f7707 |
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 | } |
b15a4068 |
64 | { |
65 | package CMM::Install; |
66 | use Class::Method::Modifiers; |
67 | use base 'PlainParent'; |
68 | } |
69 | { |
70 | package Moose::Install; |
71 | use Moose; |
72 | extends 'MooseParent'; |
73 | } |
f50f7707 |
74 | |
75 | use Benchmark qw(cmpthese); |
76 | use Benchmark ':hireswallclock'; |
77 | |
78 | my $rounds = -5; |
79 | |
80 | my $cmm_before = CMMChild::Before->new(); |
81 | my $cmm_around = CMMChild::Around->new(); |
82 | my $cmm_allthree = CMMChild::AllThree->new(); |
83 | |
84 | my $moose_before = MooseBefore->new(); |
85 | my $moose_around = MooseAround->new(); |
86 | my $moose_allthree = MooseAllThree->new(); |
87 | |
88 | print "\nBEFORE\n"; |
89 | cmpthese($rounds, { |
90 | Moose => sub { $moose_before->method() }, |
91 | ClassMethodModifiers => sub { $cmm_before->method() }, |
92 | }, 'noc'); |
93 | |
94 | print "\nAROUND\n"; |
95 | cmpthese($rounds, { |
96 | Moose => sub { $moose_around->method() }, |
97 | ClassMethodModifiers => sub { $cmm_around->method() }, |
98 | }, 'noc'); |
99 | |
100 | print "\nALL THREE\n"; |
101 | cmpthese($rounds, { |
102 | Moose => sub { $moose_allthree->method() }, |
103 | ClassMethodModifiers => sub { $cmm_allthree->method() }, |
104 | }, 'noc'); |
105 | |
b15a4068 |
106 | print "\nINSTALL AROUND\n"; |
107 | cmpthese($rounds, { |
108 | Moose => sub { |
109 | package Moose::Install; |
110 | Moose::Install::around(method => sub {}); |
111 | }, |
112 | ClassMethodModifiers => sub { |
113 | package CMM::Install; |
114 | CMM::Install::around(method => sub {}); |
115 | }, |
116 | }, 'noc'); |
117 | |