davorg-cpan / moox-role-json_ld

Moo role to easily add JSON-LD generation into a class
1 stars 5 forks source link

Nesting JSON_LD objects of the same type causes ->json_ld to hang in json_ld_data #23

Closed jwrightecs closed 4 years ago

jwrightecs commented 4 years ago

Running the following code:

use Test::More;
use Data::Dumper;
{
  package LD::Person;
  use Moo;
  use Types::Standard qw/Str ArrayRef InstanceOf/;
  use MooX::JSON_LD 'Person';

  has name => (
    is => 'ro',
    json_ld => 'name',
  );
  has children => (
    is => 'ro',
    json_ld => 'children',
  );
  no Moo;
  no MooX::JSON_LD;
}

my $c = LD::Person->new( name => 'Carla Foo');
my $p = LD::Person->new( name => 'Sam Foo', children => $c);

diag $p->json_ld;

done_testing;

Causes the script to hang on the json_ld call. This only affects JSONLD objects that contain instances of the same type (in this case LD::Person).

$ = MooX::Role::JSON_LD::json_ld_data(ref(LD::Person)) called from file `lib/perl5/site_perl/5.10.1/MooX/Role/JSON_LD.pm' line 189
$ = MooX::Role::JSON_LD::_resolve_nested(ref(LD::Person)) called from file `lib/perl5/site_perl/5.10.1/MooX/Role/JSON_LD.pm' line 213
@ = MooX::Role::JSON_LD::json_ld_data(ref(LD::Person)) called from file `lib/perl5/site_perl/5.10.1/MooX/Role/JSON_LD.pm' line 240
@ = MooX::Role::JSON_LD::json_ld(ref(LD::Person)) called from file `./ld3.pl' line 24
davorg commented 4 years ago

Do you have a test that demonstrates the problem?

jwrightecs commented 4 years ago

sorry added without code

davorg commented 4 years ago

Version 0.0.18 fixes this and is en route to CPAN.