gokuraku has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I have actually run the script that contains this code in the past, and it worked, but for some reason now when I have the following:

my $self = $class->SUPER::new(shift); # Set OS specific defaults. $self->{'binDir'} = 'bin/solaris';
the binDir variable is not getting set. I can run this in the debugger and see the variable set in the whole program, but this one is skipped. I'm not sure why or what happened, but if anyone can give me an idea as to something to look at that would be appreciated.
Thanks

Replies are listed 'Best First'.
Re: Question on OO Perl
by moritz (Cardinal) on Nov 19, 2007 at 12:52 UTC
    What do you mean by "this one is skipped"? The constructor returns a blessed hash ref that doesn't have the binDir key?

    Can you provide a running, (preferably minimal) excerpt that demonstrates that behaviour?

    BTW I'd prefer $class->SUPER::new(@_), just in case you want to pass additional variables to the super classes constructor.

      Well I could run the debugger and show the values, but this particular section is within a Test Script that runs like this:
      The main script called is - TestHarness.pl
      Which loads - SolarisTestHarness.pm that begins to set values, but loads the Super Values first.
      So it loads - UnixTestHarness.pm - which begins setting some values but it also loads - TestHarness.pm - because this is the Super of UnixTestHarness.pm
      After TestHarness.pm and UnixTestHarness.pm complete populating values it's back to SolarisTestHarness.pm - which only adds two values before it starts running, this is to include the $self->{'binDir'} value. But this one never gets set, so when a function getBinDir() is called, nothing is returned because the value is somehow skipped.
      Hope that is a little clearer, I should definitely drink more coffee before posting....

      Didn't know about new(@_), that is something I can try.

        You still haven't provided a code snippet that reproduces the problem, so it's still all guessing.

        The snippet in the root node doesn't look wrong, so the problem could be somewhere else. For example are you sure that the new method actually returns $self, and that it's being called?

        You could just add the line warn $self->{binDir}; after the assignment, and see if it produces what you expect it to.

        Then you can move it around in your code to trace the point where it seems to "magically disappear".

          A reply falls below the community's threshold of quality. You may see it by logging in.