X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint%2FClass.pm;h=8e99e4527589703b802cb110bc67745063c1e37a;hb=3975b592007cd8f44368f71cedc60fba86b5a1f2;hp=0de5c7f5ad6c3b8dc740609664d1bfabc81d474f;hpb=aff6aafcfff96c2a91bd044e35010757feae584c;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint/Class.pm b/lib/Moose/Meta/TypeConstraint/Class.pm index 0de5c7f..8e99e45 100644 --- a/lib/Moose/Meta/TypeConstraint/Class.pm +++ b/lib/Moose/Meta/TypeConstraint/Class.pm @@ -4,41 +4,42 @@ use strict; use warnings; use metaclass; +use B; use Scalar::Util 'blessed'; use Moose::Util::TypeConstraints (); -our $VERSION = '1.18'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - use base 'Moose::Meta::TypeConstraint'; __PACKAGE__->meta->add_attribute('class' => ( reader => 'class', )); +my $inliner = sub { + my $self = shift; + my $val = shift; + + return 'Scalar::Util::blessed(' . $val . ')' + . ' && ' . $val . '->isa(' . B::perlstring($self->class) . ')'; +}; + sub new { my ( $class, %args ) = @_; - $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object'); - my $self = $class->_new(\%args); + $args{parent} + = Moose::Util::TypeConstraints::find_type_constraint('Object'); + + my $class_name = $args{class}; + $args{constraint} = sub { $_[0]->isa($class_name) }; + + $args{inlined} = $inliner; + + my $self = $class->_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] ) && blessed( $_[0] ) ne 'Regexp' && $_[0]->isa($class) - } - ); -} - sub parents { my $self = shift; return ( @@ -121,14 +122,12 @@ sub get_message { 1; +# ABSTRACT: Class/TypeConstraint parallel hierarchy + __END__ =pod -=head1 NAME - -Moose::Meta::TypeConstraint::Class - Class/TypeConstraint parallel hierarchy - =head1 DESCRIPTION This class represents type constraints for a class. @@ -192,17 +191,4 @@ with accidentally autovivified type constraints. See L for details on reporting bugs. -=head1 AUTHOR - -Yuval Kogman Enothingmuch@cpan.orgE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006-2010 by Infinity Interactive, Inc. - -L - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - =cut