Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Tom Metro
Guillermo Roditi wrote: > Please take a look at Class::MOP and Class::MOP::Class. Sounds like a little > ->meta foo would makeyour life easier... Introspection is good and good for > you! > http://search.cpan.org/~stevan/Class-MOP-0.37/ Indeed. It even includes one of the things I was looking for

Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Ben Tilly
On 5/18/07, Greg London <[EMAIL PROTECTED]> wrote: [...] > >You're looking at the wrong part of the code. I'm referring to how I > >made sure to capture refaddr before creating the anonymous sub so that > >the anonymous sub did not have $object in it anywhere. That keeps > >$object from being in

Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Greg London
>The purpose of using goto there is in case some code uses caller() and >could get confused about the extra subroutine. (For instance Carp >would be likely to warn at the enclosing subroutine that you defined.) Ah yes, it's coming back to me now ___

Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Greg London
>On 5/18/07, Greg London <[EMAIL PROTECTED]> wrote: >> >> >sub replace_sub_for_instance { >> >my ($object, $subroutine_name, $new_subroutine) = @_; >> >no strict 'refs'; >> >my $old_subroutine = \&$subroutine_name >> >or die "Subroutine $subroutine_name not found"; >> >my $

Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Uri Guttman
> "TM" == Tom Metro <[EMAIL PROTECTED]> writes: TM> Isn't there also a potential problem if the if something upstream of the TM> reblessing saves a reference to the object, or is this true: TM>use Scalar::Util 'refaddr'; TM>my $obj = {}; TM>my $before = refaddr($obj);

Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Ben Tilly
On 5/18/07, Greg London <[EMAIL PROTECTED]> wrote: > > >sub replace_sub_for_instance { > >my ($object, $subroutine_name, $new_subroutine) = @_; > >no strict 'refs'; > >my $old_subroutine = \&$subroutine_name > >or die "Subroutine $subroutine_name not found"; > >my $object_n

Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Greg London
>sub replace_sub_for_instance { >my ($object, $subroutine_name, $new_subroutine) = @_; >no strict 'refs'; >my $old_subroutine = \&$subroutine_name >or die "Subroutine $subroutine_name not found"; >my $object_name = refaddr($object); >*$subroutine_name = sub { >m

Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Greg London
>On first read of Greg's code I thought he was suggesting modifying the >class under test to incorporate the extra decision logic, but taking a >second look after seeing your take above, I see the idea was to >externally inject a wrapper with instance detection logic. This could be >a good approach

Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Ben Tilly
On 5/18/07, Tom Metro <[EMAIL PROTECTED]> wrote: > Ben Tilly wrote: [...] > > Also note that AUTOLOAD and inheritance do NOT play well together. > > That's another reason to avoid that solution. > > I had that thought as well. Isn't there a workaround where your AUTOLOAD > handler can explicitly ha

Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Tom Metro
Ben Tilly wrote: > sub replace_sub_for_instance { > my ($object, $subroutine_name, $new_subroutine) = @_; > no strict 'refs'; > my $old_subroutine = \&$subroutine_name > or die "Subroutine $subroutine_name not found"; > my $object_name = refaddr($object); > *$subroutine_

Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Uri Guttman
> "TM" == Tom Metro <[EMAIL PROTECTED]> writes: TM> My understanding is that Perl's OO dereferencing for methods doesn't TM> involve the object instance, other than to obtain the class name so it TM> can find the right package namespace. If this is correct, then there TM> probably i

Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Guillermo Roditi
http://search.cpan.org/~stevan/Class-MOP-0.37/ -- Forwarded message -- From: Guillermo Roditi <[EMAIL PROTECTED]> Date: May 18, 2007 10:20 AM Subject: Re: [Boston.pm] overriding instance methods, dynamic package namespaces To: Tom Metro <[EMAIL PROTECTED]> Please take a look at Cl

Re: [Boston.pm] overriding instance methods, dynamic package namespaces

2007-05-18 Thread Ben Tilly
On 5/17/07, Tom Metro <[EMAIL PROTECTED]> wrote: > Greg London wrote: > > Evals and typeglobs will let you do it. > > If you don't like that sort of thing (I don't), > > you can use a module I wrote called SymbolTable > > which hides all the ugliness for you. > > Thanks Greg for taking the time to