r31331 - in /branches/upstream/libnamespace-clean-perl/current: ./ inc/Module/ inc/Module/Install/ lib/namespace/ t/ t/lib/
antonio-guest at users.alioth.debian.org
antonio-guest at users.alioth.debian.org
Tue Mar 3 20:41:28 UTC 2009
Author: antonio-guest
Date: Tue Mar 3 20:41:23 2009
New Revision: 31331
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=31331
Log:
[svn-upgrade] Integrating new upstream version, libnamespace-clean-perl (0.11)
Added:
branches/upstream/libnamespace-clean-perl/current/t/05-explicit-cleanee.t
branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridge.pm
branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridgeDirect.pm
branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridgeExplicit.pm
branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeTarget.pm
Modified:
branches/upstream/libnamespace-clean-perl/current/Changes
branches/upstream/libnamespace-clean-perl/current/MANIFEST
branches/upstream/libnamespace-clean-perl/current/META.yml
branches/upstream/libnamespace-clean-perl/current/Makefile.PL
branches/upstream/libnamespace-clean-perl/current/README
branches/upstream/libnamespace-clean-perl/current/inc/Module/Install.pm
branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/AutoInstall.pm
branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Base.pm
branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Can.pm
branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Fetch.pm
branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Include.pm
branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Makefile.pm
branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Metadata.pm
branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Win32.pm
branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/WriteAll.pm
branches/upstream/libnamespace-clean-perl/current/lib/namespace/clean.pm
Modified: branches/upstream/libnamespace-clean-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/Changes?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/Changes (original)
+++ branches/upstream/libnamespace-clean-perl/current/Changes Tue Mar 3 20:41:23 2009
@@ -1,3 +1,11 @@
+ [0.11] Tue Mar 3 17:34:49 CET 2009
+ - Added -cleanee option to specify the package to clean (Closes
+ RT#41850).
+ - Added n:c->clean_subroutines($cleanee, @subs).
+
+ [0.10] Fri Feb 20 14:31:36 CET 2009
+ - Depend on B::Hooks::EndOfScope 0.07 to avoid segfaults and lost error
+ messages when something goes wrong.
[0.09] Wed Oct 22 17:48:49 CEST 2008
- Use B::Hooks::EndOfScope instead of %^H + Scope::Guard.
Modified: branches/upstream/libnamespace-clean-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/MANIFEST?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/MANIFEST (original)
+++ branches/upstream/libnamespace-clean-perl/current/MANIFEST Tue Mar 3 20:41:23 2009
@@ -20,6 +20,11 @@
t/02-inheritance.t
t/03-unimport.t
t/04-except.t
+t/05-explicit-cleanee.t
+t/lib/CleaneeBridge.pm
+t/lib/CleaneeBridgeDirect.pm
+t/lib/CleaneeBridgeExplicit.pm
+t/lib/CleaneeTarget.pm
t/lib/ExporterTest.pm
t/lib/FunctionWipeout.pm
t/lib/Inheritance.pm
Modified: branches/upstream/libnamespace-clean-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/META.yml?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/META.yml (original)
+++ branches/upstream/libnamespace-clean-perl/current/META.yml Tue Mar 3 20:41:23 2009
@@ -6,7 +6,7 @@
FindBin: 0
Test::More: 0.62
distribution_type: module
-generated_by: 'Module::Install version 0.77'
+generated_by: 'Module::Install version 0.79'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -16,13 +16,9 @@
directory:
- inc
- t
-provides:
- namespace::clean:
- file: lib/namespace/clean.pm
- version: 0.09
requires:
- B::Hooks::EndOfScope: 0
+ B::Hooks::EndOfScope: 0.07
Symbol: 0
resources:
license: http://dev.perl.org/licenses/
-version: 0.09
+version: 0.11
Modified: branches/upstream/libnamespace-clean-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/Makefile.PL?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/Makefile.PL (original)
+++ branches/upstream/libnamespace-clean-perl/current/Makefile.PL Tue Mar 3 20:41:23 2009
@@ -6,13 +6,13 @@
name q{namespace-clean};
license q{perl};
-author q{Robert 'phaylon' Sedlacek <rs at 474.at>};
+author q{Robert 'phaylon'' Sedlacek <rs at 474.at>};
all_from q{lib/namespace/clean.pm};
build_requires q{Test::More}, '0.62';
build_requires q{FindBin}, 0;
-requires q{B::Hooks::EndOfScope}, 0;
+requires q{B::Hooks::EndOfScope}, '0.07';
requires q{Symbol}, 0;
auto_provides;
Modified: branches/upstream/libnamespace-clean-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/README?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/README (original)
+++ branches/upstream/libnamespace-clean-perl/current/README Tue Mar 3 20:41:23 2009
@@ -2,7 +2,7 @@
namespace::clean - Keep imports and functions out of your namespace
VERSION
- 0.08
+ 0.11
SYNOPSIS
package Foo;
@@ -91,13 +91,44 @@
Same goes for Moose::Role.
+ Cleaning other packages
+ You can tell "namespace::clean" that you want to clean up another
+ package instead of the one importing. To do this you have to pass in the
+ "-cleanee" option like this:
+
+ package My::MooseX::namespace::clean;
+ use strict;
+
+ use namespace::clean (); # no cleanup, just load
+
+ sub import {
+ namespace::clean->import(
+ -cleanee => scalar(caller),
+ -except => 'meta',
+ );
+ }
+
+ If you don't care about "namespace::clean"s discover-and-"-except"
+ logic, and just want to remove subroutines, try "clean_subroutines".
+
METHODS
You shouldn't need to call any of these. Just "use" the package at the
appropriate place.
+ clean_subroutines
+ This exposes the actual subroutine-removal logic.
+
+ namespace::clean->clean_subroutines($cleanee, qw( subA subB ));
+
+ will remove "subA" and "subB" from $cleanee. Note that this will remove
+ the subroutines immediately and not wait for scope end. If you want to
+ have this effect at a specific time (e.g. "namespace::clean" acts on
+ scope compile end) it is your responsibility to make sure it runs at
+ that time.
+
import
Makes a snapshot of the current defined functions and installs a
- Scope::Guard in the current scope to invoke the cleanups.
+ B::Hooks::EndOfScope hook in the current scope to invoke the cleanups.
unimport
This method will be called when you do a
@@ -132,7 +163,7 @@
use "undef" instead.
SEE ALSO
- Scope::Guard
+ B::Hooks::EndOfScope
AUTHOR AND COPYRIGHT
Robert 'phaylon' Sedlacek "<rs at 474.at>", with many thanks to Matt S
Modified: branches/upstream/libnamespace-clean-perl/current/inc/Module/Install.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/inc/Module/Install.pm?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/inc/Module/Install.pm (original)
+++ branches/upstream/libnamespace-clean-perl/current/inc/Module/Install.pm Tue Mar 3 20:41:23 2009
@@ -30,7 +30,7 @@
# This is not enforced yet, but will be some time in the next few
# releases once we can make sure it won't clash with custom
# Module::Install extensions.
- $VERSION = '0.77';
+ $VERSION = '0.79';
*inc::Module::Install::VERSION = *VERSION;
@inc::Module::Install::ISA = __PACKAGE__;
@@ -250,7 +250,7 @@
sub load_extensions {
my ($self, $path, $top) = @_;
- unless ( grep { lc $_ eq lc $self->{prefix} } @INC ) {
+ unless ( grep { !ref $_ and lc $_ eq lc $self->{prefix} } @INC ) {
unshift @INC, $self->{prefix};
}
@@ -366,4 +366,4 @@
1;
-# Copyright 2008 Adam Kennedy.
+# Copyright 2008 - 2009 Adam Kennedy.
Modified: branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/AutoInstall.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/AutoInstall.pm?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/AutoInstall.pm (original)
+++ branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/AutoInstall.pm Tue Mar 3 20:41:23 2009
@@ -6,7 +6,7 @@
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.77';
+ $VERSION = '0.79';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
Modified: branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Base.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Base.pm?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Base.pm (original)
+++ branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Base.pm Tue Mar 3 20:41:23 2009
@@ -1,7 +1,7 @@
#line 1
package Module::Install::Base;
-$VERSION = '0.77';
+$VERSION = '0.79';
# Suspend handler for "redefined" warnings
BEGIN {
Modified: branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Can.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Can.pm?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Can.pm (original)
+++ branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Can.pm Tue Mar 3 20:41:23 2009
@@ -11,7 +11,7 @@
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.77';
+ $VERSION = '0.79';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
Modified: branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Fetch.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Fetch.pm?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Fetch.pm (original)
+++ branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Fetch.pm Tue Mar 3 20:41:23 2009
@@ -6,20 +6,20 @@
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.77';
+ $VERSION = '0.79';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
sub get_file {
my ($self, %args) = @_;
- my ($scheme, $host, $path, $file) =
+ my ($scheme, $host, $path, $file) =
$args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) {
$args{url} = $args{ftp_url}
or (warn("LWP support unavailable!\n"), return);
- ($scheme, $host, $path, $file) =
+ ($scheme, $host, $path, $file) =
$args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
}
Modified: branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Include.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Include.pm?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Include.pm (original)
+++ branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Include.pm Tue Mar 3 20:41:23 2009
@@ -6,7 +6,7 @@
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.77';
+ $VERSION = '0.79';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
Modified: branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Makefile.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Makefile.pm?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Makefile.pm (original)
+++ branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Makefile.pm Tue Mar 3 20:41:23 2009
@@ -7,7 +7,7 @@
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.77';
+ $VERSION = '0.79';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
@@ -64,7 +64,7 @@
my $self = shift;
my $clean = $self->makemaker_args->{clean} ||= {};
%$clean = (
- %$clean,
+ %$clean,
FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_),
);
}
@@ -73,7 +73,7 @@
my $self = shift;
my $realclean = $self->makemaker_args->{realclean} ||= {};
%$realclean = (
- %$realclean,
+ %$realclean,
FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_),
);
}
@@ -124,7 +124,7 @@
$self->configure_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ );
- # Generate the
+ # Generate the
my $args = $self->makemaker_args;
$args->{DISTNAME} = $self->name;
$args->{NAME} = $self->module_name || $self->name;
@@ -196,7 +196,7 @@
my $top_class = ref($self->_top) || '';
my $top_version = $self->_top->VERSION || '';
- my $preamble = $self->preamble
+ my $preamble = $self->preamble
? "# Preamble by $top_class $top_version\n"
. $self->preamble
: '';
Modified: branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Metadata.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Metadata.pm?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Metadata.pm (original)
+++ branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Metadata.pm Tue Mar 3 20:41:23 2009
@@ -6,7 +6,7 @@
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.77';
+ $VERSION = '0.79';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
@@ -176,18 +176,15 @@
"Did not provide a value to perl_version()"
);
- # Convert triple-part versions (eg, 5.6.1 or 5.8.9) to
- # numbers (eg, 5.006001 or 5.008009).
-
- $version =~ s/^(\d+)\.(\d+)\.(\d+)$/sprintf("%d.%03d%03d",$1,$2,$3)/e;
-
- $version =~ s/_.+$//;
- $version = $version + 0; # Numify
+ # Normalize the version
+ $version = $self->_perl_version($version);
+
+ # We don't support the reall old versions
unless ( $version >= 5.005 ) {
die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n";
}
+
$self->{values}{perl_version} = $version;
- return 1;
}
sub license {
@@ -451,9 +448,6 @@
while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
$pattern =~ s{\s+}{\\s+}g;
if ( $license_text =~ /\b$pattern\b/i ) {
- if ( $osi and $license_text =~ /All rights reserved/i ) {
- print "WARNING: 'All rights reserved' in copyright may invalidate Open Source license.\n";
- }
$self->license($license);
return 1;
}
@@ -482,19 +476,70 @@
return 1;
}
-sub install_script {
- my $self = shift;
- my $args = $self->makemaker_args;
- my $exe = $args->{EXE_FILES} ||= [];
- foreach ( @_ ) {
- if ( -f $_ ) {
- push @$exe, $_;
- } elsif ( -d 'script' and -f "script/$_" ) {
- push @$exe, "script/$_";
- } else {
- die("Cannot find script '$_'");
- }
- }
+# Convert triple-part versions (eg, 5.6.1 or 5.8.9) to
+# numbers (eg, 5.006001 or 5.008009).
+# Also, convert double-part versions (eg, 5.8)
+sub _perl_version {
+ my $v = $_[-1];
+ $v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e;
+ $v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e;
+ $v =~ s/(\.\d\d\d)000$/$1/;
+ $v =~ s/_.+$//;
+ if ( ref($v) ) {
+ $v = $v + 0; # Numify
+ }
+ return $v;
+}
+
+
+
+
+
+######################################################################
+# MYMETA.yml Support
+
+sub WriteMyMeta {
+ $_[0]->write_mymeta;
+}
+
+sub write_mymeta {
+ my $self = shift;
+
+ # If there's no existing META.yml there is nothing we can do
+ return unless -f 'META.yml';
+
+ # Merge the perl version into the dependencies
+ my $val = $self->Meta->{values};
+ my $perl = delete $val->{perl_version};
+ if ( $perl ) {
+ $val->{requires} ||= [];
+ my $requires = $val->{requires};
+
+ # Canonize to three-dot version after Perl 5.6
+ if ( $perl >= 5.006 ) {
+ $perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e
+ }
+ unshift @$requires, [ perl => $perl ];
+ }
+
+ # Load the advisory META.yml file
+ require YAML::Tiny;
+ my @yaml = YAML::Tiny::LoadFile('META.yml');
+ my $meta = $yaml[0];
+
+ # Overwrite the non-configure dependency hashs
+ delete $meta->{requires};
+ delete $meta->{build_requires};
+ delete $meta->{recommends};
+ if ( exists $val->{requires} ) {
+ $meta->{requires} = { map { @$_ } @{ $val->{requires} } };
+ }
+ if ( exists $val->{build_requires} ) {
+ $meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } };
+ }
+
+ # Save as the MYMETA.yml file
+ YAML::Tiny::DumpFile('MYMETA.yml', $meta);
}
1;
Modified: branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Win32.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Win32.pm?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Win32.pm (original)
+++ branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/Win32.pm Tue Mar 3 20:41:23 2009
@@ -6,7 +6,7 @@
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '0.77';
+ $VERSION = '0.79';
@ISA = qw{Module::Install::Base};
$ISCORE = 1;
}
Modified: branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/WriteAll.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/WriteAll.pm?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/WriteAll.pm (original)
+++ branches/upstream/libnamespace-clean-perl/current/inc/Module/Install/WriteAll.pm Tue Mar 3 20:41:23 2009
@@ -6,7 +6,7 @@
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
- $VERSION = '0.77';
+ $VERSION = '0.79';
@ISA = qw{Module::Install::Base};
$ISCORE = 1;
}
Modified: branches/upstream/libnamespace-clean-perl/current/lib/namespace/clean.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/lib/namespace/clean.pm?rev=31331&op=diff
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/lib/namespace/clean.pm (original)
+++ branches/upstream/libnamespace-clean-perl/current/lib/namespace/clean.pm Tue Mar 3 20:41:23 2009
@@ -15,11 +15,11 @@
=head1 VERSION
-0.08
-
-=cut
-
-$VERSION = 0.09;
+0.11
+
+=cut
+
+$VERSION = '0.11';
$STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE';
=head1 SYNOPSIS
@@ -114,6 +114,27 @@
Same goes for L<Moose::Role>.
+=head2 Cleaning other packages
+
+You can tell C<namespace::clean> that you want to clean up another package
+instead of the one importing. To do this you have to pass in the C<-cleanee>
+option like this:
+
+ package My::MooseX::namespace::clean;
+ use strict;
+
+ use namespace::clean (); # no cleanup, just load
+
+ sub import {
+ namespace::clean->import(
+ -cleanee => scalar(caller),
+ -except => 'meta',
+ );
+ }
+
+If you don't care about C<namespace::clean>s discover-and-C<-except> logic, and
+just want to remove subroutines, try L</clean_subroutines>.
+
=head1 METHODS
You shouldn't need to call any of these. Just C<use> the package at the
@@ -121,14 +142,21 @@
=cut
-=head2 import
-
-Makes a snapshot of the current defined functions and installs a
-L<B::Hooks::EndOfScope> hook in the current scope to invoke the cleanups.
+=head2 clean_subroutines
+
+This exposes the actual subroutine-removal logic.
+
+ namespace::clean->clean_subroutines($cleanee, qw( subA subB ));
+
+will remove C<subA> and C<subB> from C<$cleanee>. Note that this will remove the
+subroutines B<immediately> and not wait for scope end. If you want to have this
+effect at a specific time (e.g. C<namespace::clean> acts on scope compile end)
+it is your responsibility to make sure it runs at that time.
=cut
my $RemoveSubs = sub {
+
my $cleanee = shift;
my $store = shift;
SYMBOL:
@@ -153,19 +181,38 @@
}
};
+sub clean_subroutines {
+ my ($nc, $cleanee, @subs) = @_;
+ $RemoveSubs->($cleanee, {}, @subs);
+}
+
+=head2 import
+
+Makes a snapshot of the current defined functions and installs a
+L<B::Hooks::EndOfScope> hook in the current scope to invoke the cleanups.
+
+=cut
+
sub import {
my ($pragma, @args) = @_;
my (%args, $is_explicit);
- if (@args and $args[0] =~ /^\-/) {
- %args = @args;
- @args = ();
- }
- elsif (@args) {
- $is_explicit++;
- }
-
- my $cleanee = caller;
+
+ ARG:
+ while (@args) {
+
+ if ($args[0] =~ /^\-/) {
+ my $key = shift @args;
+ my $value = shift @args;
+ $args{ $key } = $value;
+ }
+ else {
+ $is_explicit++;
+ last ARG;
+ }
+ }
+
+ my $cleanee = exists $args{ -cleanee } ? $args{ -cleanee } : scalar caller;
if ($is_explicit) {
on_scope_end {
$RemoveSubs->($cleanee, {}, @args);
@@ -215,10 +262,10 @@
=cut
sub unimport {
- my ($pragma) = @_;
+ my ($pragma, %args) = @_;
# the calling class, the current functions and our storage
- my $cleanee = caller;
+ my $cleanee = exists $args{ -cleanee } ? $args{ -cleanee } : scalar caller;
my $functions = $pragma->get_functions($cleanee);
my $store = $pragma->get_class_store($cleanee);
Added: branches/upstream/libnamespace-clean-perl/current/t/05-explicit-cleanee.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/t/05-explicit-cleanee.t?rev=31331&op=file
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/t/05-explicit-cleanee.t (added)
+++ branches/upstream/libnamespace-clean-perl/current/t/05-explicit-cleanee.t Tue Mar 3 20:41:23 2009
@@ -1,0 +1,25 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Test::More tests => 19;
+
+use_ok('CleaneeTarget');
+
+ok CleaneeTarget->can('IGNORED'), 'symbol in exception list still there';
+ok CleaneeTarget->can('NOTAWAY'), 'symbol after import call still there';
+ok !CleaneeTarget->can('AWAY'), 'normal symbol has disappeared';
+
+ok !CleaneeTarget->can('x_foo'), 'explicitely removed disappeared (1/2)';
+ok CleaneeTarget->can('x_bar'), 'not in explicit removal and still there';
+ok !CleaneeTarget->can('x_baz'), 'explicitely removed disappeared (2/2)';
+
+ok !CleaneeTarget->can('d_foo'), 'directly removed disappeared (1/2)';
+ok CleaneeTarget->can('d_bar'), 'not in direct removal and still there';
+ok !CleaneeTarget->can('d_baz'), 'directly removed disappeared (2/2)';
+
+my @values = qw( 23 27 17 XFOO XBAR XBAZ 7 8 9 );
+is(CleaneeTarget->summary->[ $_ ], $values[ $_ ], sprintf('testing sub in cleanee (%d/%d)', $_ + 1, scalar @values))
+ for 0 .. $#values;
Added: branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridge.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridge.pm?rev=31331&op=file
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridge.pm (added)
+++ branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridge.pm Tue Mar 3 20:41:23 2009
@@ -1,0 +1,14 @@
+package CleaneeBridge;
+use strict;
+use warnings;
+
+use namespace::clean ();
+
+sub import {
+ namespace::clean->import(
+ -cleanee => scalar(caller),
+ -except => 'IGNORED',
+ );
+}
+
+1;
Added: branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridgeDirect.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridgeDirect.pm?rev=31331&op=file
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridgeDirect.pm (added)
+++ branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridgeDirect.pm Tue Mar 3 20:41:23 2009
@@ -1,0 +1,10 @@
+package CleaneeBridgeDirect;
+use strict;
+
+use namespace::clean ();
+
+sub import {
+ namespace::clean->clean_subroutines(scalar(caller), qw( d_foo d_baz ));
+}
+
+1;
Added: branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridgeExplicit.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridgeExplicit.pm?rev=31331&op=file
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridgeExplicit.pm (added)
+++ branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeBridgeExplicit.pm Tue Mar 3 20:41:23 2009
@@ -1,0 +1,14 @@
+package CleaneeBridgeExplicit;
+use strict;
+use warnings;
+
+use namespace::clean ();
+
+sub import {
+ namespace::clean->import(
+ -cleanee => scalar(caller),
+ qw( x_foo x_baz ),
+ );
+}
+
+1;
Added: branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeTarget.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeTarget.pm?rev=31331&op=file
==============================================================================
--- branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeTarget.pm (added)
+++ branches/upstream/libnamespace-clean-perl/current/t/lib/CleaneeTarget.pm Tue Mar 3 20:41:23 2009
@@ -1,0 +1,26 @@
+package CleaneeTarget;
+use strict;
+use warnings;
+
+sub AWAY { 23 };
+sub IGNORED { 27 };
+
+use CleaneeBridge;
+
+sub NOTAWAY { 17 };
+
+sub x_foo { 'XFOO' }
+sub x_bar { 'XBAR' }
+sub x_baz { 'XBAZ' }
+
+use CleaneeBridgeExplicit;
+
+sub d_foo { 7 }
+sub d_bar { 8 }
+sub d_baz { 9 }
+
+sub summary { [AWAY, IGNORED, NOTAWAY, x_foo, x_bar, x_baz, d_foo, d_bar, d_baz] }
+
+use CleaneeBridgeDirect;
+
+1;
More information about the Pkg-perl-cvs-commits
mailing list