-
-
19 Jun 2013 19:26:54 UTC
- Distribution: Package-Alias
- Module version: 0.13
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (0)
- Testers (2939 / 0 / 0)
- Kwalitee
Bus factor: 0- 95.45% Coverage
- License: perl_5
- Perl: v5.6.0
- Activity
24 month- Tools
- Download (12.23KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- Carp
- strict
- Reverse dependencies
- CPAN Testers List
- Dependency graph
- NAME
- VERSION
- SYNOPSIS
- DESCRIPTION
- GLOBALS
- METHODS
- CAVEATS
- NOTES
- SEE ALSO
- AUTHORS
- COPYRIGHT AND LICENSE
NAME
Package::Alias - Alias one namespace as another
VERSION
version 0.13
SYNOPSIS
use Package::Alias Foo => 'main', 'P::Q' => 'Really::Long::Package::Name', Alias => 'Existing::Namespace';
DESCRIPTION
This module aliases one package name to another. After running the SYNOPSIS code,
@INC
(shorthand for@main::INC
) and@Foo::INC
reference the same memory, likewise for the other pairings.Modules not currently loaded into %INC will be used automatically. e.g.,
use Package::Alias HMS => 'Hash::Merge::Simple'; # automatically runs 'use Hash::Merge::Simple;'
To facilitate some crafty slight of hand, the above will also
use P::Q
if it's not already loaded, and tell Perl thatReally::Long::Package::Name
is loaded. In some rare cases such asMouse
, additional trickery may be required; see "Working with Mouse".GLOBALS
Package::Alias won't alias over a namespace if it's already in use. That's not a fatal error - you'll see a warning and flow will continue. You can change that cowardly behaviour this way:
# Make Bar like Foo, even if Bar is already in use. BEGIN { $Package::Alias::BRAVE = 1 } use Package::Alias Bar => 'Foo'; # The old Bar was just clobbered
METHODS
alias
Underlying class method that aliases one namespace to another.
Package::Alias->alias($aliased_namespace, $original_namespace);
CAVEATS
To be strict-compliant, you'll need to quote any packages on the left-hand side of a => if the namespace has colons. Packages on the right-hand side all have to be quoted. This is documented as "Comma Operator" in perlop.
NOTES
Chip Salzenberg says that it's not technically feasible to perform runtime namespace aliasing. At compile time, Perl grabs pointers to functions and global vars. Those pointers aren't updated if we alias the namespace at runtime.
Working with Mouse
BEGIN { use Package::Alias Moose => Mouse; # Make Mouse's finicky internal checks happy... Moose::Exporter->setup_import_methods(exporting_package => 'Moose', # Alas the defaults live in Mouse... as_is => [qw( extends with has before after around override super augment inner ), \&Scalar::Util::blessed, \&Carp::confess, ], );
SEE ALSO
aliased namespace Devel::Symdump
AUTHORS
Joshua Keroes <joshua@cpan.org>
Jerrad Pierce <jpierce@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Joshua Keroes.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Module Install Instructions
To install Package::Alias, copy and paste the appropriate command in to your terminal.
cpanm Package::Alias
perl -MCPAN -e shell install Package::Alias
For more information on module installation, please visit the detailed CPAN module installation guide.