Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Aliasing a package

by Superfox il Volpone (Sexton)
on Jan 25, 2014 at 10:01 UTC ( [id://1072049]=perlquestion: print w/replies, xml ) Need Help??

Superfox il Volpone has asked for the wisdom of the Perl Monks concerning the following question:

Hi there,
Is there a way to alias or obtain a shortcut to refer to a package ?

for instance:
use common::system::utilities::Logger; Logger::print("stuff");
or, a la c++:
namespace Logger = common::system::utilities::Logger;
Thanks in advance

Kind regards,
s.fox

Replies are listed 'Best First'.
Re: Aliasing a package
by Anonymous Monk on Jan 25, 2014 at 10:11 UTC

    Usually you create an object

    my $logger = common::system::utilities::Logger->new; $logger->print( ... );

    or a subroutine  sub LOG { &common::system::utilities::Logger::print }

    but you can do "aliases" with Package::Alias  use Package::Alias Logger => 'common::system::utilities::Logger' ;

    or do it yourself

    BEGIN{ use common::system::utilities::Logger; *Logger:: = *common::system::utilities::Logger::; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1072049]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-09-18 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (25 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.