0.15
* Don't export Mouse's sugar into the package 'main'
+ * Rename Mouse::TypeRegistry to Mouse::Util::TypeConstraints
+
0.14 Sat Dec 20 16:53:05 2008
* POD fix
use Mouse::Meta::Attribute;
use Mouse::Meta::Class;
use Mouse::Object;
-use Mouse::TypeRegistry;
+use Mouse::Util::TypeConstraints;
our @EXPORT = qw(extends has before after around blessed confess with);
if ($constraint) {
$accessor .= 'my $val = ';
if ($should_coerce) {
- $accessor .= 'Mouse::TypeRegistry->typecast_constraints("'.$attribute->associated_class->name.'", $attribute->{find_type_constraint}, $attribute->{type_constraint}, '.$value.');';
+ $accessor .= 'Mouse::Util::TypeConstraints->typecast_constraints("'.$attribute->associated_class->name.'", $attribute->{find_type_constraint}, $attribute->{type_constraint}, '.$value.');';
} else {
$accessor .= $value.';';
}
my @type_constraints = split /\|/, $type_constraint;
my $code;
- my $optimized_constraints = Mouse::TypeRegistry->optimized_constraints;
+ my $optimized_constraints = Mouse::Util::TypeConstraints->optimized_constraints;
if (@type_constraints == 1) {
$code = $optimized_constraints->{$type_constraints[0]} ||
sub { Scalar::Util::blessed($_) && $_->isa($type_constraints[0]) };
sub coerce_constraint { ## my($self, $value) = @_;
my $type = $_[0]->{type_constraint}
or return $_[1];
- return Mouse::TypeRegistry->typecast_constraints($_[0]->associated_class->name, $_[0]->find_type_constraint, $type, $_[1]);
+ return Mouse::Util::TypeConstraints->typecast_constraints($_[0]->associated_class->name, $_[0]->find_type_constraint, $type, $_[1]);
}
sub _canonicalize_handles {
$code .= "if (exists \$args->{'$from'}) {\n";
if ($attr->should_coerce && $attr->type_constraint) {
- $code .= "my \$value = Mouse::TypeRegistry->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{find_type_constraint}, \$attrs[$index]->{type_constraint}, \$args->{'$from'});\n";
+ $code .= "my \$value = Mouse::Util::TypeConstraints->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{find_type_constraint}, \$attrs[$index]->{type_constraint}, \$args->{'$from'});\n";
}
else {
$code .= "my \$value = \$args->{'$from'};\n";
$code .= "my \$value = ";
if ($attr->should_coerce && $attr->type_constraint) {
- $code .= "Mouse::TypeRegistry->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{find_type_constraint}, \$attrs[$index]->{type_constraint}, ";
+ $code .= "Mouse::Util::TypeConstraints->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{find_type_constraint}, \$attrs[$index]->{type_constraint}, ";
}
if ($attr->has_builder) {
-package Mouse::TypeRegistry;
+package Mouse::Util::TypeConstraints;
use strict;
use warnings;
=head1 NAME
-Mouse::TypeRegistry - simple type constraints
+Mouse::Util::TypeConstraints - simple type constraints
=head1 METHODS
use strict;
use warnings;
-require Mouse::TypeRegistry;
+require Mouse::Util::TypeConstraints;
use MouseX::Types::TypeDecorator;
sub import {
}
}
- return Mouse::TypeRegistry->import( callee => $caller );
+ return Mouse::Util::TypeConstraints->import( callee => $caller );
}
sub _import {
use strict;
use warnings;
-BEGIN { require Mouse::TypeRegistry }
+BEGIN { require Mouse::Util::TypeConstraints }
use MouseX::Types;
BEGIN {
- my $builtin_type = +{ map { $_ => $_ } Mouse::TypeRegistry->list_all_builtin_type_constraints };
+ my $builtin_type = +{ map { $_ => $_ } Mouse::Util::TypeConstraints->list_all_builtin_type_constraints };
sub type_storage { $builtin_type }
}
{
package Response;
use Mouse;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
subtype 'HeadersType' => where { defined $_ && eval { $_->isa('Headers') } };
coerce 'HeadersType' =>
{
package Response;
use Mouse;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
subtype 'HeadersType' => as 'Object' => where { defined $_ && eval { $_->isa('Headers') } };
coerce 'HeadersType' =>
{
package Response;
use Mouse;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
subtype 'Headers' => where { defined $_ && eval { $_->isa('Response::Headers') } };
coerce 'Headers' =>
eval {
package Request;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
subtype 'Headers' => where { defined $_ && eval { $_->isa('Request::Headers') } };
};
eval {
package Request;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
coerce 'TooBad' =>
from 'HashRef' => via {
eval {
package Request;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
coerce 'Headers' =>
from 'HashRef' => via {
eval {
package Request;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
coerce 'Headers' =>
from 'HashRefa' => via {
eval {
package Request;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
coerce 'Headers' =>
from 'ArrayRef' => via {
{
package Response;
use Mouse;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
class_type Headers => { class => 't::lib::ClassType_Foo' };
coerce 'Headers' =>
{
package Response;
use Mouse;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
role_type Headers => { role => 'Response::Headers::Role' };
coerce 'Headers' =>
eval {
package Request;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
subtype 'Int' => where { 1};
};
{
package Foo;
use Mouse;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
subtype Baz => where { defined($_) && $_ eq 'Baz' };
coerce Baz => from 'ArrayRef', via { 'Baz' };
has 'bar' => ( is => 'rw', isa => 'Str | Baz | Undef', coerce => 1 );
{
package Bar;
use Mouse;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
subtype 'Type1' => where { defined($_) && $_ eq 'Name' };
coerce 'Type1', from 'Str', via { 'Names' };
{
package Baz;
use Mouse;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
subtype 'Type3' => where { defined($_) && $_ eq 'Name' };
coerce 'Type3', from 'CodeRef', via { 'Name' };
{
package Foo;
use Mouse;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
subtype 'Type1' => as 'Str' => where { blessed($_) };
has str_obj => (