Package::Relative - Support for '..' style relative paths in perl namespaces.
package My::Pkg; use Package::Relative; (PKG . "..::Foo")->method; # My::Foo (PKG . "Bar")->method; # My::Pkg::Bar
This module exports the "PKG" function, which returns an overloaded object.
This object overloads the stringification and concatenation operations, treating ".." in paths as a relative notation. See the "SYNOPSIS".
__PACKAGE__ work alike that returns an overloaded object instead of a string.
__PACKAGE__
Returns the string for the package.
Implements the . operator.
.
This is to support
PKG->method;
Although that is greatly discouraged. If you are doing that, why not use
__PACKAGE__->method;
In the future a warning might be emitted.
When the object is the right hand side of a concatenation, e.g.
"Foo" . PKG;
Then an object is returned. This means that
my $pkg = PKG; "Foo::${pkg}::..::Bar";
will DWIM.
On the other hand, when the object is the left hand side of a concatenation, a plain string is returned.
This means that
package My::Pkg; PKG . "..::Foo" . "..::Bar";
is really equal to My::Foo..::Bar instead of what you'd expect.
My::Foo..::Bar
The reason this is done is to simplify the generic case:
(PKG . "..::Foo")->method;
If an object were returned, method would have been dispatched to it, and AUTOLOAD yuckiness could not be avoided.
AUTOLOAD
The workaround, which is not too bad is to always parenthesize:
PKG . ("..::Foo::" . "..::Bar"); # notice the extra colons after Foo
To install Package::Relative, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Package::Relative
CPAN shell
perl -MCPAN -e shell install Package::Relative
For more information on module installation, please visit the detailed CPAN module installation guide.