Skip Menu |
 

This queue is for tickets about the MooseX-Types-Structured CPAN distribution.

Report information
The Basics
Id: 103247
Status: open
Priority: 0/
Queue: MooseX-Types-Structured

People
Owner: ether [...] cpan.org
Requestors: DAKKAR [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 0.31
  • 0.32
Fixed in: (no value)



Subject: imported type constraint subs are no longer blessed
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
X-RT-Interface: Web
Message-ID: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org>
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1427900407-8887-2"
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: binary
Content-Length: 585
Download (untitled) / with headers
text/plain 585b
Since commit https://github.com/moose/MooseX-Types-Structured/commit/e1b0728f79fab8270c3c03711226758b7e363b83 the subs imported by MxT:Structured are no longer blessed, so MooseX::Types::Util "has_available_type_export" returns false when checking them. This, in turn, breaks Parse::Method::Signatures (and maybe others), because it uses that checking function to figure out if a name refers to a valid type constraint. Attached is a test case. I know too little about the internals of MxT to attempt a solution right now, but I'll keep looking at it and may send a patch next week.
Subject: test2.pl
MIME-Version: 1.0
Content-Type: application/x-perl; name="test2.pl"
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline; filename="test2.pl"
Content-Transfer-Encoding: base64
Content-Length: 358
Download test2.pl
text/x-perl 358b
#!/usr/bin/env perl use strict; use warnings; use 5.020; use MooseX::Types::Moose 'Int'; use MooseX::Types::Structured 'Dict'; use MooseX::Types::Util 'has_available_type_export'; use Test::More; sub check { my ($type_name) = @_; ok(has_available_type_export('main',$type_name),"ok for $type_name"); } check('Int'); check('Dict'); done_testing();
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-28521-1427900567-138.103247-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 113
Download (untitled) / with headers
text/plain 113b
Ilmari pointed out that it's Sub::Exporter::ForMethods (used via its method_installer) that's wrapping the subs.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-28521-1427900567-138.103247-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
X-RT-Interface: Web
References: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org> <rt-4.0.18-28521-1427900567-138.103247-0-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1427901271-27485-2"
Message-ID: <rt-4.0.18-27485-1427901271-164.103247-0-0 [...] rt.cpan.org>
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
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: 30
And here's a patch, with test.
MIME-Version: 1.0
Subject: 0001-fix-rt-103247-re-bless-installed-type-subs.patch
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Type: text/x-patch; name="0001-fix-rt-103247-re-bless-installed-type-subs.patch"
Content-Disposition: inline; filename="0001-fix-rt-103247-re-bless-installed-type-subs.patch"
Content-Transfer-Encoding: binary
Content-Length: 2458
From c532e4c2fbf7c481ca264232db7d228ec83ebd37 Mon Sep 17 00:00:00 2001 From: Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> Date: Wed, 1 Apr 2015 16:13:25 +0100 Subject: [PATCH] fix rt #103247: re-bless installed type subs --- lib/MooseX/Types/Structured.pm | 33 ++++++++++++++++++++++++++++++++- t/regressions/02-blessed-type-subs.t | 8 ++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 t/regressions/02-blessed-type-subs.t diff --git a/lib/MooseX/Types/Structured.pm b/lib/MooseX/Types/Structured.pm index d639aaf..fba1ad8 100644 --- a/lib/MooseX/Types/Structured.pm +++ b/lib/MooseX/Types/Structured.pm @@ -15,12 +15,43 @@ use Scalar::Util qw(blessed); use namespace::clean 0.08; use MooseX::Types 0.22 -declare => [qw(Dict Map Tuple Optional)]; use Sub::Exporter 0.982 -setup => { - installer => method_installer, + installer => \&mxtype_installer, exports => [ qw(Dict Map Tuple Optional slurpy) ], }; use if MooseX::Types->VERSION >= 0.42, 'namespace::autoclean' => -except => 'import'; # TODO: https://github.com/rjbs/Sub-Exporter/issues/8 +# MooseX::Types requires that the type subs be blessed into a special +# package; method_installer wraps the coderefs, so the things we +# install are not blessed. This installed remembers what was blessed, +# and re-blesses whatever was installed +sub mxtype_installer { + my ($arg,$to_export) = @_; + + my $scan = sub { + for (my $i = 0; $i < @$to_export; $i += 2) { + my ($as, $code) = @$to_export[ $i, $i+1 ]; + next if ref $as; + $_[0]->($i,$code); + } + }; + my @blesses; + $scan->( + sub{ + $blesses[$_[0]] = blessed($_[1]); + } + ); + + method_installer()->($arg,$to_export); + + $scan->( + sub{ + my $class = $blesses[$_[0]] or return; + bless $_[1],$class; + } + ); +} + =head1 SYNOPSIS The following is example usage for this module. diff --git a/t/regressions/02-blessed-type-subs.t b/t/regressions/02-blessed-type-subs.t new file mode 100644 index 0000000..370e71d --- /dev/null +++ b/t/regressions/02-blessed-type-subs.t @@ -0,0 +1,8 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests=>1; +use MooseX::Types::Structured 'Dict'; +use MooseX::Types::Util 'has_available_type_export'; + +ok(has_available_type_export('main','Dict'),"Dict is recognized"); -- 2.0.5
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-27485-1427901271-164.103247-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org> <rt-4.0.18-28521-1427900567-138.103247-0-0 [...] rt.cpan.org> <rt-4.0.18-27485-1427901271-164.103247-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-27477-1427902209-1101.103247-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 144
Download (untitled) / with headers
text/plain 144b
I've reported the bug to sub:exporter::formethods, https://github.com/rjbs/Sub-Exporter-ForMethods/issues/1 fixing it in both places won't hurt
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-27477-1427902209-1101.103247-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org> <rt-4.0.18-28521-1427900567-138.103247-0-0 [...] rt.cpan.org> <rt-4.0.18-27485-1427901271-164.103247-0-0 [...] rt.cpan.org> <rt-4.0.18-27477-1427902209-1101.103247-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-28521-1427906639-1980.103247-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 477
Download (untitled) / with headers
text/plain 477b
On 2015-04-01 08:30:09, DAKKAR wrote: Show quoted text
> I've reported the bug to sub:exporter::formethods, > https://github.com/rjbs/Sub-Exporter-ForMethods/issues/1 > > fixing it in both places won't hurt
wow you're fast, I haven't even woken up yet :) What version of Moose are you running? There was a fix for blessed subs there in version 2.1005 -- and I'm running the newest version of everything on my dev box, and can't repro this issue (or I wouldn't have released it like this) :D
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-28521-1427906639-1980.103247-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org> <rt-4.0.18-28521-1427900567-138.103247-0-0 [...] rt.cpan.org> <rt-4.0.18-27485-1427901271-164.103247-0-0 [...] rt.cpan.org> <rt-4.0.18-27477-1427902209-1101.103247-0-0 [...] rt.cpan.org> <rt-4.0.18-28521-1427906639-1980.103247-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-30976-1427907280-1075.103247-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 583
Download (untitled) / with headers
text/plain 583b
On Wed Apr 01 12:43:59 2015, ETHER wrote: Show quoted text
> What version of Moose are you running?
I'm running the latest released version of everything: perlbrew lib create perl-5.20.1@test perlbrew use perl-5.20.1@test cpanm --installdeps MooseX::Types::Structured The problem is at https://metacpan.org/source/RJBS/Sub-Exporter-ForMethods-0.100051/lib/Sub/Exporter/ForMethods.pm#L27 When using Sub::Exporter::ForMethods, the code-refs that get installed are different than the ones that get picked up by Sub::Exporter. My patch blesses the new ones in the same package as the old ones.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-21156-1427908125-1673.103247-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 177
Download (untitled) / with headers
text/plain 177b
On 2015-04-01 08:00:07, DAKKAR wrote: Show quoted text
> Attached is a test case.
Could you possibly include the output from this test? I have not been able to reproduce what you're seeing.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-25667-1427910168-801.103247-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 146
Download (untitled) / with headers
text/plain 146b
I released a new version that avoids method_installer for now, but I'm leaving this ticket open to try to gain some more insight into the problem.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-25667-1427910168-801.103247-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org> <rt-4.0.18-25667-1427910168-801.103247-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-8872-1427924690-134.103247-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 1583
Download (untitled) / with headers
text/plain 1.5k
On Wed Apr 01 13:42:48 2015, ETHER wrote: Show quoted text
> I released a new version that avoids method_installer for now, but I'm > leaving this ticket open to try to gain some more insight into the > problem.
I'm quite surprised that you can't reproduce the problem, since I've seen it on a few different machines... Anyway: the test script passes with 0.30 and 0.33, fails with 0.31 and 0.32: $ cpanm MooseX::Types::Structured@0.30 $ perl test.pl ok 1 - ok for Int ok 2 - ok for Dict 1..2 $ cpanm MooseX::Types::Structured@0.31 $ perl test.pl ok 1 - ok for Int not ok 2 - ok for Dict # Failed test 'ok for Dict' # at /tmp/test.pl line 11. 1..2 # Looks like you failed 1 test of 2. $ cpanm MooseX::Types::Structured@0.32 $ perl test.pl ok 1 - ok for Int not ok 2 - ok for Dict # Failed test 'ok for Dict' # at /tmp/test.pl line 11. 1..2 # Looks like you failed 1 test of 2. $ cpanm MooseX::Types::Structured@0.33 $ perl test.pl ok 1 - ok for Int ok 2 - ok for Dict 1..2 The Dict subroutine in the main namespace is not blessed when exported via the method_exporter (which is not surprising, seeing as how that exporter is implemented). I'm not sure why the method_installer was used, since none of the benefits in its documentation seem to apply: - adding a named stack frame is not useful for type constraints - non being cleaned by namespace::autoclean seems counter-productive to me I'll be out of the house for a few days, with limited internet connectivity, so I may not respond quickly until next Tuesday or Wednesday.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-8872-1427924690-134.103247-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org> <rt-4.0.18-25667-1427910168-801.103247-0-0 [...] rt.cpan.org> <rt-4.0.18-8872-1427924690-134.103247-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-703-1437179479-1869.103247-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 777
Download (untitled) / with headers
text/plain 777b
On 2015-04-01 14:44:50, DAKKAR wrote: Show quoted text
> On Wed Apr 01 13:42:48 2015, ETHER wrote:
> > I released a new version that avoids method_installer for now, but I'm > > leaving this ticket open to try to gain some more insight into the > > problem.
> > I'm quite surprised that you can't reproduce the problem, since I've > seen it on a few different machines...
If you can still reproduce the problem, can you find the versions you have of: - MooseX::Types - namespace::clean - namespace::autoclean - Moose I suspect that what you were hitting was what I changed in MooseX::Types 0.44 (which essentially is what rjbs just implemented directly in Sub::Exporter::ForMethods 0.100052 as the 'rebless' option). So I was running a more recent MXT, and could not reproduce what you had.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-703-1437179479-1869.103247-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-8887-1427900407-1271.0-0-0 [...] rt.cpan.org> <rt-4.0.18-25667-1427910168-801.103247-0-0 [...] rt.cpan.org> <rt-4.0.18-8872-1427924690-134.103247-0-0 [...] rt.cpan.org> <rt-4.0.18-703-1437179479-1869.103247-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-10188-1437207614-1736.103247-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 69
I can no longer reproduce the problem (yay!). Thank you for the help!


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.