Make compatibility tests optional. Its is almost useless now.
[gitmo/Mouse.git] / benchmarks / coercion.pl
CommitLineData
d03295d7 1#!perl
2use strict;
3use warnings;
4use Benchmark qw/cmpthese/;
5
6
7for my $klass (qw/Moose Mouse/) {
8 eval qq{
9 package ${klass}One;
346a3ab8 10 use $klass;
d03295d7 11 use ${klass}::Util::TypeConstraints;
346a3ab8 12
d03295d7 13 subtype 'NaturalNumber', as 'Int', where { \$_ > 0 };
14
15 coerce 'NaturalNumber',
16 from 'Str', via { 42 },
346a3ab8 17 ;
18
d03295d7 19 has n => (
20 is => 'rw',
21 isa => 'NaturalNumber',
22 coerce => 1,
23 );
24 no $klass;
25 __PACKAGE__->meta->make_immutable;
26 };
27 die $@ if $@;
28}
29
30print "Class::MOP: $Class::MOP::VERSION\n";
31print "Moose: $Moose::VERSION\n";
32print "Mouse: $Mouse::VERSION\n";
33print "---- new\n";
34cmpthese(
35 -1 => {
36 map { my $x = $_; $_ => sub { $x->new(n => 'foo') } }
37 map { "${_}One" }
38 qw/Moose Mouse/
39 }
40);
41
42print "---- new,set\n";
43cmpthese(
44 -1 => {
45 map { my $y = $_; $_ => sub { $y->new(n => 'foo')->n('bar') } }
46 map { "${_}One" }
47 qw/Moose Mouse/
48 }
49);
50
51print "---- set\n";
52my %c = map { $_ => "${_}One"->new(n => 'foo') } qw/Moose Mouse/;
53cmpthese(
54 -1 => {
55 map { my $y = $_; $_ => sub { $c{$y}->n('bar') } }
56 qw/Moose Mouse/
57 }
58);