Skip to content

Unexpected behaviour with in-package _data_printer method #199

Description

@hvds

I do not understand why the output here claims to have seen repeated values like var[0][0]. I don't see this behaviour without the custom _data_printer method (tested both with and without my own .dataprinter settings).

% $PERL -v | grep version 
This is perl 5, version 34, subversion 0 (v5.34.0) built for x86_64-linux

% $PERL -MDDP -E 'say $Data::Printer::VERSION'
1.002001

% cat t1
# simplified from real-world example
use strict;
use warnings;
use DDP;

my $list = [
    map [ map Obj->new($_), @$_ ], (
        [ { data => { a => 1 } }, { data => { b => 2 } } ],
        [ { data => { c => 3 } }, { data => { d => 4 } } ],
    ),
];
p $list;

package Obj {
    sub new {
        my($class, $data) = @_;
        bless $data, $class;
    }
    sub _data_printer {
        my($self, $ddp) = @_;
        my %subdata = %{ $self->{data} };
        return $ddp->parse(\%subdata);
    }
};

% $PERL t1
[
    [
        {
            a => 1
        },
        {
            b => var[0][0]
        }
    ],
    [
        {
            c => 3
        },
        {
            d => var[1][0]
        }
    ]
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions