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=1d4669291edf1495a90d5b110a6334b05ca1cc78;hp=d4f19b8c46fcca2c77c2a4a0118f36f5fe487b74;hpb=b5f363acfcf077778dd4f3b59460a0cbb9e51400;p=gitmo%2FMooseX-Storage.git diff --git a/t/006_w_custom_type_handlers.t b/t/006_w_custom_type_handlers.t index d4f19b8..e028a42 100644 --- a/t/006_w_custom_type_handlers.t +++ b/t/006_w_custom_type_handlers.t @@ -1,36 +1,35 @@ -#!/usr/bin/perl - use strict; use warnings; use Test::More tests => 9; -use Test::Exception; +use Test::Deep; +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; @@ -39,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', @@ -67,7 +66,7 @@ isa_ok($foo, 'Foo'); isa_ok($foo->bar, 'Bar'); -is_deeply( +cmp_deeply( $foo->pack, { __CLASS__ => "Foo", @@ -81,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'); }