Re: Explain private methods/attributes to newbie

[email protected] (Yuval Kogman)
Newsgroups perl.moose
Message-ID <[email protected]>
On Tue, Apr 01, 2008 at 20:08:52 +0000, [email protected] wrote:
> What is a the best way to specify them? Are they really private is the C++ sense?

Out of Perl convention Moose doesn't support private stuff per se.

It's pretty standard in Perl land to name private methods with a
leading underscore, to imply privateness. Usually they are left
undocumented, too.

Similarly, the idiomatic way to declare a private attribute in Moose
is:

	has foo => (
		is => "rw",
		writer => "_foo",
	);

In practice this generally private in a much more Perlish sense - if
somebody uses them and their code breaks, it's their fault.

Since in Perl there is always a way to cheat and work around
everything, trying too hard to make things private is probably just
going to make things more complicated for everyone involved, instead
of helping to develop clean maintainable code.

-- 
  Yuval Kogman <[email protected]>
http://nothingmuch.woobling.org  0xEBD27418
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.