develooper Front page | perl.perl6.language | Postings from February 2009

Re: Sigils in Classes after initial "has"

Thread Previous
From:
Moritz Lenz
Date:
February 23, 2009 07:36
Subject:
Re: Sigils in Classes after initial "has"
Message ID:
49A2623E.9040204@physik.uni-wuerzburg.de
Hi,

Peter Schwenn wrote:
> If a class attribute declaration has a . or ! twigil, e.g. has @!items, do
> all the ensuing references to @items in the class's methods have to include
> the twigil or can the variable be written thereafter simply @items without
> the twigil?

If you declare a private attribute

has @!items

then all your references to that attribute have to include that sigil.

If you declare it with the dot sigil:

has @.items

then it creates an accessor, so that self.items or @.items work for
accessing, as well as @!items.

You can also declare

has @items;

in which case a private attribute @!items is declared, with a lexical
alias @items (without any twigil).

This could become a FAQ entry...

Moritz
-- 
Moritz Lenz
http://perlgeek.de/ |  http://perl-6.de/ | http://sudokugarden.de/

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About