Re: Java annotation/.NET attributes in Moose

[email protected] (Brian Fraser)
Newsgroups perl.moose
Message-ID <CA+nL+nZePFrnmXBiqrTnz0e-5SD3Hj52ZP-Qtg_0Z=b-vM6DEw@mail.gmail.com>
On Wed, Oct 19, 2011 at 4:19 AM, Sherwin Daganato <[email protected]>wrote:

> Has anyone here got any idea how to implement Java annotation[1] or
> .NET attributes[2] with Moose? I'm particularly interested in how it
> can be applied to a Moose class and attribute.
>
> Right now I'm looking into MooseX-Role-Parameterized to create
> parameterized metaclass and attribute traits. It seems to be a fit for
> what I want to do, except that the role block which it requires will
> be empty.
>
> Anyone with a more elegant solution?
>
> [1] http://en.wikipedia.org/wiki/Java_annotation
> [2] http://en.wikipedia.org/wiki/.NET_metadata#Attributes
>

You don't really need Moose to emulate .NET attributes*; vanilla Perl has
subroutine attributes:
http://perldoc.perl.org/Attribute/Handlers.html
http://perldoc.perl.org/attributes.html

But honestly, why would you want to do that? Trying to program X in Y is
always a code smell. In what little Moose I've done, a trait has always been
the best fit for this sort of thing.

*Though there's probably a MooseX module out there that will handle things
for you. Just saying that it might be overkill.
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.