in reply to current/active package

ref

sub method { my ($self) = @_; print ref($self), "\n"; }

It's very rare to need that. Why do you ask? Maybe there's a better answer if we knew the bigger picture.

Replies are listed 'Best First'.
Re^2: current/active package
by eye (Chaplain) on Sep 25, 2009 at 06:04 UTC
    Except,
    sub woot { my ($self) = @_; print __PACKAGE__, "\n"; # <-- prints "foo" print ref($self), "\n"; # <-- prints nothing }
    While,
    sub woot { my ($self) = @_; print __PACKAGE__, "\n"; # <-- prints "foo" print $self, "\n"; # <-- prints "bar" }
    I think this is because, in this simple example, the object was never blessed. Had it been blessed, I think ikegami's answer is correct.
      yeah, oops.
      sub class_method { my ($class) = @_; print "$class\n"; } sub object_method { my ($self) = @_; my $class = ref($self); print "$class\n"; } Class->class_method(); $obj->object_method();
      the object was never blessed.
      There is no object at all. Note that the OP's call of woot is done like this:

      package main; bar->woot();
      This means that he is writing a package name to the left of ->, i.e. woot is might be something like a constructor. So you don't have an object, but you do have a package name.

      -- 
      Ronald Fischer <ynnor@mm.st>
        In the example, there are no objects. This is supposed to be invoking a package-level method with ISA inheritance, knowing the package you are in, and the package the sub was invoked upon. I realize that in the example, $_[0] = the package the sub was invoked upon. But aren't there other ways to invoke the function in which that will not be true? What about bar::woot() ???