MooseX::Storage::Format::Storable でJavaのSerializableっぽくオブジェクトのシリアライズ
以下のように
with Storage('format' => 'Storable');
とMooseのRoleをconsumeすると、そのクラスのオブジェクトをserialize, deserializeできるようになります。
JavaのSerializable interfaceをimplementsするような感じでつかえるのはいいですね。
package Point; use Moose; use MooseX::Storage; with Storage( 'format' => 'Storable' ); has 'x' => ( is => 'rw', isa => 'Int' ); has 'y' => ( is => 'rw', isa => 'Int' ); 1; package main; use Data::Dumper; use Perl6::Say; my $p = Point->new( x => 10, y => 10 ); my $storable_data = $p->freeze(); my $p2 = Point->thaw($storable_data); say $p2->x;
# FormatにはJSONなどもあるので、MooseのオブジェクトをViewに渡す際にJSON化して使うなんていうのもいいかもしれません。