__PACKAGE__->meta->add_attribute('class' => (
reader => 'class',
+ Class::MOP::_definition_context(),
));
my $inliner = sub {
my $self = shift;
my $val = shift;
- return
- "Scalar::Util::blessed($val) && $val->isa("
- . B::perlstring( $self->class ) . ')';
+ return 'Scalar::Util::blessed(' . $val . ')'
+ . ' && ' . $val . '->isa(' . B::perlstring($self->class) . ')';
};
sub new {
$args{inlined} = $inliner;
- my $self = $class->_new( \%args );
+ my $self = $class->SUPER::new( \%args );
- $self->_create_hand_optimized_type_constraint;
$self->compile_type_constraint();
return $self;
}
-sub _create_hand_optimized_type_constraint {
- my $self = shift;
- my $class = $self->class;
- $self->hand_optimized_type_constraint(
- sub {
- blessed( $_[0] ) && $_[0]->isa($class)
- }
- );
-}
-
sub parents {
my $self = shift;
return (
my $other = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
- return unless defined $other;
+ if (!defined($other)) {
+ if (!ref($type_or_name)) {
+ return $self->class eq $type_or_name;
+ }
+ return;
+ }
+
return unless $other->isa(__PACKAGE__);
return $self->class eq $other->class;
sub is_a_type_of {
my ($self, $type_or_name) = @_;
- my $type = Moose::Util::TypeConstraints::find_type_constraint($type_or_name);
-
- ($self->equals($type) || $self->is_subtype_of($type_or_name));
+ ($self->equals($type_or_name) || $self->is_subtype_of($type_or_name));
}
sub is_subtype_of {
if ( not defined $type ) {
if ( not ref $type_or_name_or_class ) {
# it might be a class
- return 1 if $self->class->isa( $type_or_name_or_class );
+ my $class = $self->class;
+ return 1 if $class ne $type_or_name_or_class
+ && $class->isa( $type_or_name_or_class );
}
return;
}