From: gfx Date: Wed, 9 Dec 2009 12:41:58 +0000 (+0900) Subject: Add a benchmark for duck_type X-Git-Tag: 0.44~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=32aaae090f70f13cef45b0233bc8914361f04d83;p=gitmo%2FMouse.git Add a benchmark for duck_type --- diff --git a/benchmarks/type_constraints.pl b/benchmarks/type_constraints.pl index 160e102..94e2f89 100644 --- a/benchmarks/type_constraints.pl +++ b/benchmarks/type_constraints.pl @@ -24,6 +24,7 @@ my $cxsa_is_loaded = eval q{ { package MouseOne; use Mouse; + use Mouse::Util::TypeConstraints; has simple => ( is => 'rw', ); @@ -46,11 +47,17 @@ my $cxsa_is_loaded = eval q{ is => 'rw', isa => 'ArrayRef[Int]', ); + + has with_tc_duck_type => ( + is => 'rw', + isa => duck_type([qw(simple)]), + ); __PACKAGE__->meta->make_immutable; } { package MooseOne; use Moose; + use Moose::Util::TypeConstraints; has simple => ( is => 'rw', ); @@ -71,6 +78,10 @@ my $cxsa_is_loaded = eval q{ is => 'rw', isa => 'ArrayRef[Int]', ); + has with_tc_duck_type => ( + is => 'rw', + isa => duck_type([qw(simple)]), + ); __PACKAGE__->meta->make_immutable; } @@ -161,3 +172,23 @@ cmpthese -1 => { }, ) : (), }; + +print "\nSETTING for attributes with type constraints duck_type() (except for C::XSAccessor)\n"; + +$foo = MouseOne->new(); +cmpthese -1 => { + 'Mouse' => sub{ + $mi->with_tc_duck_type($foo); + $mi->with_tc_duck_type($foo); + }, + 'Moose' => sub{ + $mx->with_tc_duck_type($foo); + $mx->with_tc_duck_type($foo); + }, + $cxsa_is_loaded ? ( + 'C::XSAccessor' => sub{ + $cx->simple($foo); + $cx->simple($foo); + }, + ) : (), +};