This is a very old article. It has been imported from older blogging software, and the formatting, images, etc may have been lost. Some links may be broken. Some of the information may no longer be correct. Opinions expressed in this article may no longer be held.
One of the features of Type::Tiny that differentiates it from Moose’s built-in type constraint system is that it allows stand-alone coercions which can then be mixed with type constraints as required. So if you had a
Split coercion which split a multi-line string into an arrayref of lines, you could do something like this:
use MyApp::Types qw( ArrayRef Split ); has lines => ( is => 'ro', isa => ArrayRef + Split, coerce => 1, );
This is one of several features designed to encourage people to combine coercions with type constraints at the point of use, rather than globally. We wouldn’t want people adding coercions to the global definition of ArrayRef, because global stuff is bad, remember?
Anyway, the current stable version of Type::Tiny (0.040) is going to be the final one to overload the
+ operator for this. From now on, you need to use:
use MyApp::Types qw( ArrayRef Split ); has lines => ( is => 'ro', isa => ArrayRef->plus_coercions(Split), coerce => 1, );
plus_coercions method has existed for quite some time (pre-0.001); it’s not new by any means. It’s just that the alternative (overloading) is going away. So if you’re using that, time to update your code.
Development version 0.041_01 is on CPAN now, and includes this change, so you can test your code with that.