From: Yuval Kogman Date: Mon, 7 Jan 2008 23:52:44 +0000 (+0000) Subject: HATE SVK!!! missing file for the typeconstraint refac X-Git-Tag: 0_35~19^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5d2f0933043354c4cf497f894abc19d6e8f3751c;p=gitmo%2FMoose.git HATE SVK!!! missing file for the typeconstraint refac --- diff --git a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm new file mode 100644 index 0000000..6999a33 --- /dev/null +++ b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm @@ -0,0 +1,83 @@ +#!/usr/bin/perl + +package Moose::Util::TypeConstraints::OptimizedConstraints; + +use strict; +use warnings; + +use Scalar::Util qw(blessed looks_like_number); + +sub Value { defined($_[0]) && !ref($_[0]) } + +sub Ref { ref($_[0]) } + +sub Str { defined($_[0]) && !ref($_[0]) } + +sub Num { !ref($_[0]) && looks_like_number($_[0]) } + +sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ } + +sub ScalarRef { ref($_[0]) eq 'SCALAR' } +sub ArrayRef { ref($_[0]) eq 'ARRAY' } +sub HashRef { ref($_[0]) eq 'HASH' } +sub CodeRef { ref($_[0]) eq 'CODE' } +sub RegexpRef { ref($_[0]) eq 'Regexp' } +sub GlobRef { ref($_[0]) eq 'GLOB' } + +sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) } + +sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' } + +sub Role { blessed($_[0]) && $_[0]->can('does') } + + +__PACKAGE__ + +__END__ + +=pod + +=head1 NAME + +Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint +bodies for various moose types + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +This file contains optimized versions of Moose type constraints. + +=head1 FUNCTIONS + +=over 4 + +=item Value + +=item Ref + +=item Str + +=item Num + +=item Int + +=item ScalarRef + +=item ArrayRef + +=item HashRef + +=item CodeRef + +=item RegexpRef + +=item GlobRef + +=item FileHandle + +=item Object + +=item Role + +=back