| Package-Rename documentation | Contained in the Package-Rename distribution. |
Package::Rename - Rename or copy package
Version 0.02
This module allows you to rename, copy or even remove packages from the perl namespace.
This module defines the following functions. They are all optionally exported.
Give a package a different name. This is the equivalent of first linking a package, and then removing its original name.
Make a 'hard link' of a package, thus giving it a second name.
Remove a package from the namespace. You probably don't want to use this yourself unless you really know what you're doing.
Copy the complete contents of a package.
Leon Timmermans, <leont at cpan.org>
This code can cause serious mayham. Use it with care.
Please report any bugs or feature requests to bug-package-rename at rt.cpan.org, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Package-Rename. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
Perl looks up functions during compile time but methods run time. This fact can be useful (see namespace::clean for an example of that), but also to confusing.
You can find documentation for this module with the perldoc command.
perldoc Package::Rename
You can also look for information at:
Copyright 2009 Leon Timmermans, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Package-Rename documentation | Contained in the Package-Rename distribution. |
package Package::Rename; use strict; use warnings; use Carp; use MRO::Compat; use base 'Exporter'; our @EXPORT_OK = qw/copy_package remove_package rename_package link_package/; our $VERSION = '0.02'; sub copy_package { my ($old_name, $new_name) = @_; no strict 'refs'; %{"$new_name\::"} = %{"$old_name\::"}; mro::method_changed_in($new_name); return; } sub remove_package { my $name = shift; my ($super, $sub) = $name =~ / ^ ( \w+ (?> ::\w+ )* ) :: (\w+) $/xs ? ($1, $2) : ('main', $name); no strict 'refs'; undef ${"$super\::"}{"$sub\::"}; mro::method_changed_in($name); return; } sub link_package { my ($old_name, $new_name) = @_; no strict 'refs'; *{"$new_name\::"} = *{"$old_name\::"}; mro::method_changed_in($new_name); return; } sub rename_package { my ($old_name, $new_name) = @_; link_package($old_name, $new_name); remove_package($old_name); return; } 1; # End of Package::Rename __END__