Commit | Line | Data |
5d2f0933 |
1 | #!/usr/bin/perl |
2 | |
616f0741 |
3 | =begin comment |
4 | |
5 | 04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz |
6 | 04:09 <@konobi> or utilxs.tar.gz iirc |
7 | |
8 | =cut |
9 | |
5d2f0933 |
10 | package Moose::Util::TypeConstraints::OptimizedConstraints; |
11 | |
12 | use strict; |
13 | use warnings; |
14 | |
15 | use Scalar::Util qw(blessed looks_like_number); |
16 | |
17 | sub Value { defined($_[0]) && !ref($_[0]) } |
18 | |
19 | sub Ref { ref($_[0]) } |
20 | |
21 | sub Str { defined($_[0]) && !ref($_[0]) } |
22 | |
23 | sub Num { !ref($_[0]) && looks_like_number($_[0]) } |
24 | |
25 | sub 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 | |
37 | sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) } |
38 | |
39 | sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' } |
40 | |
41 | sub Role { blessed($_[0]) && $_[0]->can('does') } |
42 | |
43 | |
44 | __PACKAGE__ |
45 | |
46 | __END__ |
47 | |
48 | =pod |
49 | |
50 | =head1 NAME |
51 | |
52 | Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint |
53 | bodies for various moose types |
54 | |
55 | =head1 SYNOPSIS |
56 | |
57 | =head1 DESCRIPTION |
58 | |
59 | This 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 |