From: Dave Rolsky Date: Fri, 15 Apr 2011 15:40:04 +0000 (-0500) Subject: Add inlining code for Role constraint class X-Git-Tag: 2.0100~69 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=089455fca7782f2ce50870f026f9e1bdbec8aa85;p=gitmo%2FMoose.git Add inlining code for Role constraint class --- diff --git a/lib/Moose/Meta/TypeConstraint/Role.pm b/lib/Moose/Meta/TypeConstraint/Role.pm index 51951b1..5544b6d 100644 --- a/lib/Moose/Meta/TypeConstraint/Role.pm +++ b/lib/Moose/Meta/TypeConstraint/Role.pm @@ -4,6 +4,7 @@ use strict; use warnings; use metaclass; +use B; use Scalar::Util 'blessed'; use Moose::Util::TypeConstraints (); @@ -13,6 +14,14 @@ __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 ) = @_; @@ -21,6 +30,8 @@ sub new { 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;