in reply to code ref confusion

What class $self refers to is dependend on the caller, not the package it's in, this is especially true if you have subclasses:

#!perl C::A->thing(); # prints "C::A"; C::B->thing(); # prints "C::B"; package C::A; sub thing { print shift; } package C::B; use base 'C::A';

There is a bug in your code:

my $self = @_; #2
will set $self to the number of arguments to the anonymous sub, so this will not be what you want.

#3 $self->{bla} - $self will be the $self created when the argument to Class::B->do_things is called. Where that is, I can't tell, because there is no definition of Class::B->do_things in this code.

By the way, none of the variables are in package Class::B, because lexicals are not bound to classes anyway.

Hope this helps
Joost

Replies are listed 'Best First'.
Re^2: code ref confusion
by CassJ (Sexton) on Jun 30, 2004 at 12:22 UTC
    "There is a bug in your code:
    my $self = @_; #2 "

    Yeah, that was what part of what I didn't get - Actually args ( including $self) are passed to the anonymous sub when it is dereferenced. Once I realised that, it all made sense. Was just being a muppet. Thanks for your help though!

    Cxx