Re: Constant attributes
[email protected] ("Chris Prather")
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <[email protected]> |
On Wed, May 21, 2008 at 4:49 PM, Sartak <[email protected]> wrote: > 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; which can also be written: sub needs_trinket () { 0 } and sub needs_trinket () { 1 } perl optimizes things with empty prototypes that return a constant. -Chris