r36534 - in /branches/upstream/libnamespace-autoclean-perl/current: Changes LICENSE MANIFEST META.yml Makefile.PL README dist.ini lib/namespace/autoclean.pm t/matchclean.t

ryan52-guest at users.alioth.debian.org ryan52-guest at users.alioth.debian.org
Thu May 28 02:10:05 UTC 2009


Author: ryan52-guest
Date: Thu May 28 02:09:58 2009
New Revision: 36534

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=36534
Log:
[svn-upgrade] Integrating new upstream version, libnamespace-autoclean-perl (0.07)

Added:
    branches/upstream/libnamespace-autoclean-perl/current/t/matchclean.t
Modified:
    branches/upstream/libnamespace-autoclean-perl/current/Changes
    branches/upstream/libnamespace-autoclean-perl/current/LICENSE
    branches/upstream/libnamespace-autoclean-perl/current/MANIFEST
    branches/upstream/libnamespace-autoclean-perl/current/META.yml
    branches/upstream/libnamespace-autoclean-perl/current/Makefile.PL
    branches/upstream/libnamespace-autoclean-perl/current/README
    branches/upstream/libnamespace-autoclean-perl/current/dist.ini
    branches/upstream/libnamespace-autoclean-perl/current/lib/namespace/autoclean.pm

Modified: branches/upstream/libnamespace-autoclean-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-autoclean-perl/current/Changes?rev=36534&op=diff
==============================================================================
--- branches/upstream/libnamespace-autoclean-perl/current/Changes (original)
+++ branches/upstream/libnamespace-autoclean-perl/current/Changes Thu May 28 02:09:58 2009
@@ -1,3 +1,7 @@
+0.07  Wed, 27 May 2009 22:27:46 +0200
+ * Drop the useless Class::MOP::class_of call (Chris Prather).
+ * Extend -also to make it accept coderefs and regexen (Kent Fredric).
+
 0.06  Wed, 20 May 2009 15:14:36 +0200
  * Allow selection of explicit cleanee (Shawn M Moore).
 

Modified: branches/upstream/libnamespace-autoclean-perl/current/LICENSE
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-autoclean-perl/current/LICENSE?rev=36534&op=diff
==============================================================================
--- branches/upstream/libnamespace-autoclean-perl/current/LICENSE (original)
+++ branches/upstream/libnamespace-autoclean-perl/current/LICENSE Thu May 28 02:09:58 2009
@@ -1,9 +1,9 @@
 This software is copyright (c) 2009 by Florian Ragwitz.
 
 This is free software; you can redistribute it and/or modify it under
-the same terms as perl itself.
-
-Terms of Perl itself
+the same terms as the Perl 5 programming language system itself.
+
+Terms of the Perl programming language system itself
 
 a) the GNU General Public License as published by the Free
    Software Foundation; either version 1, or (at your option) any

Modified: branches/upstream/libnamespace-autoclean-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-autoclean-perl/current/MANIFEST?rev=36534&op=diff
==============================================================================
--- branches/upstream/libnamespace-autoclean-perl/current/MANIFEST (original)
+++ branches/upstream/libnamespace-autoclean-perl/current/MANIFEST Thu May 28 02:09:58 2009
@@ -9,4 +9,5 @@
 t/also.t
 t/basic.t
 t/cleanee.t
+t/matchclean.t
 t/role.t

Modified: branches/upstream/libnamespace-autoclean-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-autoclean-perl/current/META.yml?rev=36534&op=diff
==============================================================================
--- branches/upstream/libnamespace-autoclean-perl/current/META.yml (original)
+++ branches/upstream/libnamespace-autoclean-perl/current/META.yml Thu May 28 02:09:58 2009
@@ -1,12 +1,16 @@
 ---
-abstract: Keep imports out of your namespace
+abstract: 'Keep imports out of your namespace'
 author:
-- Florian Ragwitz <rafl at debian.org>
-generated_by: Dist::Zilla::Plugin::MetaYaml version 1.091260
+  - 'Florian Ragwitz <rafl at debian.org>'
+generated_by: 'Dist::Zilla::Plugin::MetaYAML version 1.091440'
 license: perl
+meta-spec:
+  url: http://module-build.sourceforge.net/META-spec-v1.4.html
+  version: 1.4
 name: namespace-autoclean
 requires:
-  B::Hooks::EndOfScope: '0.07'
-  Class::MOP: '0.80'
-  namespace::clean: '0.11'
-version: '0.06'
+  B::Hooks::EndOfScope: 0.07
+  Class::MOP: 0.80
+  List::Util: 0
+  namespace::clean: 0.11
+version: 0.07

