use Moose::Meta::Class;
use Moose::Meta::Attribute;
use Moose::Meta::TypeConstraint;
+use Moose::Meta::TypeCoercion;
use Moose::Object;
use Moose::Util::TypeConstraints;
}
else {
# otherwise assume it is a constraint
- my $constraint = Moose::Util::TypeConstraints::find_type_constraint($options{isa});
+ my $constraint = find_type_constraint($options{isa});
# if the constraing it not found ....
unless (defined $constraint) {
# assume it is a foreign class, and make
my $constraint = Moose::Util::TypeConstraints::find_type_constraint($constraint_name)->_compiled_type_constraint;
(defined $constraint)
|| confess "Could not find the type constraint ($constraint_name)";
- push @coercions => [ $constraint, $action ];
+ push @coercions => [ $constraint, $action ];
}
$self->_compiled_type_coercion(sub {
my $thing = shift;
use warnings;
use Carp 'confess';
-use Sub::Name 'subname';
use Scalar::Util 'blessed';
our $VERSION = '0.02';
sub import {
shift;
my $pkg = shift || caller();
- return if $pkg eq ':no_export';
no strict 'refs';
- foreach my $export (qw(type subtype as where coerce from via)) {
+ foreach my $export (qw(type subtype as where coerce from via find_type_constraint)) {
*{"${pkg}::${export}"} = \&{"${export}"};
}
}
my %TYPES;
sub find_type_constraint { $TYPES{$_[0]} }
- sub create_type_constraint {
+ sub _create_type_constraint {
my ($name, $parent, $check) = @_;
(!exists $TYPES{$name})
|| confess "The type constraint '$name' has already been created"
if defined $name;
- $parent = find_type_constraint($parent) if defined $parent;
+ $parent = $TYPES{$parent} if defined $parent;
my $constraint = Moose::Meta::TypeConstraint->new(
name => $name || '__ANON__',
parent => $parent,
return $constraint;
}
- sub install_type_coercions {
+ sub _install_type_coercions {
my ($type_name, $coercion_map) = @_;
- my $type = find_type_constraint($type_name);
+ my $type = $TYPES{$type_name};
(!$type->has_coercion)
|| confess "The type coercion for '$type_name' has already been registered";
my $type_coercion = Moose::Meta::TypeCoercion->new(
}
}
+# type constructors
sub type ($$) {
my ($name, $check) = @_;
- create_type_constraint($name, undef, $check);
+ _create_type_constraint($name, undef, $check);
}
sub subtype ($$;$) {
unshift @_ => undef if scalar @_ == 2;
- create_type_constraint(@_);
+ _create_type_constraint(@_);
}
sub coerce ($@) {
my ($type_name, @coercion_map) = @_;
- install_type_coercions($type_name, \@coercion_map);
+ _install_type_coercions($type_name, \@coercion_map);
}
sub as ($) { $_[0] }
=item B<find_type_constraint ($type_name)>
-=item B<create_type_constraint ($type_name, $type_constraint)>
+=item B<_create_type_constraint ($type_name, $type_constraint)>
-=item B<install_type_coercions>
+=item B<_install_type_coercions>
=item B<export_type_contstraints_as_functions>
=> as Natural
=> where { $_ < 10 };
-Moose::Util::TypeConstraints::export_type_contstraints_as_functions();
+Moose::Util::TypeConstraints->export_type_contstraints_as_functions();
is(Num(5), 5, '... this is a Num');
ok(!defined(Num('Foo')), '... this is not a Num');
};
::ok(!$@, '... successfully exported &subtype to Foo package');
- Moose::Util::TypeConstraints::export_type_contstraints_as_functions();
+ Moose::Util::TypeConstraints->export_type_contstraints_as_functions();
::ok(MyRef({}), '... Ref worked correctly');
::ok(MyArrayRef([]), '... ArrayRef worked correctly');
my $SCALAR_REF = \(my $var);
-Moose::Util::TypeConstraints::export_type_contstraints_as_functions();
+Moose::Util::TypeConstraints->export_type_contstraints_as_functions();
ok(defined Any(0), '... Any accepts anything');
ok(defined Any(100), '... Any accepts anything');
use Test::Exception;
BEGIN {
- use_ok('Moose::Util::TypeConstraints', (':no_export'));
+ use_ok('Moose::Util::TypeConstraints');
}
foreach my $type_name (qw(
RegexpRef
Object
)) {
- is(Moose::Util::TypeConstraints::find_type_constraint($type_name)->name,
+ is(find_type_constraint($type_name)->name,
$type_name,
'... got the right name for ' . $type_name);
}
\ No newline at end of file
=> from HashRef
=> via { HTTPHeader->new(hash => $_[0]) };
-Moose::Util::TypeConstraints::export_type_contstraints_as_functions();
+Moose::Util::TypeConstraints->export_type_contstraints_as_functions();
my $header = HTTPHeader->new();
isa_ok($header, 'HTTPHeader');
ok(!Header([]), '... this did not pass the type test');
ok(!Header({}), '... this did not pass the type test');
-my $coercion = Moose::Util::TypeConstraints::find_type_constraint('Header')->coercion;
+my $coercion = find_type_constraint('Header')->coercion;
isa_ok($coercion, 'Moose::Meta::TypeCoercion');
{