use strict;
use warnings;
-use Scalar::Util qw( blessed reftype );
+use Scalar::Util qw( blessed looks_like_number reftype );
sub type { goto &Moose::Util::TypeConstraints::type }
sub subtype { goto &Moose::Util::TypeConstraints::subtype }
subtype 'Value'
=> as 'Defined'
=> where { !ref($_) }
- => optimize_as
- \&Moose::Util::TypeConstraints::OptimizedConstraints::Value;
+ => optimize_as \&_Value;
subtype 'Ref'
=> as 'Defined'
=> where { ref($_) }
- => optimize_as
- \&Moose::Util::TypeConstraints::OptimizedConstraints::Ref;
+ => optimize_as \&_Ref;
subtype 'Str'
=> as 'Value'
=> where { ref(\$_) eq 'SCALAR' }
- => optimize_as
- \&Moose::Util::TypeConstraints::OptimizedConstraints::Str;
+ => optimize_as \&_Str;
subtype 'Num'
=> as 'Str'
=> where { Scalar::Util::looks_like_number($_) }
- => optimize_as
- \&Moose::Util::TypeConstraints::OptimizedConstraints::Num;
+ => optimize_as \&_Num;
subtype 'Int'
=> as 'Num'
=> where { "$_" =~ /^-?[0-9]+$/ }
- => optimize_as
- \&Moose::Util::TypeConstraints::OptimizedConstraints::Int;
+ => optimize_as \&_Int;
subtype 'CodeRef'
=> as 'Ref'
=> where { ref($_) eq 'CODE' }
- => optimize_as
- \&Moose::Util::TypeConstraints::OptimizedConstraints::CodeRef;
+ => optimize_as \&_CodeRef;
subtype 'RegexpRef'
=> as 'Ref'
- => where( \&Moose::Util::TypeConstraints::OptimizedConstraints::RegexpRef )
- => optimize_as
- \&Moose::Util::TypeConstraints::OptimizedConstraints::RegexpRef;
+ => where( \&_RegexpRef )
+ => optimize_as \&_RegexpRef;
subtype 'GlobRef'
=> as 'Ref'
=> where { ref($_) eq 'GLOB' }
- => optimize_as
- \&Moose::Util::TypeConstraints::OptimizedConstraints::GlobRef;
+ => optimize_as \&_GlobRef;
# NOTE: scalar filehandles are GLOB refs, but a GLOB ref is not always a
# filehandle
=> where {
Scalar::Util::openhandle($_) || ( blessed($_) && $_->isa("IO::Handle") );
}
- => optimize_as
- \&Moose::Util::TypeConstraints::OptimizedConstraints::FileHandle;
+ => optimize_as \&_FileHandle;
subtype 'Object'
=> as 'Ref'
=> where { blessed($_) }
- => optimize_as
- \&Moose::Util::TypeConstraints::OptimizedConstraints::Object;
+ => optimize_as \&_Object;
# This type is deprecated.
subtype 'Role'
=> as 'Object'
=> where { $_->can('does') }
- => optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Role;
+ => optimize_as \&_Role;
subtype 'ClassName'
=> as 'Str'
=> where { Class::MOP::is_class_loaded($_) }
- => optimize_as
- \&Moose::Util::TypeConstraints::OptimizedConstraints::ClassName;
+ => optimize_as \&_ClassName;
subtype 'RoleName'
=> as 'ClassName'
=> where {
(Class::MOP::class_of($_) || return)->isa('Moose::Meta::Role');
}
- => optimize_as
- \&Moose::Util::TypeConstraints::OptimizedConstraints::RoleName;
+ => optimize_as \&_RoleName;
$registry->add_type_constraint(
Moose::Meta::TypeConstraint::Parameterizable->new(
parent =>
Moose::Util::TypeConstraints::find_type_constraint('Ref'),
constraint => sub { ref($_) eq 'SCALAR' || ref($_) eq 'REF' },
- optimized =>
- \&Moose::Util::TypeConstraints::OptimizedConstraints::ScalarRef,
+ optimized => \&_ScalarRef,
constraint_generator => sub {
my $type_parameter = shift;
my $check = $type_parameter->_compiled_type_constraint;
parent =>
Moose::Util::TypeConstraints::find_type_constraint('Ref'),
constraint => sub { ref($_) eq 'ARRAY' },
- optimized =>
- \&Moose::Util::TypeConstraints::OptimizedConstraints::ArrayRef,
+ optimized => \&_ArrayRef,
constraint_generator => sub {
my $type_parameter = shift;
my $check = $type_parameter->_compiled_type_constraint;
parent =>
Moose::Util::TypeConstraints::find_type_constraint('Ref'),
constraint => sub { ref($_) eq 'HASH' },
- optimized =>
- \&Moose::Util::TypeConstraints::OptimizedConstraints::HashRef,
+ optimized => \&_HashRef,
constraint_generator => sub {
my $type_parameter = shift;
my $check = $type_parameter->_compiled_type_constraint;
);
}
+sub _Value { defined($_[0]) && !ref($_[0]) }
+
+sub _Ref { ref($_[0]) }
+
+# We might need to use a temporary here to flatten LVALUEs, for instance as in
+# Str(substr($_,0,255)).
+sub _Str {
+ defined($_[0])
+ && ( ref(\ $_[0] ) eq 'SCALAR'
+ || ref(\(my $value = $_[0])) eq 'SCALAR')
+}
+
+sub _Num { !ref($_[0]) && looks_like_number($_[0]) }
+
+# using a temporary here because regex matching promotes an IV to a PV,
+# and that confuses some things (like JSON.pm)
+sub _Int {
+ my $value = $_[0];
+ defined($value) && !ref($value) && $value =~ /\A-?[0-9]+\z/
+}
+
+sub _ScalarRef { ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' }
+sub _ArrayRef { ref($_[0]) eq 'ARRAY' }
+sub _HashRef { ref($_[0]) eq 'HASH' }
+sub _CodeRef { ref($_[0]) eq 'CODE' }
+sub _GlobRef { ref($_[0]) eq 'GLOB' }
+
+# RegexpRef is implemented in Moose.xs
+
+sub _FileHandle {
+ ref( $_[0] ) eq 'GLOB' && Scalar::Util::openhandle( $_[0] )
+ or blessed( $_[0] ) && $_[0]->isa("IO::Handle");
+}
+
+sub _Object { blessed($_[0]) }
+
+sub _Role {
+ Moose::Deprecated::deprecated(
+ feature => 'Role type',
+ message =>
+ 'The Role type has been deprecated. Maybe you meant to create a RoleName type? This type be will be removed in Moose 2.0200.'
+ );
+ blessed( $_[0] ) && $_[0]->can('does');
+}
+
+sub _ClassName {
+ return Class::MOP::is_class_loaded( $_[0] );
+}
+
+sub _RoleName {
+ ClassName( $_[0] )
+ && ( Class::MOP::class_of( $_[0] ) || return )
+ ->isa('Moose::Meta::Role');
+}
+
1;
+++ /dev/null
-package Moose::Util::TypeConstraints::OptimizedConstraints;
-
-use strict;
-use warnings;
-
-use Class::MOP;
-use Moose::Deprecated;
-use Scalar::Util 'blessed', 'looks_like_number';
-
-sub Value { defined($_[0]) && !ref($_[0]) }
-
-sub Ref { ref($_[0]) }
-
-# We might need to use a temporary here to flatten LVALUEs, for instance as in
-# Str(substr($_,0,255)).
-sub Str {
- defined($_[0])
- && ( ref(\ $_[0] ) eq 'SCALAR'
- || ref(\(my $value = $_[0])) eq 'SCALAR')
-}
-
-sub Num { !ref($_[0]) && looks_like_number($_[0]) }
-
-# using a temporary here because regex matching promotes an IV to a PV,
-# and that confuses some things (like JSON.pm)
-sub Int {
- my $value = $_[0];
- defined($value) && !ref($value) && $value =~ /\A-?[0-9]+\z/
-}
-
-sub ScalarRef { ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' }
-sub ArrayRef { ref($_[0]) eq 'ARRAY' }
-sub HashRef { ref($_[0]) eq 'HASH' }
-sub CodeRef { ref($_[0]) eq 'CODE' }
-sub GlobRef { ref($_[0]) eq 'GLOB' }
-
-# RegexpRef is implemented in Moose.xs
-
-sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") }
-
-sub Object { blessed($_[0]) }
-
-sub Role {
- Moose::Deprecated::deprecated(
- feature => 'Role type',
- message =>
- 'The Role type has been deprecated. Maybe you meant to create a RoleName type? This type be will be removed in Moose 2.0200.'
- );
- blessed( $_[0] ) && $_[0]->can('does');
-}
-
-sub ClassName {
- return Class::MOP::is_class_loaded( $_[0] );
-}
-
-sub RoleName {
- ClassName($_[0])
- && (Class::MOP::class_of($_[0]) || return)->isa('Moose::Meta::Role')
-}
-
-# NOTE:
-# we have XS versions too, ...
-# 04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz
-# 04:09 <@konobi> or utilxs.tar.gz iirc
-
-1;
-
-__END__
-
-=pod
-
-=head1 NAME
-
-Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
-bodies for various moose types
-
-=head1 DESCRIPTION
-
-This file contains the hand optimized versions of Moose type constraints,
-no user serviceable parts inside.
-
-=head1 FUNCTIONS
-
-=over 4
-
-=item C<Value>
-
-=item C<Ref>
-
-=item C<Str>
-
-=item C<Num>
-
-=item C<Int>
-
-=item C<ScalarRef>
-
-=item C<ArrayRef>
-
-=item C<HashRef>
-
-=item C<CodeRef>
-
-=item C<RegexpRef>
-
-=item C<GlobRef>
-
-=item C<FileHandle>
-
-=item C<Object>
-
-=item C<Role>
-
-=item C<ClassName>
-
-=item C<RoleName>
-
-=back
-
-=head1 BUGS
-
-See L<Moose/BUGS> for details on reporting bugs.
-
-=cut