Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 50856
Status: rejected
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.92
Fixed in: (no value)



Subject: "Str" TypeConstraint does not allow string overloaded objects
The "Str" type constraint will not allow string overloaded objects. This is a problem as string overloading can be used to hide from the user that the scalar in question it an object, the user won't know otherwise until their Moose object throws a type violation. For example, a function may document that it returns a URI string which is actually a URI object. Class::DBI documents it returns column names but returns string overload column objects. This becomes a compatibility problem when a function which formerly returned a string starts returning a string overloaded object to maintain compatibility. A Moose object with a Str type would break that compatibility. I've worked around it by defining a type like so: subtype 'NotEmptyStr' => as 'Defined', => where sub { return if ref($_) and !overload::Overloaded($_, q[""]); return length $_ > 0; }; Here's a simple example using URI as a string overloaded object. { package Foo; use URI; use Moose; has string => ( is => 'rw', isa => 'Str', ); Foo->new->string("foo"); Foo->new->string(URI->new); }
Michael, This is actually something which has been suggested and rejected before. The biggest objection is that Perl's overloading mechanism sucks and all the edge cases and gotchas would only serve to make Moose more fragile, which is not something we want to do. So while your use case is well reasoned and valid, the Moose development team isn't ready to implement this directly in core right now. This is not to say it will never happen, in fact there exists a MooseX:: module to handle this on CPAN (see MooseX::Types::Moose::Overload). This actually is the preferred way to vet new Moose features (see Moose::Manual::Contributing). I suggest you look into using this and possibly improving on it if it does not meet your needs. If you would like to debate this further, feel free to start a thread on the mailing list or stop by #moose-dev. And of course you are always invited to create a topic branch and experiment with an implementation if you want. - Stevan