diff options
author | Gianni Ceccarelli <dakkar@thenautilus.net> | 2011-11-10 12:11:38 +0000 |
---|---|---|
committer | Gianni Ceccarelli <dakkar@thenautilus.net> | 2011-11-10 12:24:14 +0000 |
commit | 04c994801b13d881b9a11dce6080f247af7ac1a9 (patch) | |
tree | 287151fb5d8b5a56a410cae1c45bf8d3d695efc5 /Data-MultiValued/t | |
parent | all traits, and some tests (diff) | |
download | data-multivalued-04c994801b13d881b9a11dce6080f247af7ac1a9.tar.gz data-multivalued-04c994801b13d881b9a11dce6080f247af7ac1a9.tar.bz2 data-multivalued-04c994801b13d881b9a11dce6080f247af7ac1a9.zip |
json-ify, works everywhere
ranges now use 'undef' instead of infs… damn json
infinity is not representable in json…
Diffstat (limited to 'Data-MultiValued/t')
-rw-r--r-- | Data-MultiValued/t/json.t | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/Data-MultiValued/t/json.t b/Data-MultiValued/t/json.t index 432ac69..ed3a31a 100644 --- a/Data-MultiValued/t/json.t +++ b/Data-MultiValued/t/json.t @@ -4,23 +4,34 @@ use warnings; package Foo;{ use Moose; use Data::MultiValued::AttributeTrait::Tags; +use Data::MultiValued::AttributeTrait::Ranges; +use Data::MultiValued::AttributeTrait::TagsAndRanges; use Data::Printer; -has stuff => ( +has tt => ( is => 'rw', isa => 'Int', traits => ['MultiValued::Tags'], default => 3, - predicate => 'has_stuff', - clearer => 'clear_stuff', + predicate => 'has_tt', + clearer => 'clear_tt', ); -has other => ( +has rr => ( is => 'rw', isa => 'Str', - traits => ['MultiValued::Tags'], - predicate => 'has_other', - clearer => 'clear_other', + traits => ['MultiValued::Ranges'], + predicate => 'has_rr', + clearer => 'clear_rr', +); + +has ttrr => ( + is => 'rw', + isa => 'Str', + default => 'default', + traits => ['MultiValued::TagsAndRanges'], + predicate => 'has_ttrr', + clearer => 'clear_ttrr', ); sub new_in_place { @@ -29,7 +40,7 @@ sub new_in_place { my $self = bless $hash,$class; for my $attr ($class->meta->get_all_attributes) { - if ($attr->does('MultiValued::Tags')) { + if ($attr->does('Data::MultiValued::AttributeTrait')) { $attr->_rebless_slot($self); } } @@ -41,7 +52,7 @@ sub as_hash { my %ret = %$self; for my $attr ($self->meta->get_all_attributes) { - if ($attr->does('MultiValued::Tags')) { + if ($attr->does('Data::MultiValued::AttributeTrait')) { my $st = $attr->_as_hash($self); if ($st) { $ret{$attr->full_storage_slot} = $st; @@ -63,11 +74,12 @@ use JSON::XS; my $opts={tag=>'something'}; my $json = JSON::XS->new->utf8; -my $obj = Foo->new(other=>'foo'); -$obj->stuff_multi($opts,1234); +my $obj = Foo->new(rr=>'foo'); +$obj->tt_multi($opts,1234); my $hash = $obj->as_hash; note p $hash; my $str = $json->encode($hash); +note p $str; note "rebuilding"; my $obj2 = Foo->new_in_place($json->decode($str)); @@ -75,8 +87,8 @@ my $obj2 = Foo->new_in_place($json->decode($str)); note p $obj; note p $obj2; -is($obj2->stuff,$obj->stuff,'stuff'); -is($obj2->stuff_multi($opts),$obj->stuff_multi($opts),'stuff tagged'); -is($obj2->other,$obj->other,'other'); +is($obj2->tt,$obj->tt,'tt'); +is($obj2->tt_multi($opts),$obj->tt_multi($opts),'tt tagged'); +is($obj2->rr,$obj->rr,'rr'); done_testing; |