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, right‽ Good, thought so.
coerce => 1
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.
Evan Carroll, <me at evancarroll.com>
<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.
bug-moosex-types-overload at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc MooseX::Types::Overload
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Types-Overload
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/MooseX-Types-Overload
CPAN Ratings
http://cpanratings.perl.org/d/MooseX-Types-Overload
Search CPAN
http://search.cpan.org/dist/MooseX-Types-Overload/
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.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'right‽'. Assuming UTF-8
To install MooseX::Types::Moose::Overload, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Types::Moose::Overload
CPAN shell
perl -MCPAN -e shell install MooseX::Types::Moose::Overload
For more information on module installation, please visit the detailed CPAN module installation guide.