From: Jesse Luehrs Date: Sat, 17 Apr 2010 02:00:09 +0000 (-0500) Subject: finish up inlining all of the basic non-parameterized types X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7fd59496af3b3971fd1513b5b79a5332ea29d53b;p=gitmo%2FMoose.git finish up inlining all of the basic non-parameterized types --- diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 0698322..af986a2 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -662,7 +662,7 @@ subtype 'Bool' => as 'Item' => where { !defined($_) || $_ eq "" || "$_" eq '1' || "$_" eq '0' }; subtype 'Value' => as 'Defined' => where { !ref($_) } => - inline_as Moose::Util::TypeConstraints::OptimizedConstraints::InlineValue(); + inline_as Moose::Util::TypeConstraints::OptimizedConstraints::InlineValue; subtype 'Ref' => as 'Defined' => where { ref($_) } => inline_as Moose::Util::TypeConstraints::OptimizedConstraints::InlineRef; @@ -675,29 +675,29 @@ subtype 'Num' => as 'Str' => inline_as Moose::Util::TypeConstraints::OptimizedConstraints::InlineNum; subtype 'Int' => as 'Num' => where { "$_" =~ /^-?[0-9]+$/ } => - optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Int; + inline_as Moose::Util::TypeConstraints::OptimizedConstraints::InlineInt; subtype 'CodeRef' => as 'Ref' => where { ref($_) eq 'CODE' } => - optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::CodeRef; + inline_as Moose::Util::TypeConstraints::OptimizedConstraints::InlineCodeRef; subtype 'RegexpRef' => as 'Ref' => where { ref($_) eq 'Regexp' } => - optimize_as - \&Moose::Util::TypeConstraints::OptimizedConstraints::RegexpRef; + inline_as + Moose::Util::TypeConstraints::OptimizedConstraints::InlineRegexpRef; subtype 'GlobRef' => as 'Ref' => where { ref($_) eq 'GLOB' } => - optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::GlobRef; + inline_as Moose::Util::TypeConstraints::OptimizedConstraints::InlineGlobRef; # NOTE: # scalar filehandles are GLOB refs, # but a GLOB ref is not always a filehandle subtype 'FileHandle' => as 'GlobRef' => where { Scalar::Util::openhandle($_) || ( blessed($_) && $_->isa("IO::Handle") ); -} => optimize_as - \&Moose::Util::TypeConstraints::OptimizedConstraints::FileHandle; +} => inline_as + Moose::Util::TypeConstraints::OptimizedConstraints::InlineFileHandle; # NOTE: # blessed(qr/.../) returns true,.. how odd subtype 'Object' => as 'Ref' => where { blessed($_) && blessed($_) ne 'Regexp' } => - optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Object; + inline_as Moose::Util::TypeConstraints::OptimizedConstraints::InlineObject; # This type is deprecated. subtype 'Role' => as 'Object' => where { $_->can('does') } => @@ -706,13 +706,13 @@ subtype 'Role' => as 'Object' => where { $_->can('does') } => my $_class_name_checker = sub { }; subtype 'ClassName' => as 'Str' => - where { Class::MOP::is_class_loaded($_) } => optimize_as - \&Moose::Util::TypeConstraints::OptimizedConstraints::ClassName; + where { Class::MOP::is_class_loaded($_) } => inline_as + Moose::Util::TypeConstraints::OptimizedConstraints::InlineClassName; subtype 'RoleName' => as 'ClassName' => where { (Class::MOP::class_of($_) || return)->isa('Moose::Meta::Role'); -} => optimize_as - \&Moose::Util::TypeConstraints::OptimizedConstraints::RoleName; +} => inline_as + Moose::Util::TypeConstraints::OptimizedConstraints::InlineRoleName; ## -------------------------------------------------------- # parameterizable types ... diff --git a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm index ab88d82..9c632e1 100644 --- a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm +++ b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm @@ -4,7 +4,6 @@ use strict; use warnings; use Class::MOP; -use Scalar::Util 'blessed', 'looks_like_number'; our $VERSION = '1.01'; $VERSION = eval $VERSION; @@ -27,7 +26,17 @@ sub InlineNum { q{!ref($_[0]) && Scalar::Util::looks_like_number($_[0])} } -sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ } +sub InlineInt { + q{defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/} +} + +# XXX: not used yet +sub InlineScalarRef { q{ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF'} } +sub InlineArrayRef { q{ref($_[0]) eq 'ARRAY'} } +sub InlineHashRef { q{ref($_[0]) eq 'HASH'} } +sub InlineCodeRef { q{ref($_[0]) eq 'CODE'} } +sub InlineRegexpRef { q{ref($_[0]) eq 'Regexp'} } +sub InlineGlobRef { q{ref($_[0]) eq 'GLOB'} } sub ScalarRef { ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' } sub ArrayRef { ref($_[0]) eq 'ARRAY' } @@ -36,19 +45,22 @@ sub CodeRef { ref($_[0]) eq 'CODE' } sub RegexpRef { ref($_[0]) eq 'Regexp' } sub GlobRef { ref($_[0]) eq 'GLOB' } -sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") } +sub InlineFileHandle { + q{(ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]))} + . q{ or (Scalar::Util::blessed($_[0]) && $_[0]->isa('IO::Handle'))} +} -sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' } +sub InlineObject { + q{Scalar::Util::blessed($_[0]) && Scalar::Util::blessed($_[0]) ne 'Regexp'} +} -sub Role { Carp::cluck('The Role type is deprecated.'); blessed($_[0]) && $_[0]->can('does') } +sub Role { Carp::cluck('The Role type is deprecated.'); Scalar::Util::blessed($_[0]) && $_[0]->can('does') } -sub ClassName { - return Class::MOP::is_class_loaded( $_[0] ); -} +sub InlineClassName { q{Class::MOP::is_class_loaded($_[0])} } -sub RoleName { - ClassName($_[0]) - && (Class::MOP::class_of($_[0]) || return)->isa('Moose::Meta::Role') +sub InlineRoleName { + InlineClassName() + . q{ && (Class::MOP::class_of($_[0]) || return)->isa('Moose::Meta::Role')} } # NOTE: