Alphabetize author_requires
[gitmo/Moose.git] / lib / Moose / Util / TypeConstraints / OptimizedConstraints.pm
CommitLineData
5d2f0933 1package Moose::Util::TypeConstraints::OptimizedConstraints;
2
3use strict;
4use warnings;
5
e631c7d1 6use Class::MOP;
28412c0b 7use Scalar::Util 'blessed', 'looks_like_number';
8
72643035 9our $VERSION = '1.08';
75b95414 10$VERSION = eval $VERSION;
28412c0b 11our $AUTHORITY = 'cpan:STEVAN';
5d2f0933 12
fd542f49 13sub Value { defined($_[0]) && !ref($_[0]) }
5d2f0933 14
fd542f49 15sub Ref { ref($_[0]) }
5d2f0933 16
74d5a674 17# We need to use a temporary here to flatten LVALUEs, for instance as in
18# Str(substr($_,0,255)).
19sub Str {
20 my $value = $_[0];
21 defined($value) && ref(\$value) eq 'SCALAR'
22}
bc47531e 23
fd542f49 24sub Num { !ref($_[0]) && looks_like_number($_[0]) }
5d2f0933 25
fd542f49 26sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ }
27
150e5142 28sub ScalarRef { ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' }
267f8179 29sub ArrayRef { ref($_[0]) eq 'ARRAY' }
30sub HashRef { ref($_[0]) eq 'HASH' }
31sub CodeRef { ref($_[0]) eq 'CODE' }
32sub RegexpRef { ref($_[0]) eq 'Regexp' }
33sub GlobRef { ref($_[0]) eq 'GLOB' }
fd542f49 34
35sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") }
36
37sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' }
38
0eb7894a 39sub Role {
40 Moose::Deprecated::deprecated(
41 feature => 'Role type',
42 message =>
43 'The Role type has been deprecated. Maybe you meant to create a RoleName type?'
44 );
45 blessed( $_[0] ) && $_[0]->can('does');
46}
fd542f49 47
e151db23 48sub ClassName {
e631c7d1 49 return Class::MOP::is_class_loaded( $_[0] );
e151db23 50}
51
f0cac16f 52sub RoleName {
9df65fdb 53 ClassName($_[0])
54 && (Class::MOP::class_of($_[0]) || return)->isa('Moose::Meta::Role')
f0cac16f 55}
56
fd542f49 57# NOTE:
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
5d2f0933 61
28412c0b 621;
5d2f0933 63
64__END__
65
66=pod
67
68=head1 NAME
69
70Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
71bodies for various moose types
72
5d2f0933 73=head1 DESCRIPTION
74
d03bd989 75This file contains the hand optimized versions of Moose type constraints,
004222dc 76no user serviceable parts inside.
5d2f0933 77
78=head1 FUNCTIONS
79
80=over 4
81
6549b0d1 82=item C<Value>
5d2f0933 83
6549b0d1 84=item C<Ref>
5d2f0933 85
6549b0d1 86=item C<Str>
5d2f0933 87
6549b0d1 88=item C<Num>
5d2f0933 89
6549b0d1 90=item C<Int>
5d2f0933 91
6549b0d1 92=item C<ScalarRef>
5d2f0933 93
6549b0d1 94=item C<ArrayRef>
5d2f0933 95
6549b0d1 96=item C<HashRef>
5d2f0933 97
6549b0d1 98=item C<CodeRef>
5d2f0933 99
6549b0d1 100=item C<RegexpRef>
5d2f0933 101
6549b0d1 102=item C<GlobRef>
5d2f0933 103
6549b0d1 104=item C<FileHandle>
5d2f0933 105
6549b0d1 106=item C<Object>
5d2f0933 107
6549b0d1 108=item C<Role>
5d2f0933 109
6549b0d1 110=item C<ClassName>
e151db23 111
c8a26288 112=item C<RoleName>
113
5d2f0933 114=back
28412c0b 115
116=head1 BUGS
117
d4048ef3 118See L<Moose/BUGS> for details on reporting bugs.
28412c0b 119
120=head1 AUTHOR
121
122Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
123
124=head1 COPYRIGHT AND LICENSE
125
2840a3b2 126Copyright 2007-2009 by Infinity Interactive, Inc.
28412c0b 127
128L<http://www.iinteractive.com>
129
130This library is free software; you can redistribute it and/or modify
131it under the same terms as Perl itself.
132
133=cut