如何获取 Perl 对象(不是类)的结构和继承历史? [英] How to get structure and inheritance history of a Perl object (not a class)?

查看:53
本文介绍了如何获取 Perl 对象(不是类)的结构和继承历史?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

如何获取这些 Perl 对象($ua 和 $tx)的结构和继承历史?

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

Data::Dumper 仅显示结构和继承历史的一小部分.

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

推荐答案

Perl 不跟踪变量的历史值.

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

Perl 不跟踪历史继承关系.

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

(它有局限性:只显示一个对偶变量的值;不显示关联的魔法;等等.如果您需要更精确的表示,可以使用 Devel::Peek 的 Dump.)

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

这篇关于如何获取 Perl 对象(不是类)的结构和继承历史?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