1 package Moose::Util::TypeConstraints::OptimizedConstraints;
7 use Scalar::Util 'blessed', 'looks_like_number';
10 $VERSION = eval $VERSION;
11 our $AUTHORITY = 'cpan:STEVAN';
13 sub Value { defined($_[0]) && !ref($_[0]) }
15 sub Ref { ref($_[0]) }
17 # We need to use a temporary here to flatten LVALUEs, for instance as in
18 # Str(substr($_,0,255)).
21 defined($value) && ref(\$value) eq 'SCALAR'
24 sub Num { !ref($_[0]) && looks_like_number($_[0]) }
26 sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ }
28 sub ScalarRef { ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' }
29 sub ArrayRef { ref($_[0]) eq 'ARRAY' }
30 sub HashRef { ref($_[0]) eq 'HASH' }
31 sub CodeRef { ref($_[0]) eq 'CODE' }
32 sub RegexpRef { ref($_[0]) eq 'Regexp' }
33 sub GlobRef { ref($_[0]) eq 'GLOB' }
35 sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") }
37 sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' }
40 Moose::Deprecated::deprecated(
41 feature => 'Role type',
43 'The Role type has been deprecated. Maybe you meant to create a RoleName type?'
45 blessed( $_[0] ) && $_[0]->can('does');
49 return Class::MOP::is_class_loaded( $_[0] );
54 && (Class::MOP::class_of($_[0]) || return)->isa('Moose::Meta::Role')
58 # we have XS versions too, ...
59 # 04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz
60 # 04:09 <@konobi> or utilxs.tar.gz iirc
70 Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
71 bodies for various moose types
75 This file contains the hand optimized versions of Moose type constraints,
76 no user serviceable parts inside.
118 See L<Moose/BUGS> for details on reporting bugs.
122 Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
124 =head1 COPYRIGHT AND LICENSE
126 Copyright 2007-2009 by Infinity Interactive, Inc.
128 L<http://www.iinteractive.com>
130 This library is free software; you can redistribute it and/or modify
131 it under the same terms as Perl itself.