r17718 - in /trunk/libnamespace-clean-perl: Changes META.yml Makefile.PL README debian/changelog lib/namespace/clean.pm t/00-basic.t

roberto at users.alioth.debian.org roberto at users.alioth.debian.org
Mon Mar 17 02:57:39 UTC 2008


Author: roberto
Date: Mon Mar 17 02:57:38 2008
New Revision: 17718

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=17718
Log:
* New upstream release.

Modified:
    trunk/libnamespace-clean-perl/Changes
    trunk/libnamespace-clean-perl/META.yml
    trunk/libnamespace-clean-perl/Makefile.PL
    trunk/libnamespace-clean-perl/README
    trunk/libnamespace-clean-perl/debian/changelog
    trunk/libnamespace-clean-perl/lib/namespace/clean.pm
    trunk/libnamespace-clean-perl/t/00-basic.t

Modified: trunk/libnamespace-clean-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnamespace-clean-perl/Changes?rev=17718&op=diff
==============================================================================
--- trunk/libnamespace-clean-perl/Changes (original)
+++ trunk/libnamespace-clean-perl/Changes Mon Mar 17 02:57:38 2008
@@ -1,3 +1,10 @@
+
+    [0.08] Sun Mar  9 22:01:01 CET 2008
+        - Added explicit cleanup behaviour
+
+    [0.07] Sun Mar  9 20:13:33 CET 2008
+        - Switched from Filter::EOF to a much saner implementation via
+          %^H and Scope::Guard. (mst & autobox)++ for this.
 
     [0.06] Wed Feb 20 15:09:00 CET 2008
         - Fixed 'uninitialized value in ref-to-glob cast' error

Modified: trunk/libnamespace-clean-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnamespace-clean-perl/META.yml?rev=17718&op=diff
==============================================================================
--- trunk/libnamespace-clean-perl/META.yml (original)
+++ trunk/libnamespace-clean-perl/META.yml Mon Mar 17 02:57:38 2008
@@ -18,9 +18,9 @@
 provides: 
   namespace::clean: 
     file: lib/namespace/clean.pm
-    version: 0.06
+    version: 0.08
 requires: 
