Data-Path-XS
view release on metacpan or search on metacpan
use strict;
use warnings;
use Test::More;
use Test::LeakTrace;
use Scalar::Util qw(weaken isweak);
use Data::Path::XS qw(
path_get path_set path_delete path_exists
patha_get patha_set
);
# Behaviour around interesting Perl reference shapes.
subtest 'cyclic references â get returns the cycle, no infinite loop' => sub {
my $d = { name => 'root' };
$d->{self} = $d; # cycle
is(path_get($d, '/self/self/self/name'), 'root', 'three hops through cycle');
ok(path_exists($d, '/self/self/self/self'), 'exists through cycle');
# Break the cycle to avoid leak warning at scope exit
delete $d->{self};
};
subtest 'weak references propagate as the underlying ref' => sub {
my $target = { val => 42 };
my $d = { weak => $target };
weaken $d->{weak};
ok(isweak($d->{weak}), 'sanity: weak flag set');
is(path_get($d, '/weak/val'), 42, 'path_get follows weak ref');
# path_get must NOT strengthen the ref
ok(isweak($d->{weak}), 'weak flag preserved after path_get');
};
subtest 'scalar refs as values are passthrough' => sub {
my $scalar = 'hello';
my $d = { ref => \$scalar };
( run in 0.776 second using v1.01-cache-2.11-cpan-995e09ba956 )