$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) |