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

北战南征 提交于 2020-01-05 05:53:09

问题


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.


回答1:


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)) };


来源:https://stackoverflow.com/questions/59512734/how-to-get-structure-and-inheritance-history-of-a-perl-object-not-a-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!