Stereonaut!

Re: Private methods in Perl5
~ Aug 14, 2009

with 4 comments

Peter, I have a single word for you: Moose.

Photo 81

:)

Written by David Moreno

August 14th, 2009 at 3:41 pm

Categorized in: debian,perl,planet-debian,planeta linux

Tagged with , ,

4 Responses to 'Re: Private methods in Perl5'

Subscribe to comments with RSS or TrackBack to 'Re: Private methods in Perl5'.

  1. Moose itself does not provide Private Methods.

    Sid Burn

    17 Aug 09 at 5:20 am

  2. Exactly. Then again, implementing private methods is simple and straight forward. Plus, IMO, the proper way to design and implement OO right now on Perl 5 is only Moose.

    David Moreno

    17 Aug 09 at 7:26 am

  3. Yeah that is right. Moose is the way you should use OOP in Perl today. I use it myself. I even look over MooseX::Declare and what he provides like MooseX::Method::Signatures or MooseX::MultiMethod it is awesome. But i never see private Methods in Perl, and i don't think it is easy to implement. (I don't speak of anonymous subroutines)

    A "real" Private Method is something that in your own module you can just write "$self->something()" just like a normal method. But you can see "something()" only in your module. From outside of your module calling "something()" on the object then needs to throw an error that says that something() doesn't exists.

    Even namespace::clean can't help you here.

    Moose and his extensions are really great, but i don't see how you can implement private methods with it.

    Sid Burn

    18 Aug 09 at 3:22 am

  4. As far as I can tell, one _cannot_ implement the private concept in Perl 5.

    A sub is always a sub in Perl 5 whatever the module/extension you're using to declare your classes.

    The same goes for "private" attributes for a given object. You won't be able to prevent a user from accessing $self->{_my_really_private_stuff} … ;)

    Alexis Sukrieh

    7 Oct 09 at 7:49 am

Leave a Reply