DBIx-QuickORM
view release on metacpan or search on metacpan
lib/DBIx/QuickORM/Type/JSON.pm view on Meta::CPAN
else { die "Not sure what to do with $val" }
}
return $class->JSON->encode($val);
}
sub qorm_compare {
my $class = shift;
my ($a, $b) = @_;
# First decode the json if it is not already decoded
$a = $class->qorm_inflate($a);
$b = $class->qorm_inflate($b);
# Now encode it in canonical form so that identical structures produce identical strings.
# Another option would be to use Test2::Compare...
$a = $class->CJSON->encode($a);
$b = $class->CJSON->encode($b);
return $a cmp $b;
}
t/AI/type_json.t view on Meta::CPAN
use DBIx::QuickORM::Type::JSON;
my $C = 'DBIx::QuickORM::Type::JSON';
subtest affinity => sub {
is($C->qorm_affinity, 'string', "JSON affinity is string");
};
subtest inflate => sub {
my $ref = $C->qorm_inflate(class => $C, value => '{"a":1,"b":[2,3]}');
is($ref, {a => 1, b => [2, 3]}, "decoded JSON object string into a Perl structure");
is(
$C->qorm_inflate(class => $C, value => '[1,2,3]'),
[1, 2, 3],
"decoded JSON array string",
);
is($C->qorm_inflate(class => $C, value => undef), undef, "undef inflates to undef");
# An already-inflated ref passes straight through (the row layer can
# re-run inflate on a value that is already a ref).
my $already = {x => 1};
is($C->qorm_inflate(class => $C, value => $already), $already, "ref value passes through unchanged");
};
( run in 3.142 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )