use strict;
use warnings;
-use Test::More tests => 14;
+use Test::More tests => 13;
{
package Response::Headers;
{
package Response;
use Mouse;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
- subtype 'Headers' => where { defined $_ && eval { $_->isa('Response::Headers') } };
+ type 'Headers' => where { defined $_ && eval { $_->isa('Response::Headers') } };
coerce 'Headers' =>
from 'HashRef' => via {
Response::Headers->new(%{ $_ });
eval {
package Request;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
- subtype 'Headers' => where { defined $_ && eval { $_->isa('Request::Headers') } };
+ type 'Headers' => where { defined $_ && eval { $_->isa('Request::Headers') } };
};
-like $@, qr/The type constraint 'Headers' has already been created, cannot be created again in Request/;
+like $@, qr/The type constraint 'Headers' has already been created in Response and cannot be created again in Request/;
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 {
- Request::Headers->new(%{ $_ });
+ coerce 'Int' =>
+ from 'XXX' => via {
+ 1
},
;
};
-like $@, qr/Could not find the type constraint \(HashRefa\) to coerce from/;
+like $@, qr/Could not find the type constraint \(XXX\) to coerce from/;
eval {
package Request;
- use Mouse::TypeRegistry;
+ use Mouse::Util::TypeConstraints;
coerce 'Headers' =>
from 'ArrayRef' => via {
};
ok !$@;
-eval {
- package Response;
- subtype 'Headers' => where { defined $_ && eval { $_->isa('Response::Headers') } };
-};
-like $@, qr/The type constraint 'Headers' has already been created, cannot be created again in Response/;
-
{
package Request;
use Mouse;
);
}
-
my $req = Request->new(headers => { foo => 'bar' });
isa_ok($req->headers, 'Response::Headers');
is($req->headers->foo, 'bar');
$res->headers({foo => 'yay'});
isa_ok($res->headers, 'Response::Headers');
is($res->headers->foo, 'yay');
+