X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F006_w_custom_type_handlers.t;h=e028a4265c42ae09c4b9b1f144571e9ecbdd05c1;hb=c2d52f94beb56939250944a12df15d7d90779866;hp=bc59968e5aeba2b7f3bf8bb6445eb81d908a1ce3;hpb=81a84db6ebe5ec540d0035fc6d1104cc49c81e25;p=gitmo%2FMooseX-Storage.git diff --git a/t/006_w_custom_type_handlers.t b/t/006_w_custom_type_handlers.t index bc59968..e028a42 100644 --- a/t/006_w_custom_type_handlers.t +++ b/t/006_w_custom_type_handlers.t @@ -7,29 +7,29 @@ use Test::Fatal; BEGIN { use_ok('MooseX::Storage'); - use_ok('MooseX::Storage::Engine'); + use_ok('MooseX::Storage::Engine'); } =pod -This is just a simple example of defining +This is just a simple example of defining a custom type handler to take care of custom -inflate and deflate needs. +inflate and deflate needs. =cut { package Bar; use Moose; - + has 'baz' => (is => 'rw', isa => 'Str'); - has 'boo' => (is => 'rw', isa => 'Str'); - + has 'boo' => (is => 'rw', isa => 'Str'); + sub encode { my $self = shift; $self->baz . '|' . $self->boo; } - + sub decode { my ($class, $packed) = @_; my ($baz, $boo) = split /\|/ => $packed; @@ -38,20 +38,20 @@ inflate and deflate needs. boo => $boo, ); } - + MooseX::Storage::Engine->add_custom_type_handler( 'Bar' => ( expand => sub { Bar->decode(shift) }, collapse => sub { (shift)->encode }, ) ); - + package Foo; use Moose; use MooseX::Storage; - + with Storage; - + has 'bar' => ( is => 'ro', isa => 'Bar', @@ -80,9 +80,9 @@ $foo->pack, bar => "BAZ|BOO", }); isa_ok($foo, 'Foo'); - - isa_ok($foo->bar, 'Bar'); - + + isa_ok($foo->bar, 'Bar'); + is($foo->bar->baz, 'BAZ', '... got the right stuff'); is($foo->bar->boo, 'BOO', '... got the right stuff'); }