the "use" let you import into the current namespace some the semantics that are in the module you provide to it, these semantics include the methods and variables that would be available to the current namespace ..

Inheritance on the other hand comes into play when you are writing a class (derived) that would use methods from another class (base), so the derived class inherits from the base class, this would be provided in the @ISA of the derived class, so when Perl can not find a method or a class in your current package it would check the @ISA for a class that has that method and subsequently execute it..

"Does that mean log() become a method of Catalyst context and that's what we call inheritance in Perl?"

It is a method invoked by the object used in your program, which is an object of Catalyst but it doesn't necessarily need to be inherited by Catalyst or taken as a representer of what inheritance is unless Catalyst itself has inherited this particular method from another base class, check the documentation..

An example of Inheritance, I would have two classes, a base CLASS1.pm and a derived CLASS2.pm, the second class would inherit the method declared in the first one and hence calling the second class and using it would call that method from CLASS1 but as a method of CLASS2..

#!/usr/local/bin/perl CLASS1.pm package CLASS1; sub new{ my $self = {}; bless($self); return $self; } sub gettext{ #this is the method I want to inherit return "I come from CLASS1.pm\n"; }; return 1;
Inheritance is done by:
#!/usr/local/bin/perl #CLASS2.pm package CLASS2; #import into the current namespace the symbol table of CLASS1 use CLASS; @ISA=qw(CLASS1); #Inherit from Class1. sub new{ my $self = CLASS1->new; #call constructor method of CLASS1 return bless($self); }
Using CLASS2 that inherits from CLASS1:
#!/usr/local/bin/perl #TryingIt.pl use CLASS2; my $object1=CLASS2->new(); print "The object says: ",$object1->gettext(),"\n"; print "The object class is ",ref $object1, "\n"; #The object says: I come from CLASS1.pm #The object class is CLASS2

The above code is just a proof of principle that illustrates what inheritance is, I hope you find it instructive and criticism is accepted with an open heart...but the subject is a vast one...You might also be interested in checking:


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

In reply to Re: Inheritance in Perl by biohisham
in thread Inheritance in Perl by sman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.