Is there a Perl module or technique that makes using long namespaces easier? -
some namespaces long , annoying. lets downloaded hypothetical package called foofoo-barbar-bazbaz.tar.gz, , has 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 module or technique can use that's similar c++ 'using' statement, i.e., there way can do
using foofoo::barbar::bazbaz;
which let me do
my $obj = brown->new(); ok $obj->isa('foofoo::barbar::bazbaz::brown') ; # true # or... ok $obj->isa('brown'); # true
the aliased pragma this:
use aliased 'foofoo::barbar::bazbaz::bill'; $bill = bill->new;
aliased
syntactic sugar
use constant bill => 'foofoo::barbar::bazbaz::bill'; # or sub bill () {'foofoo::barbar::bazbaz::bill'}
the downside of normal usage of package names arguments done quoted strings:
$obj->isa('foofoo::barbar::bazbaz::bill')
but constant subroutine needs bare word:
$obj->isa(bill);
which seems bug waiting happen.
alternatively, use perl's builtin support 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::} # magic happens here fbb::bill->new; # foo::bar::baz::bill=hash(0x80fd10) fbb::tom->new; # foo::bar::baz::tom=hash(0xfd1080)
regarding ->isa('shortname')
requirement, aliased stash method works quoted strings usual:
my $obj = fbb::bill->new; $obj->isa('fbb::bill'); # prints 1 $obj->isa('foo::bar::baz::bill'); # prints 1
the effect of compile time alias begin {*short:: = *long::package::name::}
global across packages , scopes. fine long pick empty package alias into.
Comments
Post a Comment