Skip Menu |

This queue is for tickets about the namespace-sweep CPAN distribution.

Report information
The Basics
Id: 78816
Status: resolved
Priority: 0/
Queue: namespace-sweep

People
Owner: Nobody in particular
Requestors: perl [...] toby.ink
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.004
Fixed in: (no value)



Subject: interaction with Moo
HTML::Inject <https://metacpan.org/module/HTML::Inject> uses Moo and namespace::sweep. As you can see from CPAN testers <http:// www.cpantesters.org/distro/H/HTML-Inject.html> this seems to introduce an odd interaction. Basically Moo will upgrade itself to a Moose object if you attempt to call ->meta on the class. namespace::sweep attempts to call ->meta. In HTML::Inject's case this manifests itself as an undeclared dependency on Moose. So while neither Moo nor namespace::sweep requires Moose, the combination of them does! On a related note, it seems to be the recommendation from the Moose/MOP crowd *not* to call ->meta to get the metaclass for a class. This is because Class::MOP/Moose classes can rename their meta method to something else. Instead, you're supposed to use Class::MOP::class_of ($class) to get the metaclass. A test case and patch are attached, but further investigation may be required with regards to how it interacts with *Mouse*!
Subject: namespace-sweep-moo.diff
--- /home/tai/perl5/perlbrew/perls/thr-5.16.0/lib/site_perl/5.16.0/namespace/sweep.pm 2012-06-15 17:59:19.000000000 +0100 +++ namespace/sweep.pm 2012-08-06 19:09:45.639065761 +0100 @@ -67,9 +67,10 @@ }; my %keep; - if ( $cleanee->can( 'meta' ) ) { + my $class_of = UNIVERSAL::can('Class::MOP', 'can') && Class::MOP->can('class_of'); + if ( $class_of ) { # look for moose-ish composed methods - my $meta = $cleanee->meta; + my $meta = $class_of->($cleanee); if ( blessed $meta && $meta->can( 'get_all_method_names' ) ) { %keep = map { $_ => 1 } $meta->get_all_method_names; }
Subject: namespace-sweep-moo.t
use Test::More tests => 1; { package Local::Cow; use Moo; use namespace::sweep; } ok not $INC{'Moose.pm'};
From: chip [...] pobox.com
Is there no way to query Moo to get a list of methods, though? It seems the proposed patch just treats Moo like a bare package.
On 2012-08-30T04:38:48+01:00, CHIPS wrote: Show quoted text
> Is there no way to query Moo to get a list of methods, though? It > seems the proposed patch just treats Moo like a bare package.
Moo doesn't provide the reflection features of Moose. It just "inflates" classes to full Moose classes when ->meta is called.
Resolved in 0.006.