开发者

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

开发者 https://www.devze.com 2023-03-25 01:17 出处:网络
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 va

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

精彩评论

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