in reply to Re^2: About inheritence ? and Autoload ?
in thread About inheritence ? and Autoload ?

If you want to use the current package as the base name of some other package, you could do something like this:

my $subpackage = __PACKAGE__ . '::Command'; my $test_command = $subpackage->new(@ARGV);

You could also make a module that installs this behavior into every package. Here's a demonstration:

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

In Real Code, you'd put the sub UNIVERSAL::subpackage part into another module which you then use from every package that you want to have that behavior. While "__PACKAGE__->method( 'Blah' )" is a lot longer than just "Blah", it also carries a bit more meaning.

Is that closer to what you want?

Replies are listed 'Best First'.
Re^4: About inheritence ? and Autoload ?
by lepetitalbert (Abbot) on Nov 25, 2009 at 16:36 UTC

    Hi again,

    pajout, I think I was (am) confused about namespace and inheritance. Thanks for your precisions,

    kyle, that's definitivly exactly what I was lookin for \o/

    Thank you all.

    Have a nice day.

    "There is only one good, namely knowledge, and only one evil, namely ignorance." Socrates