Subject: | Mouse creates an implied type |
If you use an undeclared type and then try to create a subtype with the
same name, Mouse squeaks that the type already exists.
{
package Foo;
use Mouse;
has bar =>
is => 'rw',
isa => 'Positive_Int'
;
}
{
package My::Types;
use Mouse::Util::TypeConstraints;
subtype 'Positive_Int' => (
as 'Int',
where { $_ >= 0 },
);
}
__END__
The type constraint 'Positive_Int' has already been created in
Mouse::Util::TypeConstraints and cannot be created again in My::Types at
/Users/schwern/tmp/test.plx line 25
Moose does not have a problem with this.
I discovered this when I accidentally used a subtype before loading my
custom Types module. The load order was subtle, so it wasn't
immediately obvious what was happening. The error message saying that
the constraint had been created inside TypeConstraints was very puzzling
leading me to believe I'd somehow recreated an undocumented internal
Mouse type.