引用Perl/Moose包名称的简写?

PBJ*_*PBJ 11 perl coding-style packages moose verbosity

在Python和Java中,我们必须import消除代码中完全限定的包/模块名称的重复.Perl/Moose有没有相应的东西?我认为如果我们不必重复,那么真的会让Moose更好用MyApp::Model::Item.相反,我想[somehow declare] MyApp::Model::Item;以及稍后,只需参考Item.我可以想到所有使用类名的用例......

  • extends 'Item';
  • with 'ItemRole';
  • Item->new(name => 'thing');
  • method foo(Item $xyz) { ... },与 MooseX::Method::Signatures
  • $var->isa('Item');
  • try { ... } catch (DatabaseError $e) { ... },与 TryCatch
  • $Item::SOME_PACKAGE_GLOBAL_VARIABLE

如果还没有这样的事情,有什么想法我可能会开始干净地实现这个吗?我可以看到处理classname用作字符串的情况会很棘手.

raf*_*afl 18

这一切都有效 aliased

use aliased 'MyApp::Model::Item';
use aliased 'MyApp::ItemRole';
use aliased 'MyApp::Exception::DatabaseError';

extends Item;
with ItemRole;
Item->new(name => 'thing');
method foo (Item $xyz) { ... }
$var->isa(Item);
try { ... } catch(DatabaseError $e) { ... }
Run Code Online (Sandbox Code Playgroud)

这不是:

$Item::SOME_PACKAGE_GLOBAL_VAR
Run Code Online (Sandbox Code Playgroud)

需要这样的东西似乎很少见,但我想它可以与namespace::alias模块一起工作.