Hi Vuud,

Theres something here that I dont grok. more specifically the line:

$self->Session::init (@args);
Now maybe I have missed something, but I dont understand what the above is supposed to do. Session::init I presume is a subroutine in the Session package. So why are you calling it against $self? Since you havent told us what package the new is from its hard to tell what you are up to.

I think you have some basic misunderstandings that would be cleared up by reading perltoot perlboot or perlobj. But ill try to give you an overview here.

In perl you can call a method in two ways. The first is a hangover to make C++ types feel more cozy the other way is the correct way to do it.

my $obj=new Some::Module; # ok but not so cool my $obj=Some::Module->new(); # TWTDI
You can see how this differs to the above sample from your new(). Im not even going to try to figure out how perl is interpreting your statement up there, but I am virtually certain its not doing what you think its doing

Anyway here is how I expected your new to look (and this is straight from perltoot)

package Session; #.... sub new { my $proto=shift; my $class=ref($proto) || $proto; my $self=bless {}, $class; # the below line assumes that this new is from # the Session class $self->init(@_); #no need to copy @_ return $self; };
Now from this point on all the help I can give is conjecture as your OP makes assumptions about what we know about things we have never seen (ie your code, and object model). Remember we havent been fighting/living/breathing this stuff for days so things that you take for granted we dont even know... :-) For instance what happens if you dont pass a Session ID to StartSession?

Nevertheless here is what I think you might need,

package SessionManager; #.... sub MakeNewSession { my $self=shift; my $session=Session->new() || die "Failed to construct Session!"; my $id=$session->SessionID; die "SessionID returned an undef value!" if !defined($id); print "New session has ID of ".$i; return $session; }
So the above sub will create a new session object print out its id and return it. I hope I havent misunderstood your question/problem and that this helps

Dont forget to read perltoot perlboot or perlobj. PerlToot and PerlBoot are very good tutorials and much about Perl let alone OOPerl can be learned from both.

Yves
--
You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)


In reply to Re: Re: Re: Creating objects within objects being strange... by demerphq
in thread Creating objects within objects being strange... by Vuud

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.