Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Mouse CPAN distribution.

Report information
The Basics
Id: 77227
Status: open
Priority: 0/
Queue: Mouse

People
Owner: Nobody in particular
Requestors: dexter [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.97
Fixed in: (no value)



Subject: Mouse: default => sub { $@ } doesn't work with XS
$@ is undef when used with XS flavour of Mouse. It works correctly with PurePerl (Mouse::Tiny) Use case: $ perl -le 'package E; use Mouse; has e => (is => "ro", default => sub { $@ }); package main; eval { die "foo" }; my $e=E->new; print $e->e ' $ perl -le 'package E; use Mouse::Tiny; has e => (is => "ro", default => sub { $@ }); package main; eval { die "foo" }; my $e=E->new; print $e->e ' foo at -e line 1.
Seems that this report is a duplicate of #75313. The patch for #75313 fixes this use case: $ perl -Ilib -le 'package E; use Mouse; has e => (is => "ro", default => sub { $@ }); package main; eval { die "foo" }; my $e=E->new; print $e->e ' foo at -e line 1.
Subject: RT_75313.diff
diff --git a/xs-src/MouseUtil.xs b/xs-src/MouseUtil.xs index 3ec7d8c..2124138 100644 --- a/xs-src/MouseUtil.xs +++ b/xs-src/MouseUtil.xs @@ -130,8 +130,8 @@ mouse_call_sv_safe(pTHX_ SV* const sv, I32 const flags) { ENTER; /* Don't do SAVETMPS */ - SAVESPTR(ERRSV); - ERRSV = sv_newmortal(); + SAVEGENERICSV(ERRSV); + ERRSV = SvREFCNT_inc(sv_newmortal()); count = Perl_call_sv(aTHX_ sv, flags | G_EVAL);
Thanks for the patch. Can you give me a test for it, please? -- Goro Fuji (gfx) GFUJI at CPAN.org
Applied the patch so that it is fixed in 0.98. Thanks! -- Goro Fuji (gfx) GFUJI at CPAN.org
Applied the patch so that it is fixed in 0.98. Thanks! -- Goro Fuji (gfx) GFUJI at CPAN.org
This bug is not closed. See following test case: #!perl # https://rt.cpan.org/Ticket/Display.html?id=77227 use strict; use Test::More tests => 1; { package Foo; use Mouse; has e => ( is => 'ro', default => sub { $@ }, ); } $@ = "foo"; my $Foo = Foo->new; is $Foo->e, "foo"; done_testing; __END__ The default value filled with $@ can be useful if you implement an exception class. This can't be implemented with Mouse::XS because of mouse_call_sv_safe() wrapper which calls Perl_call_sv() with G_EVAL flag. This flag clears ERRSV and makes $@ variable unavailable in Mouse's callbacks. Unfortunately, this wrapper is needed to make a workaround for RT#69939. I think this workaround should be disabled for modern version of Perl, at least >= 5.12.