Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dex4er/perl-namespace-functions
namespace::functions - Keep package's namespace clean
https://github.com/dex4er/perl-namespace-functions
Last synced: 10 days ago
JSON representation
namespace::functions - Keep package's namespace clean
- Host: GitHub
- URL: https://github.com/dex4er/perl-namespace-functions
- Owner: dex4er
- License: other
- Created: 2011-01-25T23:18:40.000Z (almost 14 years ago)
- Default Branch: cpan
- Last Pushed: 2011-01-30T12:37:44.000Z (almost 14 years ago)
- Last Synced: 2024-10-28T09:01:57.080Z (about 2 months ago)
- Language: Perl
- Homepage: http://search.cpan.org/dist/namespace-functions/
- Size: 113 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
NAME
namespace::functions - Keep package's namespace cleanSYNOPSIS
package My::Class;# import some function
use Scalar::Util 'looks_like_number';# collect the names of all previously created functions
use namespace::functions;# our function uses imported function
sub is_num {
my ($self, $val) = @_;
return looks_like_number("$val");
}# delete all previously collected functions
no namespace::functions;# our package doesn't provide imported function anymore!
DESCRIPTION
This pragma allows to collect all functions existing in package's
namespace and finally delete them.The problem is that any function which is imported to your package,
stays a part of public API of this package. I.e.:package My::PollutedClass;
use Scalar::Util 'looks_like_number';sub is_num {
my ($val) = @_;
return looks_like_number("$val");
}package main;
print My::PollutedClass->can('looks_like_number'); # trueDeleting imported function from package's stash is a solution, because
the function will be not available at run-time:delete {\%My::PoorSolutionClass::}->{looks_like_number};
The `namespace::functions' collects the function names and finally
deletes them from package's namespace.AUTHOR
Piotr RoszatyckiCOPYRIGHT
Copyright (C) 2009, 2011 by Piotr Roszatycki .This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.See http://www.perl.com/perl/misc/Artistic.html