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
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
#!/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();
Ilmari pointed out that it's Sub::Exporter::ForMethods (used via its method_installer) that's wrapping the subs.
And here's a patch, with test.
Subject: 0001-fix-rt-103247-re-bless-installed-type-subs.patch
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
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
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
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.
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.
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.
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.
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.
I can no longer reproduce the problem (yay!). Thank you for the help!