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