Package::Rename - Rename or copy package


Package-Rename documentation Contained in the Package-Rename distribution.

Index


Code Index:

NAME

Top

Package::Rename - Rename or copy package

VERSION

Top

Version 0.02

SYNOPSIS

Top

This module allows you to rename, copy or even remove packages from the perl namespace.

FUNCTIONS

Top

This module defines the following functions. They are all optionally exported.

rename_package($old_name, $new_name)

Give a package a different name. This is the equivalent of first linking a package, and then removing its original name.

remove_package($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_package($old_name, $new_name)

Copy the complete contents of a package.

AUTHOR

Top

Leon Timmermans, <leont at cpan.org>

BUGS

Top

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.

PITFALLS

Top

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.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Package::Rename




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Package-Rename

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Package-Rename

* CPAN Ratings

http://cpanratings.perl.org/d/Package-Rename

* Search CPAN

http://search.cpan.org/dist/Package-Rename

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


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__