has 'baz' => (is => 'rw');
has 'bar' => (is => 'rw', isa => 'Foo');
- has 'boo' => (is => 'rw', isa => type 'CustomFoo' => where { blessed($_) && $_->isa('Foo') });
}
my $foo = Foo->new;
'w_constraint' => sub {
$foo->bar($foo);
},
- 'w_custom_constraint' => sub {
- $foo->boo($foo);
- },
}
);
+use lib '/Users/stevan/Projects/Moose-CPAN/Sub-Compose/Sub-Compose/lib';
+
package Moose::Meta::TypeConstraint;
use strict;
use Carp 'confess';
use Scalar::Util 'blessed';
+use Sub::Compose::Composer;
+
our $VERSION = '0.06';
__PACKAGE__->meta->add_attribute('name' => (reader => 'name' ));
my @parents = map { $_->constraint } $self->_collect_all_parents;
# then we compile them to run without
# having to recurse as we did before
- $self->_compiled_type_constraint(subname $self->name => sub {
- local $_ = $_[0];
- foreach my $parent (@parents) {
- return undef unless $parent->($_[0]);
- }
- return undef unless $check->($_[0]);
- 1;
- });
+
+ my $composer = Sub::Compose::Composer->new(@parents, $check);
+ my $str = $composer->conjoin_code_string(
+ prefix => 'local $_ = $_[0]',
+ around => [ '(', ')'],
+ postfix => ' || undef',
+ );
+ #warn "Compiling " . $self->name . " from\n" . $str . "\n\n";
+ my $code = eval $str;
+ confess "Something went wrong when evaling : \n $str \n\n $@" if $@;
+ $self->_compiled_type_constraint(subname $self->name => $code);
+
+ #$self->_compiled_type_constraint(subname $self->name => sub {
+ # local $_ = $_[0];
+ # foreach my $parent (@parents) {
+ # return undef unless $parent->($_[0]);
+ # }
+ # return undef unless $check->($_[0]);
+ # 1;
+ #});
}
else {
# NOTE:
# blessed(qr/.../) returns true,.. how odd
-subtype 'Object' => as 'Ref' => where { blessed($_) && blessed($_) ne 'Regexp' };
+subtype 'Object' => as 'Ref' => where { Scalar::Util::blessed($_) && Scalar::Util::blessed($_) ne 'Regexp' };
subtype 'Role' => as 'Object' => where { $_->can('does') };