X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FTypeConstraint%2FRole.pm;h=5544b6df651ded9b874c1010cded16912d7994e9;hb=477a812e8edd6ee5ebee1a3b7b90cfeac3b2b9f7;hp=a69a074dd84bccaa491ef5e1101965abc3119152;hpb=5ef36adde3d619733607b9f5f1136524a00848df;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/TypeConstraint/Role.pm b/lib/Moose/Meta/TypeConstraint/Role.pm index a69a074..5544b6d 100644 --- a/lib/Moose/Meta/TypeConstraint/Role.pm +++ b/lib/Moose/Meta/TypeConstraint/Role.pm @@ -4,24 +4,35 @@ use strict; use warnings; use metaclass; +use B; use Scalar::Util 'blessed'; use Moose::Util::TypeConstraints (); -our $VERSION = '0.85'; -$VERSION = eval $VERSION; -our $AUTHORITY = 'cpan:STEVAN'; - use base 'Moose::Meta::TypeConstraint'; __PACKAGE__->meta->add_attribute('role' => ( reader => 'role', )); +my $inliner = sub { + my $self = shift; + my $val = shift; + + return + "Moose::Util::does_role( $val, " . B::perlstring( $self->role ) . ')'; +}; + sub new { my ( $class, %args ) = @_; $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object'); - my $self = $class->_new(\%args); + + my $role_name = $args{role}; + $args{constraint} = sub { Moose::Util::does_role( $_[0], $role_name ) }; + + $args{inlined} = $inliner; + + my $self = $class->_new( \%args ); $self->_create_hand_optimized_type_constraint; $self->compile_type_constraint(); @@ -102,14 +113,12 @@ sub create_child_type { 1; +# ABSTRACT: Role/TypeConstraint parallel hierarchy + __END__ =pod -=head1 NAME - -Moose::Meta::TypeConstraint::Role - Role/TypeConstraint parallel hierarchy - =head1 DESCRIPTION This class represents type constraints for a role. @@ -165,21 +174,6 @@ object! =head1 BUGS -All complex software has bugs lurking in it, and this module is no -exception. If you find a bug please either email me, or add the bug -to cpan-RT. - -=head1 AUTHOR - -Yuval Kogman Enothingmuch@cpan.orgE - -=head1 COPYRIGHT AND LICENSE - -Copyright 2006-2009 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. +See L for details on reporting bugs. =cut