View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Evan Carroll > MooseX-Types-Moose-Overload > MooseX::Types::Moose::Overload



Annotate this POD


Module Version: 0.01_07   Source  


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.

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>


Please report any bugs or feature requests to bug-moosex-types-overload at, or through the web interface at 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.

    perldoc MooseX::Types::Overload

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.

syntax highlighting: