note
kyle
<p>If you want to use the current package as the base name of some other package, you could do something like this:
<c>
my $subpackage = __PACKAGE__ . '::Command';
my $test_command = $subpackage->new(@ARGV);
</c>
<p>You could also make a module that installs this behavior into every package. Here's a demonstration:
<c>
sub UNIVERSAL::subpackage { join '::', @_ }
package Foo::Command;
sub wow { print "I am: ", __PACKAGE__, "\n" }
package Foo;
sub check { __PACKAGE__->subpackage( 'Command' )->wow() }
package main;
Foo->check();
__END__
I am: Foo::Command
</c>
<p>In Real Code, you'd put the <c>sub UNIVERSAL::subpackage</c> part into another module which you then [doc://use] from every package that you want to have that behavior. While "<c>__PACKAGE__->method( 'Blah' )</c>" is a lot longer than just "<c>Blah</c>", it also carries a bit more meaning.
<p>Is that closer to what you want?
809222
809319