in reply to Re^2: Question on OO Perl
in thread Question on OO Perl

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".

Replies are listed 'Best First'.
Re^4: Question on OO Perl
by gokuraku (Monk) on Nov 19, 2007 at 14:59 UTC

    Well I'm not sure what snippet would work. This is running a set of scripts (total of about 8 to run this example) that are using objects to set up the environment depending on platform and OS. I already have some warnings placed in the code, as well as print statements for debugging.

    The basic function is this:

    sub getBinDir { my $self = shift; if ( not exists $self->{'binDir'} ) { warn "Object member binDir not set"; return ""; } $self->{'binDir'} = shift if @_; print "Returning binDir.\n"; return $self->{'binDir'}; }

    It's located in the TestHarness.pm file, but called from UnixTestHarness.pm

    sub copyCtestBinaries { my $self = shift; my $binDir = $self->getBinDir(); if ( $binDir eq '' ) { warn "Could not set up C test binary area: $!\n"; print "Received " . $self->getBinDir() . " for binDir.\n"; return; } $binDir = $binDir . "\/*"; print "BinDir = $binDir.\n"; my $appBin = $self->app1() . "/bin"; print "AppDir = $appBin.\n"; `cp $binDir $appBin`; }

    With the values set up in SolarisTestHarness.pm

    sub new { my $class = shift; # Pass the command line to the base class. my $self = $class->SUPER::new(@_); # Set OS specific defaults. $self->{'binDir'} = 'bin/solaris'; bless ($self, $class); return $self; }

    One thing I did try, was to move the function to the SolarisTestHarness.pm file and set it there if its not set already. Which generated the following:
    Can't locate object method "getBinDir" via package "SolarisTestHarness" at /opt/testharness/UnixTestHarness.pm line 90.

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