Merge 'Moose-moosex_compile_support' into 'trunk'
[gitmo/Moose.git] / lib / Moose / Util / TypeConstraints / OptimizedConstraints.pm
CommitLineData
5d2f0933 1#!/usr/bin/perl
2
616f0741 3=begin comment
4
504:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz
604:09 <@konobi> or utilxs.tar.gz iirc
7
8=cut
9
5d2f0933 10package Moose::Util::TypeConstraints::OptimizedConstraints;
11
12use strict;
13use warnings;
14
15use Scalar::Util qw(blessed looks_like_number);
16
17sub Value { defined($_[0]) && !ref($_[0]) }
18
19sub Ref { ref($_[0]) }
20
21sub Str { defined($_[0]) && !ref($_[0]) }
22
23sub Num { !ref($_[0]) && looks_like_number($_[0]) }
24
25sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ }
26
42bc21a4 27{
28 no warnings 'uninitialized';
29 sub ScalarRef { ref($_[0]) eq 'SCALAR' }
30 sub ArrayRef { ref($_[0]) eq 'ARRAY' }
31 sub HashRef { ref($_[0]) eq 'HASH' }
32 sub CodeRef { ref($_[0]) eq 'CODE' }
33 sub RegexpRef { ref($_[0]) eq 'Regexp' }
34 sub GlobRef { ref($_[0]) eq 'GLOB' }
35}
5d2f0933 36
37sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) }
38
39sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' }
40
41sub Role { blessed($_[0]) && $_[0]->can('does') }
42
43
44__PACKAGE__
45
46__END__
47
48=pod
49
50=head1 NAME
51
52Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint
53bodies for various moose types
54
55=head1 SYNOPSIS
56
57=head1 DESCRIPTION
58
59This file contains optimized versions of Moose type constraints.
60
61=head1 FUNCTIONS
62
63=over 4
64
65=item Value
66
67=item Ref
68
69=item Str
70
71=item Num
72
73=item Int
74
75=item ScalarRef
76
77=item ArrayRef
78
79=item HashRef
80
81=item CodeRef
82
83=item RegexpRef
84
85=item GlobRef
86
87=item FileHandle
88
89=item Object
90
91=item Role
92
93=back