Re: Constant attributes

[email protected] (Sartak)
Newsgroups perl.moose
Message-ID <[email protected]>
On 5/22/08, Bernardo Rechea <[email protected]> wrote:
> Chris Prather wrote:
>
>  > which can also be written:
>  >
>  > sub needs_trinket () { 0 }
>  > and
>  > sub needs_trinket () { 1 }
>  >
>  > perl optimizes things with empty prototypes that return a constant.
>
>
> That's quite a wonderful bit of arcana. At least for me: I don't use
>  prototypes, so I never paid much attention to the prototypes section in the
>  camel book.
>
>
>  Bernardo
>

Coincidentally, use constant is just a nicer syntax for this. The
relevant line in constant.pm is:

    *$full_name = sub () { $scalar };

Hooray Perl. :)

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.