The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

MooseX::Types::Moose::Overload - Deal with overload, in the overloaded sense ;)

DESCRIPTION

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 modifies the base types in a slightly ugly way -- I hope to fix this in the future. I reserve the right to remove it from cpan, or change its namespace until it is removed from DEV status; because the base types are global, this attaches to all modules that use the base types. Please see the section on "Future Proofing".

This only attaches a coercion to subtypes of "Value", and it only coerces from "Objects", and only executes on Objects that stringify overload.

SYNOPSIS

        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 );

Future Proofing (TODO)

Currently, this module iterates through all subtypes of "Value" and attaches a coercion with the MooseX::Types1 API. I'm not yet sure if there is a supported method of cloning those base types. Please, do not rely on a naked use MooseX::Types::Moose::Overload; modifying the types exported by MooseX::Types::Moose::Overload. This is an unfortunate side-effect. I really would rather return new fresh types over modify the base types. I didn't realize that the base types were still kinda global.

AUTHOR

Evan Carroll, <me at evancarroll.com>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc MooseX::Types::Overload

You can also look for information at:

COPYRIGHT & LICENSE

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:

Around line 47:

Non-ASCII character seen before =encoding in 'right‽'. Assuming UTF-8