in reply to What is this Moose mojo?

has 'fif' => ( is => 'rw', reader => '_fif' );

this will create read accessor with name _fif instead of usual fif, so that's where _fif from and that's why no names conflict.

Replies are listed 'Best First'.
Re^2: What is this Moose mojo?
by locked_user sundialsvc4 (Abbot) on Feb 04, 2009 at 22:33 UTC

    All right then... (damn! that was quick!) :-D ... we still seem to have an attribute and a sub that are both named “fif.”

    Why is there not a conflict with regard to the without an underscore name? Don't we now have a method-name and an attribute-name that are identical? If I now say “$foo->fif,” (no underscore...) what happens ... and why?

    Does the author ... intend ... to first set-up the has declaration, i.e. “just to create the accessor,” and then to immediately supersede it with his own sub? (Blink...) If so, why??

      Does the author ... intend ... to first set-up the has declaration, i.e. “just to create the accessor,” and then to immediately supersede it with his own sub? (Blink...) If so, why??

      It seems author doesn't want you be able to read password fields using $foo->fif (but you still can read them using $foo->_fif).

      Update: Uhm... if it's boolean, then why it's called password?

      =head2 password This is a boolean flag to prevent the field from being returned in the C<$form->fif> and C<$field->fif> methods. =cut has 'password' => ( isa => 'Bool', is => 'rw' );

      If you say "$foo->fif", the fif method is called. The "fif" attribute is stored as "$foo->{fif}".