Robert, maybe you need some OO advice.

Inherite (extend) a class exists to get a basic class and add or overwrite some methods. For example, in GUI OO libraries, is very common to have a basic class for controls, that will handle (implement methods) that are common to all the controls, like create, destroy, show, etc... And for each control, like a Button, we have it's own class that Inherite from the basic class, or extends the basic class. Is like tell to class to import the methods and attributes from another class.

What you want is to have a object X that handle some socket data, and another object Y that handle more socket data and also work with X. Soo, create one object X, from your class Tinia_CanExtender, and than create the object Y from the class Tinia_CanPwm. If you want that the object Y has internal reference to X, soo you can paste X as an argument, or set an attribute inside Y.

Take a look in this code:

my $x = new Tinia_CanExtender() ; my $y = new Tinia_CanPwm($x) ; package Tinia_CanPwm ; @ISA = qw(Tinia_CanExtender); sub new { my $class = shift ; my $this = bless({} , $class) ; my ( $parent ) = @_ ; $this->{PARENT} = $parent ; return $this ; } package Tinia_CanExtender ; sub new { my $class = shift ; my $this = bless({} , $class) ; return $this ; } sub set { my $self = shift ; my ($state,$set_by) = @_; ... }
If you want to code classes in Perl in a style similar to Java, you can take a look in the module Class::HPLOO.

Graciliano M. P.
"Creativity is the expression of the liberty".


In reply to Re: Objects: how to get parent object from child $self reference ? by gmpassos
in thread Objects: how to get parent object from child $self reference ? by Anonymous Monk

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.