1
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.

xcodejoy
  • 50
  • 9
  • 1
    See also [Devel::Isa::Explainer](https://metacpan.org/pod/release/KENTNL/Devel-Isa-Explainer-0.002900-TRIAL/lib/Devel/Isa/Explainer.pm) and [mro::get_linear_isa()](https://perldoc.perl.org/mro.html#mro%3a%3aget_linear_isa(%24classname%5b%2c-%24type%5d)) – Håkon Hægland Dec 28 '19 at 16:59
  • What are you really trying to find out? The only thing you need to know about an object for 95% of cases is its [documented interface](https://metacpan.org/pod/Mojo::UserAgent). Doing anything based on only the programmatic structure of the object is unsupported. – Grinnz Dec 29 '19 at 20:25
  • You are right. All things are well documented. But, to explore the UserAgent object I have to spend a lot of time reading documentation and writing notes. On the other hand, if I will see the complete structure of UserAgent object - it will save my time reading documentation. – xcodejoy Dec 30 '19 at 16:00

1 Answers1

3

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)) };
ikegami
  • 367,544
  • 15
  • 269
  • 518