Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 102639
Status: rejected
Priority: 0/
Queue: Type-Tiny

People
Owner: Nobody in particular
Requestors: ZDM [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Types serialization / deserialization
I can't find proper way to serialize types. I am trying to use "display_name" for serialization and eval for deserialization. But this works not for all parametrized types. For example, StrMatch [qr/.../] can't be evaluated correctly. Is it possible to add additional attribute, for example, serialize => sub {...}, so each type can correctly serialize yourself. And additional Type::Tiny constructor method, than can create object from serialized value.
In the general case, types cannot be serialized to strings. They can, for example, close over variables. my $test = 42; my $type = Type::Tiny->new(constraint => sub { $_==$test }); $type->assert_valid(42); $test = 666; $type->assert_valid(666); $type->assert_valid(42); # dies In this example, $type couldn't be serialized and deserialized in any meaningful way. Of course, it may be that the subset of types which you use in your application can be serialized and deserialized. To do this though, I'd suggest writing your own application-specific dump/load functions — I don't think they should be part of Type::Tiny itself.