in reply to OOP Question - location of $self

If you just want to avoid typing $self->other_method from with a sub method { ... } object method, unless you use shift to pull $self out of the argument list, remember that you can always just pass @_ to a function to pass arguments as-is. Thus, you could do:
sub method { my ($self, $arg) = @_; # do stuff with $self perhaps other(@_); # equiv. to $self->other($arg) }
But this is kind of goofy. It's clearer to write it out the correct way, so that you and others maintaining your code in the future don't ask themselves what in the hell you were doing:
$self->other($arg);
Does this help at all?

Replies are listed 'Best First'.
Re: Re: OOP Question - location of $self
by dws (Chancellor) on Apr 16, 2001 at 22:01 UTC
    Passing @_ is not only goofy, but it breaks inheritance. You won't be able to inherit from the class and override other. Consider   other(@_); It is a non-OO invocation. If other doesn't exist in the current class, it won't be searched for using the @ISA chain. You might want to do this to implement "restricted" (callable only within one class) functions, though it requires that all callers know that other is restricted. That can get messy. <p Now consider   $self->other($arg); If other doesn't exist within the calling class, it will be searched via @ISA, which is what you want when you're using inheritance.

      The original discussion was about "internal" routines. Those are not meant to be subject to inheritance. So avoiding inheritance for these routines was the whole point.

              - tye (but my friends call me "Tye")