Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: About inheritence ? and Autoload ?

by lepetitalbert (Monsignor)
on Nov 25, 2009 at 11:18 UTC ( #809319=note: print w/ replies, xml ) Need Help??


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

Hello dear Monks,

Thank you all for you help !

ikegami, the error was

Can't locate object method "new" via package "Command" (perhaps you fo +rgot to load "Command"?) at ./test line 13

and you said

You never defined Command::new

? here I bug :
I have a package Test::Command with a sub new, and a use Test::Command;
Why is Command new not defined ?

kyle,

But I'd like some automatic relationship between Test and Test::Command

Is that a @ISA or inheritence question

spx2, I read stuff on Moose too and will probably use it, but I thought I'll try to understand first the 'manual' way.

pajout, I think my understanding bug is somwhere in your example but still don't where ! I'll play with it.
why can't you use

use Animal::Dog::Sheepdog; my $helper = Sheepdog->new();

Thanks again.

Have a nice day.

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


Comment on Re^2: About inheritence ? and Autoload ?
Select or Download Code
Re^3: About inheritence ? and Autoload ?
by pajout (Curate) on Nov 25, 2009 at 12:11 UTC
    The name of the module is 'Animal::Dog::Sheepdog', so if you try my $helper = Sheepdog->new();, Perl has no clue which module do you mean, respectively, Perl says Sheepdog module is not used. Imagine situation when both Foo and Bar::Foo are used, you have to distinguish in your code which object you want to create.

    Update: It is just about naming, not about inheritance. Inheritance is (in my example) defined by use base.

Re^3: About inheritence ? and Autoload ?
by kyle (Abbot) on Nov 25, 2009 at 13:24 UTC

    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?

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://809319]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (13)
As of 2014-10-21 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (110 votes), past polls