开发者

Is it true that Class::Accessor::Fast is only handy for scalar data members?

It saves our time to write tedious get/set methods.

But it seems to me only handy for scalar data members, won't fit for array/hash data members开发者_StackOverflow,right?


For most Class::Accessor variants, including Class::Accessor::Fast, the underlying structure representing the objects are blessed hash references.

Hashes can only store scalars as their values.

However, that doesn't mean you can't store a list of things, a hash of things, or whatever else in your object. Merely take a reference to whatever non-scalar structure you want to store.

All references are scalars, and a hash will be able to store them just fine, no matter if you use direct object access, accessors generated by some Class::Accessor variant, Moose, or anything else that helps you in building your objects upon hash references.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