Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any alias available in Perl for referencing a module name?

Tags:

perl

I have multiple Perl modules. The package names seems to be big

everytime i access the functions from those modules, i need to provide something like this

&PackageName::Functionname()

is there a shortcut or alias available in Perl which can reference the packages with bigger names

Thanks

Karthik

like image 914
KK99 Avatar asked Sep 28 '11 08:09

KK99


2 Answers

With Package::Alias you can alias a long package name such as Foo::Bar::Baz to baz:

use Package::Alias 'baz' => 'Foo::Bar::Baz';

baz::quux;  # Invokes Foo::Bar::Baz::quux;
like image 100
Alan Haggai Alavi Avatar answered Sep 28 '22 00:09

Alan Haggai Alavi


You can call the function without the &:

PackageName::Functionname();

Also there is the exporter mechanism which exports function from a module to your default namespace:

use PackageName 'Functionname';

Functionname();

For further explainations how to use use see http://perldoc.perl.org/functions/use.html

How to export functions when writing your own modules, see http://perldoc.perl.org/Exporter.html

like image 28
Daniel Böhmer Avatar answered Sep 27 '22 22:09

Daniel Böhmer