Commit | Line | Data |
---|---|---|
5d2f0933 | 1 | package Moose::Util::TypeConstraints::OptimizedConstraints; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
e631c7d1 | 6 | use Class::MOP; |
28412c0b | 7 | use Scalar::Util 'blessed', 'looks_like_number'; |
8 | ||
8de57178 | 9 | our $VERSION = '0.92'; |
75b95414 | 10 | $VERSION = eval $VERSION; |
28412c0b | 11 | our $AUTHORITY = 'cpan:STEVAN'; |
5d2f0933 | 12 | |
fd542f49 | 13 | sub Value { defined($_[0]) && !ref($_[0]) } |
5d2f0933 | 14 | |
fd542f49 | 15 | sub Ref { ref($_[0]) } |
5d2f0933 | 16 | |
9a221523 | 17 | sub Str { defined($_[0]) && ref(\$_[0]) eq 'SCALAR' } |
bc47531e | 18 | |
fd542f49 | 19 | sub Num { !ref($_[0]) && looks_like_number($_[0]) } |
5d2f0933 | 20 | |
fd542f49 | 21 | sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ } |
22 | ||
267f8179 | 23 | sub ScalarRef { ref($_[0]) eq 'SCALAR' } |
24 | sub ArrayRef { ref($_[0]) eq 'ARRAY' } | |
25 | sub HashRef { ref($_[0]) eq 'HASH' } | |
26 | sub CodeRef { ref($_[0]) eq 'CODE' } | |
27 | sub RegexpRef { ref($_[0]) eq 'Regexp' } | |
28 | sub GlobRef { ref($_[0]) eq 'GLOB' } | |
fd542f49 | 29 | |
30 | sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or blessed($_[0]) && $_[0]->isa("IO::Handle") } | |
31 | ||
32 | sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' } | |
33 | ||
4831e2de | 34 | sub Role { Carp::cluck('The Role type is deprecated.'); blessed($_[0]) && $_[0]->can('does') } |
fd542f49 | 35 | |
e151db23 | 36 | sub ClassName { |
e631c7d1 | 37 | return Class::MOP::is_class_loaded( $_[0] ); |
e151db23 | 38 | } |
39 | ||
f0cac16f | 40 | sub RoleName { |
9df65fdb | 41 | ClassName($_[0]) |
42 | && (Class::MOP::class_of($_[0]) || return)->isa('Moose::Meta::Role') | |
f0cac16f | 43 | } |
44 | ||
fd542f49 | 45 | # NOTE: |
46 | # we have XS versions too, ... | |
47 | # 04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz | |
48 | # 04:09 <@konobi> or utilxs.tar.gz iirc | |
5d2f0933 | 49 | |
28412c0b | 50 | 1; |
5d2f0933 | 51 | |
52 | __END__ | |
53 | ||
54 | =pod | |
55 | ||
56 | =head1 NAME | |
57 | ||
58 | Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint | |
59 | bodies for various moose types | |
60 | ||
5d2f0933 | 61 | =head1 DESCRIPTION |
62 | ||
d03bd989 | 63 | This file contains the hand optimized versions of Moose type constraints, |
004222dc | 64 | no user serviceable parts inside. |
5d2f0933 | 65 | |
66 | =head1 FUNCTIONS | |
67 | ||
68 | =over 4 | |
69 | ||
6549b0d1 | 70 | =item C<Value> |
5d2f0933 | 71 | |
6549b0d1 | 72 | =item C<Ref> |
5d2f0933 | 73 | |
6549b0d1 | 74 | =item C<Str> |
5d2f0933 | 75 | |
6549b0d1 | 76 | =item C<Num> |
5d2f0933 | 77 | |
6549b0d1 | 78 | =item C<Int> |
5d2f0933 | 79 | |
6549b0d1 | 80 | =item C<ScalarRef> |
5d2f0933 | 81 | |
6549b0d1 | 82 | =item C<ArrayRef> |
5d2f0933 | 83 | |
6549b0d1 | 84 | =item C<HashRef> |
5d2f0933 | 85 | |
6549b0d1 | 86 | =item C<CodeRef> |
5d2f0933 | 87 | |
6549b0d1 | 88 | =item C<RegexpRef> |
5d2f0933 | 89 | |
6549b0d1 | 90 | =item C<GlobRef> |
5d2f0933 | 91 | |
6549b0d1 | 92 | =item C<FileHandle> |
5d2f0933 | 93 | |
6549b0d1 | 94 | =item C<Object> |
5d2f0933 | 95 | |
6549b0d1 | 96 | =item C<Role> |
5d2f0933 | 97 | |
6549b0d1 | 98 | =item C<ClassName> |
e151db23 | 99 | |
c8a26288 | 100 | =item C<RoleName> |
101 | ||
5d2f0933 | 102 | =back |
28412c0b | 103 | |
104 | =head1 BUGS | |
105 | ||
d03bd989 | 106 | All complex software has bugs lurking in it, and this module is no |
28412c0b | 107 | exception. If you find a bug please either email me, or add the bug |
108 | to cpan-RT. | |
109 | ||
110 | =head1 AUTHOR | |
111 | ||
112 | Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt> | |
113 | ||
114 | =head1 COPYRIGHT AND LICENSE | |
115 | ||
2840a3b2 | 116 | Copyright 2007-2009 by Infinity Interactive, Inc. |
28412c0b | 117 | |
118 | L<http://www.iinteractive.com> | |
119 | ||
120 | This library is free software; you can redistribute it and/or modify | |
121 | it under the same terms as Perl itself. | |
122 | ||
123 | =cut |