-  Filter::EOF: 0.02
+  Scope::Guard: 0.02
   Symbol: 0
 tests: t/*.t t_author/*.t
-version: 0.06
+version: 0.08

Modified: trunk/libnamespace-clean-perl/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnamespace-clean-perl/Makefile.PL?rev=17718&op=diff
==============================================================================
--- trunk/libnamespace-clean-perl/Makefile.PL (original)
+++ trunk/libnamespace-clean-perl/Makefile.PL Mon Mar 17 02:57:38 2008
@@ -12,7 +12,7 @@
 build_requires  q{Test::More},                  '0.62';
 build_requires  q{FindBin},                     0;
 
-requires        q{Filter::EOF},                 '0.02';
+requires        q{Scope::Guard},                '0.02';
 requires        q{Symbol},                      0;
 
 auto_provides;

Modified: trunk/libnamespace-clean-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnamespace-clean-perl/README?rev=17718&op=diff
==============================================================================
--- trunk/libnamespace-clean-perl/README (original)
+++ trunk/libnamespace-clean-perl/README Mon Mar 17 02:57:38 2008
@@ -2,7 +2,7 @@
     namespace::clean - Keep imports and functions out of your namespace
 
 VERSION
-    0.06
+    0.08
 
 SYNOPSIS
       package Foo;
@@ -35,6 +35,7 @@
       1;
 
 DESCRIPTION
+  Keeping packages clean
     When you define a function, or import one, into a Perl package, it will
     naturally also be available as a method. This does not per se cause
     problems, but it can complicate subclassing and, for example, plugin
@@ -59,14 +60,44 @@
     If you just want to "-except" a single sub, you can pass it directly.
     For more than one value you have to use an array reference.
 
+  Explicitely removing functions when your scope is compiled
+    It is also possible to explicitely tell "namespace::clean" what packages
+    to remove when the surrounding scope has finished compiling. Here is an
+    example:
+
+      package Foo;
+      use strict;
+
+      # blessed NOT available
+
+      sub my_class {
+          use Scalar::Util qw( blessed );
+          use namespace::clean qw( blessed );
+
+          # blessed available
+          return blessed shift;
+      }
+
+      # blessed NOT available
+
+  Moose
+    When using "namespace::clean" together with Moose you want to keep the
+    installed "meta" method. So your classes should look like:
+
+      package Foo;
+      use Moose;
+      use namespace::clean -except => 'meta';
+      ...
+
+    Same goes for Moose::Role.
+
 METHODS
     You shouldn't need to call any of these. Just "use" the package at the
     appropriate place.
 
   import
-    Makes a snapshot of the current defined functions and registers a
-    Filter::EOF cleanup routine to remove those symbols at the end of the
-    compile-time.
+    Makes a snapshot of the current defined functions and installs a
+    Scope::Guard in the current scope to invoke the cleanups.
 
   unimport
     This method will be called when you do a
@@ -101,7 +132,7 @@
     use "undef" instead.
 
 SEE ALSO
-    Filter::EOF
+    Scope::Guard
 
 AUTHOR AND COPYRIGHT
     Robert 'phaylon' Sedlacek "<rs at 474.at>", with many thanks to Matt S

Modified: trunk/libnamespace-clean-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnamespace-clean-perl/debian/changelog?rev=17718&op=diff
==============================================================================
--- trunk/libnamespace-clean-perl/debian/changelog (original)
+++ trunk/libnamespace-clean-perl/debian/changelog Mon Mar 17 02:57:38 2008
@@ -1,3 +1,9 @@
+libnamespace-clean-perl (0.08-1) unstable; urgency=low
+
+  * New upstream release.
+
+ -- Roberto C. Sanchez <roberto at debian.org>  Sun, 16 Mar 2008 22:57:15 -0400
+
 libnamespace-clean-perl (0.06-1) unstable; urgency=low
 
   [ gregor herrmann ]

Modified: trunk/libnamespace-clean-perl/lib/namespace/clean.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnamespace-clean-perl/lib/namespace/clean.pm?rev=17718&op=diff
==============================================================================
--- trunk/libnamespace-clean-perl/lib/namespace/clean.pm (original)
+++ trunk/libnamespace-clean-perl/lib/namespace/clean.pm Mon Mar 17 02:57:38 2008
@@ -9,18 +9,20 @@
 use warnings;
 use strict;
 
-use vars              qw( $VERSION $STORAGE_VAR );
-use Symbol            qw( qualify_to_ref );
-use Filter::EOF;
+use vars        qw( $VERSION $STORAGE_VAR $SCOPE_HOOK_KEY $SCOPE_EXPLICIT );
+use Symbol      qw( qualify_to_ref );
+use Scope::Guard;
 
 =head1 VERSION
 
-0.06
-
-=cut
-
-$VERSION     = 0.06;
-$STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE';
+0.08
+
+=cut
+
+$VERSION         = 0.08;
+$STORAGE_VAR     = '__NAMESPACE_CLEAN_STORAGE';
+$SCOPE_HOOK_KEY  = 'namespace_clean_SCOPING';
+$SCOPE_EXPLICIT  = 'namespace_clean_EXPLICIT';
 
 =head1 SYNOPSIS
 
@@ -55,6 +57,8 @@
 
 =head1 DESCRIPTION
 
+=head2 Keeping packages clean
+
 When you define a function, or import one, into a Perl package, it will
 naturally also be available as a method. This does not per se cause
 problems, but it can complicate subclassing and, for example, plugin
@@ -79,6 +83,39 @@
 If you just want to C<-except> a single sub, you can pass it directly.
 For more than one value you have to use an array reference.
 
+=head2 Explicitely removing functions when your scope is compiled
+
+It is also possible to explicitely tell C<namespace::clean> what packages
+to remove when the surrounding scope has finished compiling. Here is an
+example:
+
+  package Foo;
+  use strict;
+
+  # blessed NOT available
+
+  sub my_class {
+      use Scalar::Util qw( blessed );
+      use namespace::clean qw( blessed );
+
+      # blessed available
+      return blessed shift;
+  }
+
+  # blessed NOT available
+
+=head2 Moose
+
+When using C<namespace::clean> together with L<Moose> you want to keep
+the installed C<meta> method. So your classes should look like:
+
+  package Foo;
+  use Moose;
+  use namespace::clean -except => 'meta';
+  ...
+
+Same goes for L<Moose::Role>.
+
 =head1 METHODS
 
 You shouldn't need to call any of these. Just C<use> the package at the
@@ -88,63 +125,86 @@
 
 =head2 import
 
-Makes a snapshot of the current defined functions and registers a 
-L<Filter::EOF> cleanup routine to remove those symbols at the end 
-of the compile-time.
-
-=cut
+Makes a snapshot of the current defined functions and installs a 
+L<Scope::Guard> in the current scope to invoke the cleanups.
+
+=cut
+
+my $RemoveSubs = sub {
+    my $cleanee = shift;
+    my $store   = shift;
+  SYMBOL:
+    for my $f (@_) {
+
+        # ignore already removed symbols
+        next SYMBOL if $store->{exclude}{ $f };
+        no strict 'refs';
+
+        # keep original value to restore non-code slots
+        {   no warnings 'uninitialized';    # fix possible unimports
+            local *__tmp = *{ ${ "${cleanee}::" }{ $f } };
+            delete ${ "${cleanee}::" }{ $f };
+        }
+
+      SLOT:
+        # restore non-code slots to symbol
+        for my $t (qw( SCALAR ARRAY HASH IO FORMAT )) {
+            next SLOT unless defined *__tmp{ $t };
+            *{ "${cleanee}::$f" } = *__tmp{ $t };
+        }
+    }
+};
 
 sub import {
-    my ($pragma, %args) = @_;
-
-    # calling class, all current functions and our storage
-    my $cleanee   = caller;
-    my $functions = $pragma->get_functions($cleanee);
-    my $store     = $pragma->get_class_store($cleanee);
-
-    # except parameter can be array ref or single value
-    my %except = map {( $_ => 1 )} (
-        $args{ -except }
-        ? ( ref $args{ -except } eq 'ARRAY' ? @{ $args{ -except } } : $args{ -except } )
-        : ()
-    );
-
-    # register symbols for removal, if they have a CODE entry
-    for my $f (keys %$functions) {
-        next if     $except{ $f };
-        next unless    $functions->{ $f } 
-                and *{ $functions->{ $f } }{CODE};
-        $store->{remove}{ $f } = 1;
-    }
-
-    # register EOF handler on first call to import
-    unless ($store->{handler_is_installed}) {
-        Filter::EOF->on_eof_call(sub {
-          SYMBOL:
-            for my $f (keys %{ $store->{remove} }) {
-
-                # ignore already removed symbols
-                next SYMBOL if $store->{exclude}{ $f };
-                no strict 'refs';
-
-                # keep original value to restore non-code slots
-                {   no warnings 'uninitialized';    # fix possible unimports
-                    local *__tmp = *{ ${ "${cleanee}::" }{ $f } };
-                    delete ${ "${cleanee}::" }{ $f };
-                }
-
-              SLOT:
-                # restore non-code slots to symbol
-                for my $t (qw( SCALAR ARRAY HASH IO FORMAT )) {
-                    next SLOT unless defined *__tmp{ $t };
-                    *{ "${cleanee}::$f" } = *__tmp{ $t };
-                }
-            }
+    my ($pragma, @args) = @_;
+    $^H |= 0x120000;
+
+    my (%args, $is_explicit);
+    if (@args and $args[0] =~ /^\-/) {
+        %args = @args;
+        @args = ();
+    }
+    elsif (@args) {
+        $is_explicit++;
+    }
+
+    my $cleanee = caller;
+    if ($is_explicit) {
+        $^H{ $SCOPE_EXPLICIT } = Scope::Guard->new(sub {
+            $RemoveSubs->($cleanee, {}, @args);
         });
-        $store->{handler_is_installed} = 1;
-    }
-
-    return 1;
+    }
+    else {
+
+        # calling class, all current functions and our storage
+        my $functions = $pragma->get_functions($cleanee);
+        my $store     = $pragma->get_class_store($cleanee);
+
+        # except parameter can be array ref or single value
+        my %except = map {( $_ => 1 )} (
+            $args{ -except }
+            ? ( ref $args{ -except } eq 'ARRAY' ? @{ $args{ -except } } : $args{ -except } )
+            : ()
+        );
+
+        # register symbols for removal, if they have a CODE entry
+        for my $f (keys %$functions) {
+            next if     $except{ $f };
+            next unless    $functions->{ $f } 
+                    and *{ $functions->{ $f } }{CODE};
+            $store->{remove}{ $f } = 1;
+        }
+
+        # register EOF handler on first call to import
+        unless ($store->{handler_is_installed}) {
+            $^H{ $SCOPE_HOOK_KEY } = Scope::Guard->new(sub {
+                $RemoveSubs->($cleanee, $store, keys %{ $store->{remove} });
+            });
+            $store->{handler_is_installed} = 1;
+        }
+
+        return 1;
+    }
 }
 
 =head2 unimport
@@ -227,7 +287,7 @@
 
 =head1 SEE ALSO
 
-L<Filter::EOF>
+L<Scope::Guard>
 
 =head1 AUTHOR AND COPYRIGHT
 
@@ -241,4 +301,5 @@
 
 =cut
 
-1;
+no warnings;
+'Danger! Laws of Thermodynamics may not apply.'

Modified: trunk/libnamespace-clean-perl/t/00-basic.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libnamespace-clean-perl/t/00-basic.t?rev=17718&op=diff
==============================================================================
--- trunk/libnamespace-clean-perl/t/00-basic.t (original)
+++ trunk/libnamespace-clean-perl/t/00-basic.t Mon Mar 17 02:57:38 2008
@@ -10,7 +10,7 @@
 
 BEGIN { 
     ok( main->can('foo'), 'methods are there before cleanup' );
-    eval { use namespace::clean };
+    eval { require namespace::clean ;; namespace::clean->import };
     ok( !$@, 'module use ok' );
 }
 




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