私の最後の質問では、私は多くの無関係なことを尋ねました.いくつかの質問だけに答える複数の回答を受け入れることはできません.
use 5.010;
use strict;
use warnings;
package SomeMoo;
use Moo;
has $_ => ( is => 'rw', predicate => 1) for (qw(a1 a2 nn xx));
package SomeMoose;
use Moose;
has $_ => ( is => 'rw', predicate => "has_".$_) for (qw(a1 a2 nn xx));
package main;
use Data::Dumper;
my $omoo = SomeMoo->new(a1 => "a1val", a2 => "a2val", xx=>"xxval");
say Dumper $omoo;
# $VAR1 = bless( {
# 'a2' => 'a2val',
# 'a1' => 'a1val',
# 'xx' => 'xxval'
# }, 'SomeMoo' );
#for Moose:
my $omoose = SomeMoose->new(a1 => "a1val", a2 => "a2val", xx=>"xxval");
say Dumper $omoose;
#as above, only blessed to package 'SomeMoose'.
#in both cases can do the next, for getting an (partial) list "attributes"
say $_ for keys (%$omoose); #or %$omoo
#anyway, in Moose i can
say "all attributes";
say $_->name for $omoose->meta->get_all_attributes();
#what prints
# all attributes
# nn
# a2
# a1
# xx
したがって、祝福されたオブジェクトは、設定された属性のみを含むオブジェクトを参照します。
質問:
- なぜ
$self
参照、(したがって、%$self
conatains) 設定されている属性のみであり、すべてではありません。たとえば、nn
コード例からもですか? (bless
のみが を関連付ける場合、すべてのパッケージ変数が含まれていないのreference
はpackage
なぜ$omoo
ですか?) そして、Moose はどこからそれを知っているのですか?) - Moo の場合に all_attributes を取得するには?
明らかに、私はいくつかの基本的な知識を欠いています.. :(