Re: Constant attributes

[email protected] (Sartak)
Newsgroups perl.moose
Message-ID <[email protected]>
On 5/21/08, Bernardo Rechea <[email protected]> wrote:

Hi Bernardo,

> I wanted a constant attribute, i.e., one that is read-only and not settable
>  at construction time.

Does it have to be a full attribute? It could just be a method that
returns a constant. I often have this in my classes:

package Parent;
use constant needs_trinket => 0;

package Child;
use constant needs_trinket => 1;

Otherwise, if you need a full attribute, you could use:

has needs_trinket => (
    init_arg => undef, # I think this works...
    is => 'ro',
    default => 0,
);

>  Bernardo

Shawn
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.