1 package Moose::Util::TypeConstraints::OptimizedConstraints;
8 use Scalar::Util 'blessed', 'looks_like_number';
10 our $AUTHORITY = 'cpan:STEVAN';
12 sub Value { defined($_[0]) && !ref($_[0]) }
14 sub Ref { ref($_[0]) }
16 # We need to use a temporary here to flatten LVALUEs, for instance as in
17 # Str(substr($_,0,255)).
20 defined($value) && ref(\$value) eq 'SCALAR'
23 sub Num { !ref($_[0]) && looks_like_number($_[0]) }
25 # using a temporary here because regex matching promotes an IV to a PV,
26 # and that confuses some things (like JSON.pm)
29 defined($value) && !ref($value) && $value =~ /^-?[0-9]+$/
32 sub ScalarRef { ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' }
33 sub ArrayRef { ref($_[0]) eq 'ARRAY' }
34 sub HashRef { ref($_[0]) eq 'HASH' }
35 sub CodeRef { ref($_[0]) eq 'CODE' }
36 sub RegexpRef { ref($_[0]) eq 'Regexp' }
37 sub GlobRef { ref($_[0]) eq 'GLOB' }
39 sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") }
41 sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' }
44 Moose::Deprecated::deprecated(
45 feature => 'Role type',
47 'The Role type has been deprecated. Maybe you meant to create a RoleName type?'
49 blessed( $_[0] ) && $_[0]->can('does');
53 return Class::MOP::is_class_loaded( $_[0] );
58 && (Class::MOP::class_of($_[0]) || return)->isa('Moose::Meta::Role')
62 # we have XS versions too, ...
63 # 04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz
64 # 04:09 <@konobi> or utilxs.tar.gz iirc
74 Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
75 bodies for various moose types
79 This file contains the hand optimized versions of Moose type constraints,
80 no user serviceable parts inside.
122 See L<Moose/BUGS> for details on reporting bugs.