sub _type {
my $pkg = caller(0);
my($name, %conf) = @_;
- if (my $type = $TYPE{$name}) {
+ if ($TYPE{$name} && $TYPE_SOURCE{$name} ne $pkg) {
Carp::croak "The type constraint '$name' has already been created in $TYPE_SOURCE{$name} and cannot be created again in $pkg";
};
my $constraint = $conf{where} || do { $TYPE{delete $conf{as} || 'Any' } };
sub _subtype {
my $pkg = caller(0);
my($name, %conf) = @_;
- if (my $type = $TYPE{$name}) {
+ if ($TYPE{$name} && $TYPE_SOURCE{$name} ne $pkg) {
Carp::croak "The type constraint '$name' has already been created in $TYPE_SOURCE{$name} and cannot be created again in $pkg";
};
my $constraint = $conf{where} || do { $TYPE{delete $conf{as} || 'Any' } };
eval {
package Response;
- type 'Headers' => where { defined $_ && eval { $_->isa('Response::Headers') } };
+ type 'Headers' => where {
+ eval { $_->isa('Response::Headers') }
+ };
};
-like $@, qr/The type constraint 'Headers' has already been created in Response and cannot be created again in Response/;
+ok(!$@, "You can redefine types in their original package");
{
package Request;