develooper Front page | perl.moose | Postings from February 2012

Re: Not inlining 'new' for Foo since it has method modifiers whichwould be lost if it were inlined

Thread Previous
From:
Chris Prather
Date:
February 24, 2012 05:07
Subject:
Re: Not inlining 'new' for Foo since it has method modifiers whichwould be lost if it were inlined
Message ID:
CAEFJ168CDFmdksEC6Hs=6V_EMMYnnYaQr6=Ni4jL4EXxiiEvOw@mail.gmail.com
On Fri, Feb 24, 2012 at 7:36 AM, Bill Moseley <moseley@hank.org> wrote:
> On Fri, Feb 24, 2012 at 6:59 PM, Chris Prather <chris@prather.org> wrote:
>
>> Throwable::Error composes leads to:
>>
>>
>> https://metacpan.org/source/RJBS/Throwable-0.102080/lib/StackTrace/Auto.pm#L71
>>
>> In which we find 'around new => { ... }'. Which is exactly the method
>> modifier that Moose is warning about.
>>
>
> Thanks Chris.  Is the solution to not make_immutable all the classes that
> inherit from Throwable::Error then or to also use inline_constructor => 1
> then?

inline_constructor => 0

> I guess I'm not sure why the method modifier would be lost, but that's just
> my lack of understand of how Moose works. ;)

If I understand it properly, the inlined constructor would be a
different subroutine entry from the one being modified. If we draw it
out a little (with package names changed to protect the innocent):

    package Parent;
    use Moose; # bring's in Moose::Object::new

    around new => { ... }; # replaces Moose::Object::new with
"Parent::wrapped_new"

    package Child;
    use Moose;
    extends qw(Parent); # brings in "Parent::wrapped_new"

    __PACKAGE__->meta->make_immutable(); # tries to create a Child::new
    # ... but the wrapper is already applied as a part of Parent::wrapped_new
    # ... and so isn't going to be applied


Does this help?

-Chris

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About