Search code examples
perloopmojolicious

How to get structure and inheritance history of a Perl object (not a class)?


use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
my $tx = $ua->get( shift );

How to get structure and inheritance history of these Perl objects ($ua and $tx)?

Data::Dumper shows only small part of structure and inheritance history.


Solution

  • Perl doesn't keep track of historical values of variables.

    Perl doesn't keep track of historical inheritance relationships.

    Objects don't have inheritance relationships; classes do.


    The current structure of an object can be found using the following:

    use Data::Dumper qw( Dumper );
    
    {
       local $Data::Dumper::Purity = 1;
       print(Dumper($o));
    }
    

    (It has limitations: Only one value of dualvars is shown; associated magic isn't shown; etc. If you need a more precise representation, Devel::Peek's Dump can be used.)

    The classes from which an object's class currently inherits can be found using the following:

    use mro          qw( );
    use Scalar::Util qw( blessed );
    
    say join ", ", @{ mro::get_linear_isa(blessed($o)) };