Re: MX::Traits why can't traits be added with just new?

[email protected] (Tomas Doran)
Newsgroups perl.moose
Message-ID <[email protected]>
On 14 Mar 2012, at 17:21, Caleb Cushing wrote:
> I'm not saying new_with_traits is bad, or with_traits is bad, just
> that I'd like to be able optionally turn on a way to do it with just
> ->new . regardless of whether it changes peoples expectations of what
> new does (because otherwise I have to change a different expectation,
> which construction method to use )

package MyApp::Role::TraitsInBuild;
use Moose::Role;

sub BUILD {}
after BUILD => sub {
    my ($self, $args) = @_;
    foreach (@{$args->{traits}}) {
        $_->meta->apply($self);
   }
};

Or you can around new => sub {… and have the logic there…

Or whatever you like really.

I don't think that what you want is at all hard, I just think it's a bad idea to do it as a standard in any way.. :)

Cheers
t0m
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.