Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4000248
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:45:29+00:00 2026-05-20T07:45:29+00:00

Some namespaces are long and annoying. Lets say that i downloaded hypothetical package called

  • 0

Some namespaces are long and annoying. Lets say that i downloaded hypothetical package called FooFoo-BarBar-BazBaz.tar.gz, and it has the following modules:

FooFoo::BarBar::BazBaz::Bill
FooFoo::BarBar::BazBaz::Bob
FooFoo::BarBar::BazBaz::Ben
FooFoo::BarBar::BazBaz::Bozo
FooFoo::BarBar::BazBaz::Brown
FooFoo::BarBar::BazBaz::Berkly
FooFoo::BarBar::BazBaz::Berkly::First
FooFoo::BarBar::BazBaz::Berkly::Second

Is there a module or technique I can use that’s similar to the C++ ‘using’ statement, i.e., is there a way I can do

using FooFoo::BarBar::BazBaz;

which would then let me do

my $obj = Brown->new();

ok $obj->isa('FooFoo::BarBar::BazBaz::Brown') ;  # true
# or...
ok $obj->isa('Brown'); # also true
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:45:29+00:00Added an answer on May 20, 2026 at 7:45 am

    The aliased pragma does this:

    use aliased 'FooFoo::BarBar::BazBaz::Bill';
    
    my $bill = Bill->new;
    

    aliased is syntactic sugar for

    use constant Bill => 'FooFoo::BarBar::BazBaz::Bill';
    # or 
    sub Bill () {'FooFoo::BarBar::BazBaz::Bill'}
    

    The downside of this is that normal usage of package names as arguments is done with quoted strings:

    $obj->isa('FooFoo::BarBar::BazBaz::Bill')
    

    But the constant subroutine needs to be a bare word:

    $obj->isa(Bill);
    

    Which just seems like a bug waiting to happen.

    Alternatively, you could just use Perl’s builtin support for namespace aliasing:

    package Foo::Bar::Baz::Bill;
    
    sub new {bless {}}
    
    package Foo::Bar::Baz::Tom;
    
    sub new {bless {}}
    
    package main;
    
    BEGIN {*FBB:: = *Foo::Bar::Baz::}  # the magic happens here
    
    say FBB::Bill->new;  # Foo::Bar::Baz::Bill=HASH(0x80fd10)
    
    say FBB::Tom->new;   # Foo::Bar::Baz::Tom=HASH(0xfd1080)
    

    Regarding the ->isa('shortname') requirement, the aliased stash method works with quoted strings as usual:

    my $obj = FBB::Bill->new;
    
    say $obj->isa('FBB::Bill');           # prints 1
    say $obj->isa('Foo::Bar::Baz::Bill'); # prints 1
    

    The effect of a compile time alias BEGIN {*short:: = *long::package::name::} is global across all packages and scopes. This is fine as long as you pick an empty package to alias into.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I'm coding in Visual Studio 2010, say that I have some interface: Namespace
I remember few weeks ago when I reorgnized our code and created some namespaces
Are there some principles of organizing classes into namespaces? For example is it OK
Say I have some code like namespace Portal { public class Author { public
I was making an edit to a long existing project. Specifically I added some
I'm currently writing some general purpose .net libraries that contain usual helper classes. For
I have part of a build process that creates a hideously long paths in
I have some code that I had to write to replace a function that
Occasionaly we will have a page that required some page specific Javascript functionality. I
I started noticing that sometimes when deallocating memory in some of my programs, they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.