Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Moose: problem with accessor

by saintex (Scribe)
on Mar 31, 2011 at 19:32 UTC ( [id://896711]=note: print w/replies, xml ) Need Help??


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

Hello,
thank you for your reply.

What is the difference between
$self->method=>'changed';
and
$self->method('changed');
?
Is it a private call?
How can I generally define private methods or attributes?

Don't I need to define:
sub _set_mode { ... }
in some part of the code?

Replies are listed 'Best First'.
Re^3: Moose: problem with accessor
by ikegami (Patriarch) on Mar 31, 2011 at 19:43 UTC

    '=>' 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».

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-19 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found