geoffleach has asked for the wisdom of the Perl Monks concerning the following question:

IO::All (among others) creates objects which the standard debugger does not understand.

DB<1> x @files 0 IO::All::File=GLOB(0x2e0c038)
How can I see inside?

Thanks.

Replies are listed 'Best First'.
Re: Debugging objects
by LanX (Saint) on Aug 23, 2017 at 09:05 UTC
    Annomonk gave you a good hint for this case, but for the general case of inspecting objects ...

    Most objects in Perl are blessed hash references but not all.

    Since any kind of reference can be blessed it depends on the implementation, if and how you can "see inside". (That's particularly difficult for inside/out objects.)

    Good news, it's Perl, i.e. the implementation is open to be read.

    Cheers Rolf
    (addicted to the Perl Programming Language and to ☆☆☆☆ :)
    Je suis Charlie!

Re: Debugging objects
by zakame (Pilgrim) on Aug 23, 2017 at 11:59 UTC
    You can probably use Data::Printer in the Perl debugger to get a peek at objects like this. Ovid also has a .perldb that you can use to customize p in the debugger to inspect via regular Data::Dumper.

      Nope,

      $ perl -MIO::All -MData::Printer -e " p( io(2) ); " Can't use string ("") as a symbol ref while "strict refs" in use at .. +./site/lib/Data/Printer.pm line 702.

        Thanks, that's right. Its because io() will emit an overloaded object so stringification would trigger.

        You'll have to "peel off" the overloading, so to speak, by invoking overload::Overloaded (though funny, the perldoc says this should "true if 'arg' is subject to overloading...", wasn't expecting an actual GLOB object there.)

        % perl -de 0 -MIO::All -MData::Printer Loading DB routines from perl5db.pl version 1.51 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(-e:1): 0 DB<1> $io = io '.zshrc' DB<2> x overload::Overloaded( $io ) 0 GLOB(0x17a4378) -> *IO::All::(( DB<3> $o = overload::Overloaded( $io ) DB<4> Data::Printer::p($o) \ *IO::All::(( (layers: ) DB<5>

        It would probably make a nice exercise to implement a Data::Printer filter for this.

Re: Debugging globjects/globs
by Anonymous Monk on Aug 23, 2017 at 06:46 UTC
    The best way doesnt involve debugger, the best is RTFineM or utsl, whichever works best for you , as relying on dumpers is guessing. You're not limited to using x you can use data:dump:streamer and whatever else dumps globjects

      Example

      $ perl -de 1 Loading DB routines from perl5db.pl version 1.37 Editor support available. Enter h or 'h h' for help, or 'perldoc perldebug' for more help. main::(-e:1): 1 DB<1> x use IO::All; use Data::Dump::Streamer; sub dd { Dump(@_); () +; } 0 0 DB<2> x our $banana = io('2.txt'); 0 IO::All::File=GLOB(0x16af5fc) -> DB<3> x dd $banana my ($class,$constructor,%flags,@flags); $class = 'IO::All'; $constructor = sub { package IO::All::Base; use warnings; use strict; my $self = $class->new(@_); foreach $_ (@flags) { $self->$_($flags{$_}); } $self->constructor($constructor); return $self; }; %flags = (); @flags = (); $IO_All_File1 = do{ require Symbol; Symbol::gensym }; *$IO_All_File1 = { _assert => 0, _autoclose => 1, _binary => undef, _binmode => undef, _encoding => undef, _lock => 0, constructor => $constructor, io_handle => undef, is_open => 0, mode => undef, name => '2.txt', package => 'IO::All', tied_file => undef }; bless( $IO_All_File1, 'IO::All::File' ); empty array DB<4> q $
        Wow. Such a lesson. Thanks.
        I haven't tried it out but why do you write x dd ... if your dd() just returns an empty list ?

        dd() seems to do all the writing already.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!