Modified: branches/upstream/libnamespace-autoclean-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-autoclean-perl/current/Makefile.PL?rev=36534&op=diff
==============================================================================
--- branches/upstream/libnamespace-autoclean-perl/current/Makefile.PL (original)
+++ branches/upstream/libnamespace-autoclean-perl/current/Makefile.PL Thu May 28 02:09:58 2009
@@ -9,10 +9,11 @@
   NAME      => 'namespace::autoclean',
   AUTHOR    => 'Florian\ Ragwitz\ \<rafl\@debian\.org\>',
   ABSTRACT  => 'Keep imports out of your namespace',
-  VERSION   => '0.06',
+  VERSION   => '0.07',
   EXE_FILES => [ qw() ],
   (eval { ExtUtils::MakeMaker->VERSION(6.21) } ? (LICENSE => 'perl') : ()),
   PREREQ_PM    => {
+    "List::Util" => '0',
     "namespace::clean" => '0.11',
     "Class::MOP" => '0.80',
     "B::Hooks::EndOfScope" => '0.07',

Modified: branches/upstream/libnamespace-autoclean-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-autoclean-perl/current/README?rev=36534&op=diff
==============================================================================
--- branches/upstream/libnamespace-autoclean-perl/current/README (original)
+++ branches/upstream/libnamespace-autoclean-perl/current/README Thu May 28 02:09:58 2009
@@ -1,12 +1,12 @@
 
 
 This archive contains the distribution namespace-autoclean, version
-0.06:
+0.07:
 
   Keep imports out of your namespace
 
 This software is copyright (c) 2009 by Florian Ragwitz.
 
 This is free software; you can redistribute it and/or modify it under
-the same terms as perl itself.
+the same terms as the Perl 5 programming language system itself.
 

Modified: branches/upstream/libnamespace-autoclean-perl/current/dist.ini
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-autoclean-perl/current/dist.ini?rev=36534&op=diff
==============================================================================
--- branches/upstream/libnamespace-autoclean-perl/current/dist.ini (original)
+++ branches/upstream/libnamespace-autoclean-perl/current/dist.ini Thu May 28 02:09:58 2009
@@ -1,5 +1,5 @@
 name    = namespace-autoclean
-version = 0.06
+version = 0.07
 author  = Florian Ragwitz <rafl at debian.org>
 license = Perl_5
 copyright_holder = Florian Ragwitz
@@ -8,6 +8,7 @@
 namespace::clean = 0.11
 B::Hooks::EndOfScope = 0.07
 Class::MOP = 0.80
+List::Util = 0
 
 [@Filter]
 bundle = @Classic

Modified: branches/upstream/libnamespace-autoclean-perl/current/lib/namespace/autoclean.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-autoclean-perl/current/lib/namespace/autoclean.pm?rev=36534&op=diff
==============================================================================
--- branches/upstream/libnamespace-autoclean-perl/current/lib/namespace/autoclean.pm (original)
+++ branches/upstream/libnamespace-autoclean-perl/current/lib/namespace/autoclean.pm Thu May 28 02:09:58 2009
@@ -2,28 +2,53 @@
 use warnings;
 
 package namespace::autoclean;
-our $VERSION = '0.06';
+our $VERSION = '0.07';
 
 # ABSTRACT: Keep imports out of your namespace
 
 use Class::MOP;
 use B::Hooks::EndOfScope;
+use List::Util qw( first );
 use namespace::clean;
 
 
 sub import {
     my ($class, %args) = @_;
 
+    my $subcast = sub {
+        my $i = shift;
+        return $i if ref $i eq 'CODE';
+        return sub { $_ =~ $i } if ref $i eq 'Regexp';
+        return sub { $_ eq $i };
+    };
+
+    my $runtest = sub {
+        my ($code, $method_name) = @_;
+        local $_ = $method_name;
+        return $code->();
+    };
+
     my $cleanee = exists $args{-cleanee} ? $args{-cleanee} : scalar caller;
 
-    my @also = exists $args{-also}
+    my @also = map { $subcast->($_) } (
+        exists $args{-also}
         ? (ref $args{-also} eq 'ARRAY' ? @{ $args{-also} } : $args{-also})
-        : ();
+        : ()
+    );
+
     on_scope_end {
-        my $meta = Class::MOP::class_of($cleanee) || Class::MOP::Class->initialize($cleanee);
-        my %methods = map { ($_ => 1) } keys %{$meta->get_method_map};
+        my $meta = Class::MOP::Class->initialize($cleanee);
+        my %methods = map { ($_ => 1) } keys %{ $meta->get_method_map };
+        my %extra = ();
+
+        for my $method (keys %methods) {
+            next if exists $extra{$_};
+            next unless first { $runtest->($_, $method) } @also;
+            $extra{ $method } = 1;
+        }
+
         my @symbols = keys %{ $meta->get_all_package_symbols('CODE') };
-        namespace::clean->clean_subroutines($cleanee, @also, grep { !$methods{$_} } @symbols);
+        namespace::clean->clean_subroutines($cleanee, keys %extra, grep { !$methods{$_} } @symbols);
     };
 }
 
@@ -36,7 +61,7 @@
 
 =head1 VERSION
 
-version 0.06
+version 0.07
 
 =head1 SYNOPSIS
 
@@ -65,17 +90,6 @@
 after you C<use>d the pagma. It will also not touch anything that looks like a
 method, according to C<Class::MOP::Class::get_method_list>.
 
-Sometimes you don't want to clean imports only, but also helper functions
-you're using in your methods. The C<-also> switch can be used to declare a list
-of functions that should be removed additional to any imports:
-
-    use namespace::autoclean -also => ['some_function', 'another_function'];
-
-If only one function needs to be additionally cleaned the C<-also> switch also
-accepts a plain string:
-
-    use namespace::autoclean -also => 'some_function';
-
 If you're writing an exporter and you want to clean up after yourself (and your
 peers), you can use the C<-cleanee> switch to specify what package to clean:
 
