+ [0.04] Sat Mar 17 16:22:10 CET 2007
+ - Added -except flag
+ - Non-CODE type slots will not be removed
+
[0.03] Sat Feb 24 22:34:55 CET 2007
- Minor comment and POD cleanups
- Tried to clarify how the module works
+---
abstract: Keep imports and functions out of your namespace
author: Robert 'phaylon' Sedlacek <rs@474.at>
build_requires:
FindBin: 0
Test::More: 0.62
distribution_type: module
-generated_by: Module::Install version 0.64
+generated_by: Module::Install version 0.65
license: perl
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.3.html
+ version: 1.3
name: namespace-clean
no_index:
directory:
requires:
Filter::EOF: 0.02
Symbol: 0
-version: 0.03
+version: 0.04
namespace::clean - Keep imports and functions out of your namespace
VERSION
- 0.03
+ 0.04
SYNOPSIS
package Foo;
By unimporting via "no" you can tell "namespace::clean" to start
collecting functions for the next "use namespace::clean;" specification.
+ You can use the "-except" flag to tell "namespace::clean" that you don't
+ want it to remove a certain function. A common use would be a module
+ exporting an "import" method along with some functions:
+
+ use ModuleExportingImport;
+ use namespace::clean -except => [qw( import )];
+
METHODS
You shouldn't need to call any of these. Just "use" the package at the
appropriate place.
General Todo's
- Adding "use namespace::clean-start;" and "use namespace::clean-end;"
- - Adding "use namespace::clean 'remove_after_compile';" exporting that
- function allowing "remove_after_compiletime($class, \@functions);"
+ - Adding "use namespace::clean 'remove_after_compiletime';" exporting
+ that function allows module authors to do
+ "remove_after_compiletime($class, \@functions);"
+
# 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.64';
+ $VERSION = '0.65';
}
# Whether or not inc::Module::Install is actually loaded, the
#line 1
package Module::Install::Base;
-$VERSION = '0.64';
+$VERSION = '0.65';
# Suspend handler for "redefined" warnings
BEGIN {
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.64';
+ $VERSION = '0.65';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.64';
+ $VERSION = '0.65';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.64';
+ $VERSION = '0.65';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
. "but we need version >= $perl_version";
}
+ $args->{INSTALLDIRS} = $self->installdirs;
+
my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args;
- if ($self->admin->preop) {
- $args{dist} = $self->admin->preop;
+
+ my $user_preop = delete $args{dist}->{PREOP};
+ if (my $preop = $self->admin->preop($user_preop)) {
+ $args{dist} = $preop;
}
my $mm = ExtUtils::MakeMaker::WriteMakefile(%args);
__END__
-#line 334
+#line 338
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.64';
+ $VERSION = '0.65';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
my @scalar_keys = qw{
name module_name abstract author version license
- distribution_type perl_version tests
+ distribution_type perl_version tests installdirs
};
my @tuple_keys = qw{
};
}
+sub install_as_core { $_[0]->installdirs('perl') }
+sub install_as_cpan { $_[0]->installdirs('site') }
+sub install_as_site { $_[0]->installdirs('site') }
+sub install_as_vendor { $_[0]->installdirs('vendor') }
+
sub sign {
my $self = shift;
return $self->{'values'}{'sign'} if defined wantarray and !@_;
if (
$self->_slurp($file) =~ m/
- =head \d \s+
- (?:licen[cs]e|licensing|copyright|legal)\b
- (.*?)
+ (
+ =head \d \s+
+ (?:licen[cs]e|licensing|copyright|legal)\b
+ .*?
+ )
(=head\\d.*|=cut.*|)
\z
/ixms
'LGPL' => 'lgpl',
'BSD' => 'bsd',
'Artistic' => 'artistic',
+ 'MIT' => 'MIT',
);
while ( my ( $pattern, $license ) = splice( @phrases, 0, 2 ) ) {
$pattern =~ s{\s+}{\\s+}g;
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.64';
+ $VERSION = '0.65';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
use vars qw{$VERSION $ISCORE @ISA};
BEGIN {
- $VERSION = '0.64';
+ $VERSION = '0.65';
$ISCORE = 1;
@ISA = qw{Module::Install::Base};
}
=head1 VERSION
-0.03
+0.04
=cut
-$VERSION = 0.03;
+$VERSION = 0.04;
$STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE';
=head1 SYNOPSIS
By unimporting via C<no> you can tell C<namespace::clean> to start
collecting functions for the next C<use namespace::clean;> specification.
+You can use the C<-except> flag to tell C<namespace::clean> that you
+don't want it to remove a certain function. A common use would be a
+module exporting an C<import> method along with some functions:
+
+ use ModuleExportingImport;
+ use namespace::clean -except => [qw( import )];
+
=head1 METHODS
You shouldn't need to call any of these. Just C<use> the package at the
=cut
sub import {
- my ($pragma) = @_;
+ 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);
-
+
+ my %except = map {( $_ => 1 )} @{ $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} }) {
- next if $store->{exclude}{ $f };
+
+ # ignore already removed symbols
+ next SYMBOL if $store->{exclude}{ $f };
no strict 'refs';
+
+ # keep original value to restore non-code slots
+ 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 };
+ }
}
});
$store->{handler_is_installed} = 1;
use FindBin;
use lib "$FindBin::Bin/lib";
-use Test::More tests => 5;
+use Test::More tests => 9;
use_ok('FunctionWipeout');
ok( !FunctionWipeout->can('foo'),
'later declared function still exists' );
is( FunctionWipeout->baz, 23,
'removed functions still bound' );
-
+ok( FunctionWipeout->can('qux'),
+ '-except flag keeps import' );
+is( FunctionWipeout->qux, 17,
+ 'kept import still works' );
+ok( $FunctionWipeout::foo,
+ 'non-code symbol was not removed' );
+is( $FunctionWipeout::foo, 777,
+ 'non-code symbol still has correct value' );
use strict;
use base 'Exporter';
-use vars qw( @EXPORT_OK );
+use vars qw( @EXPORT_OK $foo );
-@EXPORT_OK = qw( foo bar );
+$foo = 777;
+@EXPORT_OK = qw( $foo foo bar qux );
sub foo { 23 }
sub bar { 12 }
+sub qux { 17 }
1;
use warnings;
use strict;
-use ExporterTest qw(foo);
+use ExporterTest qw( foo qux $foo );
sub bar { foo() }
-use namespace::clean;
+use namespace::clean -except => [qw( qux )];
sub baz { bar() }