Skip Menu |

This queue is for tickets about the Class-Method-Modifiers CPAN distribution.

Report information
The Basics
Id: 74569
Status: resolved
Priority: 0/
Queue: Class-Method-Modifiers

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

Bug Information
Severity: Normal
Broken in: 1.08
Fixed in: 1.09



Subject: Class::Method::Modifiers not marking modifications as methods
It appears that Class::Method::Modifiers isn't marking its methods as methods, such that namespace::(auto)?clean recognizes them as such: { package Foo; use namespace::autoclean; sub foo { print "normal foo sub\n"; } } { package Bar; use namespace::autoclean; sub foo { print "normal foo sub\n"; } { package Foo; use Class::Method::Modifiers; use namespace::autoclean; around foo => sub { print "wrapped foo sub\n" }; } } use Test::CleanNamespaces; namespaces_clean('Foo'); namespaces_clean('Bar'); __END__ $; perl cleannamespaces.pl not ok 1 - Foo contains no imported functions # Failed test 'Foo contains no imported functions' # at cleannamespaces.pl line 23. # remaining imports: [ # 'foo' # ] ok 2 - Bar contains no imported functions # Tests were run but no plan was declared and done_testing() was not seen. ...i.e. the 'foo' symbol is not doing __PACKAGE__->meta->add_method(foo => \&foo);
On Tue Jan 31 10:02:21 2012, ETHER wrote: Show quoted text
> It appears that Class::Method::Modifiers isn't marking its methods as > methods, such that namespace::(auto)?clean recognizes them as such:
Ok, this code helps clarify the problem: CMM modifies a sub in such a way that n::c now thinks that it is an uncleaned import. use strict; use warnings; use Test::More; use Class::MOP; use Data::Dumper; use Test::CleanNamespaces; sub symbols { my $ns = shift; my $meta = Class::MOP::class_of($ns) || Class::MOP::Class->initialize($ns); my %methods = map { ($_ => 1) } $meta->get_method_list; my @symbols = keys %{ $meta->get_all_package_symbols('CODE') || {} }; } sub imports { my $ns = shift; my $meta = Class::MOP::class_of($ns) || Class::MOP::Class->initialize($ns); my %methods = map { ($_ => 1) } $meta->get_method_list; my @symbols = keys %{ $meta->get_all_package_symbols('CODE') || {} }; my @imports = grep { !$methods{$_} } @symbols; } BEGIN { package Foo; sub foo { print "normal Foo::foo sub\n"; } } BEGIN { print "### Foo symbols initially: ", Dumper([ symbols('Foo') ]); print "### Foo imports initially: ", Dumper([ imports('Foo') ]); namespaces_clean('Foo'); } BEGIN { package Foo; use Class::Method::Modifiers; print "### redefining foo\n"; around foo => sub { print "wrapped foo sub\n" }; } print "### Foo symbols after modification: ", Dumper([ symbols('Foo') ]); print "### Foo imports after modification: ", Dumper([ imports('Foo') ]); namespaces_clean('Foo'); done_testing; __END__ ### Foo symbols initially: $VAR1 = [ 'foo' ]; ### Foo imports initially: $VAR1 = []; ok 1 - Foo contains no imported functions ### redefining foo ### Foo symbols after modification: $VAR1 = [ 'after', 'around', 'foo', 'before' ]; ### Foo imports after modification: $VAR1 = [ 'after', 'around', 'foo', 'before' ]; not ok 2 - Foo contains no imported functions # Failed test 'Foo contains no imported functions' # at external_clean.pl line 45. # remaining imports: [ # 'after', # 'around', # 'foo', # 'before' # ] 1..2 # Looks like you failed 1 test of 2. Further, once CMM tampers with 'foo', it also is showing up as an import, when initially it did not. Using namespace::autoclean inside the second 'package Foo' declaration does clean the begin/around/after subs, but it does not clean 'foo'; it does not seem possible to use namespace::clean anywhere, as no matter where it is placed, CMM reports the error "The method 'foo' is not found in the inheritance hierarchy for class Foo".
I'd be more inclined to make changes to ameloriate this issue if namespace::autoclean's documentation provided a recipe for installing subroutines into a package in such a way that it registers as a method that shouldn't be cleaned.
On Sun Feb 05 14:26:09 2012, SARTAK wrote: Show quoted text
> I'd be more inclined to make changes to ameloriate this issue if > namespace::autoclean's documentation provided a recipe for installing > subroutines into a package in such a way that it registers as a method > that shouldn't be cleaned.
I'll fix, as per #moose-dev discussion: 14:27 < rafl> can i tell you how to fix it and you'll put it into my docs at the place you would've expected it? :) 14:27 < rafl> cause it's just *$gv = subname $name => sub { ...; $original->(@_); ... } 14:27 < rafl> after importing subname from Sub::Name
RT-Send-CC: mst [...] shadowcat.co.uk
On Mon Feb 06 22:51:29 2012, ETHER wrote: Show quoted text
This patch (shipped in 1.09) makes CMM extremely noisy under any 5.8 perl. I have not yet investigated if the emited warnings are harmless or not.
Fix released as 1.09 on 2012-04-02.