MooseX::Types::Moose::Overload - Deal with overload, in the overloaded sense ;)
This module is like MooseX::Types::Moose except it will transparently handle overloaded objects.
All you have to do is use it,
and then add
coerce => 1 to the attributes you wish to enable it on.
It will then stringify all objects that support the stringifiy method.
This works in the style of overload,
forcing Moose to just do you want.
Something that stringifies to a string should simply work when the attribute isa Str,
This only attaches a coercion to subtypes of "Value", and it only coerces from "Objects", and only executes on Objects that support stringification via overload.
use MooseX::Types::Moose::Overload 'Str'; use MooseX::Types::Moose::Overload qw/Str Int/; use MooseX::Types::Moose::Overload ':all'; ## Now takes a URI object, or HTTP::Element, and of course a plain string. has 'uri' => ( isa => Str, is => 'rw', coerce => 1 );
Overloading in perl is a nasty hack.
There is a subset of overload which is even more of a nasty hack. Unoverloading types which are implimented in obscure hard-to-detect fashion is not supported. I will evaluate patches that support said method for completeness. I do not want to go into detail for fear someone will accidently learn it -- and I don't know of any modules on CPAN that use it. It is very probably a moot case.
As just said, this does not supply an overload for Object. So it does not support stringification that returns references or any other suprememly goofy shit. "$foo"->bar should not be a valid API unless you want to die in the face.
<me at evancarroll.com>
Please report any bugs or feature requests to
bug-moosex-types-overload at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Types-Moose-Overload. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
You can also look for information at:
Copyright 2008 Evan Carroll, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.