@@ -99,7 +113,41 @@
 This software is copyright (c) 2009 by Florian Ragwitz.
 
 This is free software; you can redistribute it and/or modify it under
-the same terms as perl itself.
+the same terms as the Perl 5 programming language system itself.
+
+=head1 PARAMETERS
+
+=head2 -also => [ ITEM | REGEX | SUB, .. ]
+
+=head2 -also => ITEM
+
+=head2 -also => REGEX
+
+=head2 -also => SUB
+
+Sometimes you don't want to clean imports only, but also helper functions
+you're using in your methods. The C<-also> switch can be used to declare a list
+of functions that should be removed additional to any imports:
+
+    use namespace::autoclean -also => ['some_function', 'another_function'];
+
+If only one function needs to be additionally cleaned the C<-also> switch also
+accepts a plain string:
+
+    use namespace::autoclean -also => 'some_function';
+
+In some situations, you may wish for a more I<powerful> cleaning solution.
+
+The C<-also> switch can take a Regex or a CodeRef to match against local
+function names to clean.
+
+    use namespace::autoclean -also => qr/^_/
+
+    use namespace::autoclean -also => sub { $_ =~ m{^_} };
+
+    use namespace::autoclean -also => [qr/^_/ , qr/^hidden_/ ];
+
+    use namespace::autoclean -also => [sub { $_ =~ m/^_/ or $_ =~ m/^hidden/ }, sub { uc($_) == $_ } ];
 
 =head1 SEE ALSO
 

Added: branches/upstream/libnamespace-autoclean-perl/current/t/matchclean.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-autoclean-perl/current/t/matchclean.t?rev=36534&op=file
==============================================================================
--- branches/upstream/libnamespace-autoclean-perl/current/t/matchclean.t (added)
+++ branches/upstream/libnamespace-autoclean-perl/current/t/matchclean.t Thu May 28 02:09:58 2009
@@ -1,0 +1,34 @@
+use strict;
+use warnings;
+use Test::More tests => 6;
+
+{
+
+    package Foo;
+    use namespace::autoclean -also => qr/^_/;
+    use namespace::autoclean -also => sub { $_ =~ m{x} and $_ !~ m{y} };
+    sub _hidden               { }
+    sub xsubs_are_bad         { }
+    sub ysubs_are_good        { }
+    sub xsubs_with_y_are_good { }
+}
+{
+
+    package Bar;
+    use namespace::autoclean -also =>
+      [ qr/^_/, sub { $_ =~ m{x} and $_ !~ m{y} } ];
+    sub _hidden               { }
+    sub xsubs_are_bad         { }
+    sub ysubs_are_good        { }
+    sub xsubs_with_y_are_good { }
+
+}
+
+ok( !Foo->can('_hidden'),              '-also regex works' );
+ok( !Foo->can('xsubs_are_bad'),        '-also sub works' );
+ok( Foo->can('xsubs_with_y_are_good'), '-also sub doesnt overclean' );
+
+ok( !Bar->can('_hidden'),              '-also list with regex works' );
+ok( !Bar->can('xsubs_are_bad'),        '-also list with sub works' );
+ok( Bar->can('xsubs_with_y_are_good'), '-also list with sub doesnt overclean' );
+




More information about the Pkg-perl-cvs-commits mailing list