Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Assigning to a ArrayRef accessor type

by tobyink (Canon)
on Sep 21, 2020 at 22:16 UTC ( [id://11122045]=note: print w/replies, xml ) Need Help??


in reply to Re: Assigning to a ArrayRef accessor type
in thread Assigning to a ArrayRef accessor type

The perlootut page you recommend says:

There's really no good reason to write your classes from scratch in Perl.

  • Comment on Re^2: Assigning to a ArrayRef accessor type

Replies are listed 'Best First'.
Re^3: Assigning to a ArrayRef accessor type
by perlfan (Vicar) on Sep 21, 2020 at 22:57 UTC
    Okay, so what? Does it say, "There's no good reason to know how objects in Perl work."? My contention is simple, having this knowledge would likely result in some different choices being made depending on what is appropriate given the need.

      This accessor could be implemented in two ways. I'm showing this as a read-only accessor because the read-write aspect isn't important for the example.

      sub files { return $_[0]{'files'}; } # OR sub files { return @{ $_[0]{'files'} }; }

      (And of course, there's the version that checks wantarray.)

      OP's problem is that he assumed Moo did it the second way, when it actually does it the first way. I don't see how learning to write constructors and accessors from scratch would have helped figure out what the issue was.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11122045]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-25 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found