in reply to Re^2: Moose: problem with accessor
in thread Moose: problem with accessor

'=>' is a (slightly special) comma, so

$self->method => 'changed'
is
$self->method, 'changed'
which is
$self->method(), 'changed'

How can I generally define private methods or attributes?

"Perl doesn't have an infatuation with enforced privacy. It would prefer that you stayed out of its living room because you weren't invited, not because it has a shotgun" — Larry Wall

You can't force something to be private (and it would be useless to do so). However, naming something with a leading "_" is a well known convention to indicate something is private.

Don't I need to define [_set_mode]

No. When you use 'reader', 'writer' and 'accessor', you are asking Moose to create the a function for you.

Keep in mind that «is => 'ro'» is a shortcut for «reader => $att_name» and «is => 'rw'» is a shortcut for «accessor => $att_name».

Replies are listed 'Best First'.
Re^4: Moose: problem with accessor
by saintex (Scribe) on Apr 01, 2011 at 07:38 UTC
    hello,
    thank you for your excellent answer.

    At this point, what is the difference between:
    $self->method(), 'changed' and  $self->method('changed') ?

      $self->method() passes no arguments.
      $self->method('changed') passes an argument.

        So, can't I use:
        $self->method => 'changed';
        to pass any arguments?

        is it right?