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
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 420
Download (untitled) / with headers
text/plain 420b
$@ 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.
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Type: multipart/mixed; boundary="----------=_1337111559-20177-143"
Message-ID: <rt-3.8.HEAD-20177-1337111559-314.77227-0-0 [...] rt.cpan.org>
X-RT-Original-Encoding: utf-8
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 261
Download (untitled) / with headers
text/plain 261b
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.
MIME-Version: 1.0
Subject: RT_75313.diff
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Type: text/x-patch; name="RT_75313.diff"
Content-Disposition: inline; filename="RT_75313.diff"
Content-Transfer-Encoding: binary
Content-Length: 436
Download RT_75313.diff
text/x-diff 436b
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);
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-20177-1337111559-314.77227-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-20177-1337111559-314.77227-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-13961-1341024999-864.77227-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 99
Thanks for the patch. Can you give me a test for it, please? -- Goro Fuji (gfx) GFUJI at CPAN.org
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-1966-1341032013-1802.77227-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 93
Applied the patch so that it is fixed in 0.98. Thanks! -- Goro Fuji (gfx) GFUJI at CPAN.org
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-29863-1341032016-1465.77227-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 93
Applied the patch so that it is fixed in 0.98. Thanks! -- Goro Fuji (gfx) GFUJI at CPAN.org
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-28343-1345902148-1204.77227-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 792
Download (untitled) / with headers
text/plain 792b
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.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.