X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=benchmarks%2Ftype_constraints.pl;h=94e2f89430a1f41700455f5d281384939a0dddfb;hb=36e85b8cb4375445f5df32fb610a8bba0828f55f;hp=160e102d9d448ed99edba30e954912c97c324633;hpb=c6821d12fa22d1236df47b12749f1517493c2cf4;p=gitmo%2FMouse.git 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); + }, + ) : (), +};