Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 344ef42fc3020a5c4b539718fbf1436300f325dd 1 parent 2e49125
Chris Weyl authored October 26, 2009
2  lib/namespace/autoclean.pm
@@ -130,7 +130,7 @@ sub import {
130 130
             $extra{ $method } = 1;
131 131
         }
132 132
 
133  
-        my @symbols = keys %{ $meta->get_all_package_symbols('CODE') };
  133
+        my @symbols = grep { !/^\(/ } keys %{ $meta->get_all_package_symbols('CODE') };
134 134
         namespace::clean->clean_subroutines($cleanee, keys %extra, grep { !$methods{$_} } @symbols);
135 135
     };
136 136
 }
43  t/overloads.t
... ...
@@ -0,0 +1,43 @@
  1
+#!/usr/bin/perl
  2
+
  3
+=head1 NAME
  4
+
  5
+overloads.t - Make sure we don't klobber overloaded functions
  6
+
  7
+=head1 DESCRIPTION 
  8
+
  9
+This test exercises namespace::autoclean with overloaded operators; making
  10
+sure we don't klobber them.
  11
+
  12
+=cut
  13
+
  14
+{
  15
+    package TestOverload;
  16
+
  17
+    use Moose;
  18
+    use namespace::autoclean;
  19
+    use overload '""' => sub { shift->id         }, fallback => 1;
  20
+    use overload '+'  => sub { (shift) + (shift) }, fallback => 1;
  21
+
  22
+    has id => (is => 'ro', default => 'bar');
  23
+
  24
+    __PACKAGE__->meta->make_immutable;
  25
+}
  26
+
  27
+use strict;
  28
+use warnings;
  29
+
  30
+use Test::More tests => 3;
  31
+
  32
+my $one = TestOverload->new;
  33
+isa_ok $one => 'TestOverload';
  34
+
  35
+is $one->id, 'bar', 'id is "bar"';
  36
+is "$one",   'bar', 'id stringifies to "bar"';
  37
+
  38
+__END__
  39
+
  40
+=head1 AUTHOR
  41
+
  42
+Chris Weyl  <cweyl@alumni.drew.edu>
  43
+

6 notes on commit 344ef42

Chip Salzenberg

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

Chris Weyl
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 :)

Mike Friedman

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.

Chip Salzenberg

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

Mike Friedman

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.

Chip Salzenberg

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

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