#!/usr/bin/perl -w
BEGIN {
$ENV
{MOO_XS_DISABLE} =
"no cheating"
;
$ENV
{MOUSE_PUREPERL} =
"no cheating"
;
}
sub
new {
my
(
$class
) =
shift
;
bless
{
test
=> 23 },
$class
;
}
has
test
=> (
is
=>
"rw"
);
has
test
=> (
is
=>
"rw"
);
has
test
=> (
is
=>
"rw"
);
has
test
=> (
is
=>
"rw"
);
has
test
=> (
is
=>
"rw"
);
has
test
=> (
is
=>
"rw"
);
my
$tmp
;
my
$direct
= Bench::Direct->new({
test
=> 23 });
my
%accessor
= (
Direct
=>
sub
{
$tmp
=
$direct
->{test}; } );
my
%mutator
= (
Direct
=>
sub
{
$direct
->{test} = 42; } );
for
my
$p
(
qw/Normal Fast Faster Moose Mouse Moo/
) {
my
$o
=
"Bench::$p"
->new({
test
=> 23 });
is
$o
->test, 23,
"$p init"
;
$o
->test(24);
is
$o
->test, 24,
"$p set"
;
$accessor
{
$p
} =
sub
{
$tmp
=
$o
->test; };
$mutator
{
$p
} =
sub
{
$o
->test(42); };
}
print
"accessors:\n"
;
cmpthese( -1, \
%accessor
);
print
"\n"
;
print
"mutators:\n"
;
cmpthese( -1, \
%mutator
);