Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

don't wipe out overloaded functions (and add tests)

  • Loading branch information...
commit 344ef42fc3020a5c4b539718fbf1436300f325dd 1 parent 2e49125
@RsrchBoy authored
Showing with 44 additions and 1 deletion.
  1. +1 −1  lib/namespace/autoclean.pm
  2. +43 −0 t/overloads.t
View
2  lib/namespace/autoclean.pm
@@ -130,7 +130,7 @@ sub import {
$extra{ $method } = 1;
}
- my @symbols = keys %{ $meta->get_all_package_symbols('CODE') };
+ my @symbols = grep { !/^\(/ } keys %{ $meta->get_all_package_symbols('CODE') };
namespace::clean->clean_subroutines($cleanee, keys %extra, grep { !$methods{$_} } @symbols);
};
}
View
43 t/overloads.t
@@ -0,0 +1,43 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+overloads.t - Make sure we don't klobber overloaded functions
+
+=head1 DESCRIPTION
+
+This test exercises namespace::autoclean with overloaded operators; making
+sure we don't klobber them.
+
+=cut
+
+{
+ package TestOverload;
+
+ use Moose;
+ use namespace::autoclean;
+ use overload '""' => sub { shift->id }, fallback => 1;
+ use overload '+' => sub { (shift) + (shift) }, fallback => 1;
+
+ has id => (is => 'ro', default => 'bar');
+
+ __PACKAGE__->meta->make_immutable;
+}
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+
+my $one = TestOverload->new;
+isa_ok $one => 'TestOverload';
+
+is $one->id, 'bar', 'id is "bar"';
+is "$one", 'bar', 'id stringifies to "bar"';
+
+__END__
+
+=head1 AUTHOR
+
+Chris Weyl <cweyl@alumni.drew.edu>
+

6 comments on commit 344ef42

@chipdude

Whoa, you found this two years ago. I just did. Identical code too. :)

@RsrchBoy
Owner

Yeah -- it was slammed pretty hard over in https://rt.cpan.org/Public/Bug/Display.html?id=50938 ; and asking after that on the Moose mailing list found a difference of opinion between the core cabal members.

After that, I sort of gave up ever getting this in namespace-autolcean proper, and wrote MooseX::MarkAsMethods... But it would be significantly easier to have it in namespace::autoclean (not to mention being able to use it in non-Moose packages at that point, too).

Maybe I'll try another pull request; see how it goes this time :)

@friedo

This issue recently came up in a SO thread here. I think this qualifies as a genuine bug in namespace::autoclean, and I'm disappointed that this patch was rejected so long ago.

@chipdude

It does seem that namespace::autoclean is making itself obsolete, and will have to be replaced a la parent.pm vs base.pm

@friedo

I've written a new distribution called namespace::sweep which addresses this problem (and has some other nice features.) Repo here and blog post here.

@chipdude

Sweet, I'll evaluate for replacement of ns::ac

Please sign in to comment.
Something went wrong with that request. Please try again.