Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Moo and Moose together with Throwable::Error.

3 views
Skip to first unread message

Bill Moseley

unread,
Feb 20, 2013, 1:36:19 AM2/20/13
to mo...@perl.org
I'm curious how Moo and Moose play together.

I have some classes that make use of
Throwable::Error<http://search.cpan.org/dist/Throwable/lib/Throwable/Error.pm>,
which uses the StackTrace::Auto role. The problem is StackTrace::Auto
builds Devel::StackTrace without the "no_refs" option set, so my objects
leak. (They don't get DEMOLISHED until global destruction.)

My quick fix was to add this wrapper to my Throwable::Error subclass to add
the no_refs argument to Devel::StackTrace:

around _build_stack_trace_args => sub {
my ( $orig, $self, @rest ) = @_;
my $args_array = $self->$orig( @rest );
push @{$args_array}, no_refs => 1;
return $args_array;
};


This worked fine until I updated Throwable::Error which now uses Moo
instead of Moose.

Am I correct that "around" just will not work any more?

Do I have any other options other than overriding the entire
_build_stack_trace_method (besides trying to get no_refs added to the
Throwable dist)?

Thanks,



--
Bill Moseley
mos...@hank.org

Tomas Doran

unread,
Feb 20, 2013, 2:18:21 PM2/20/13
to Bill Moseley, mo...@perl.org

On 20 Feb 2013, at 06:36, Bill Moseley <mos...@hank.org> wrote:

> Am I correct that "around" just will not work any more?
>

No, this should just work.

The Moo class will get upgraded to a Moose class automatically, you shouldn't need to do anything - this should 'just work'.

It's a bug in Moo if it doesn't (and one that will get fixed if you can provide a simpleish test - which sounds easy in this case).

Cheers
t0m

Bill Moseley

unread,
Feb 20, 2013, 8:56:39 PM2/20/13
to mo...@perl.org
Moo $VERSION = '1.000004'; # 1.0.4
$Moose::VERSION = '2.0604';
$Throwable::Error::VERSION = '0.200003';



package My::Throwable;
use Moose;
extends 'Throwable::Error';

around _build_stack_trace_args => sub {
my ( $orig, $self, @rest ) = @_;
return $self->$orig( @rest );
};

package main;

My::Throwable->throw({ message => 'oops', });


The method '_build_stack_trace_args' was not found in the inheritance
hierarchy for My::Throwable at
/home/bill/perl5/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2/x86_64-linux/Class/MOP/Class.pm
line 1053.

But I can override:

package My::Throwable;
use Moose;
extends 'Throwable::Error';

sub _build_stack_trace_args { die "override works!\n" }

package main;

My::Throwable->throw({ message => 'oops', });


override works!

shell returned 255




--
Bill Moseley
mos...@hank.org

Graham Knop

unread,
Feb 21, 2013, 6:38:02 AM2/21/13
to mo...@perl.org
On 2/20/13 8:56 PM, Bill Moseley wrote:
> On Wed, Feb 20, 2013 at 11:18 AM, Tomas Doran <bobt...@bobtfish.net> wrote:
>
>>
>> On 20 Feb 2013, at 06:36, Bill Moseley <mos...@hank.org> wrote:
>>
>>> Am I correct that "around" just will not work any more?
>>>
>>
>> No, this should just work.
>>
>> The Moo class will get upgraded to a Moose class automatically, you
>> shouldn't need to do anything - this should 'just work'.
>>
>> It's a bug in Moo if it doesn't (and one that will get fixed if you can
>> provide a simpleish test - which sounds easy in this case).
>>
>
> Moo $VERSION = '1.000004'; # 1.0.4
> $Moose::VERSION = '2.0604';
> $Throwable::Error::VERSION = '0.200003';
>

I've filed an RT ticket for this issue, and written a test for it. I
don't yet have a fix.

https://rt.cpan.org/Ticket/Display.html?id=83508

0 new messages