summaryrefslogtreecommitdiff
path: root/Data-MultiValued/t/json.t
diff options
context:
space:
mode:
Diffstat (limited to 'Data-MultiValued/t/json.t')
-rw-r--r--Data-MultiValued/t/json.t40
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;