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

2007-05-31 Thread Guillermo Roditi
/me curses forgotten thread I actively contribute to the codebase of both Moose and MOP, so if you have questions etc I'm usually good about either saying "Yeah, I think it'd be fun to try to implement $IMPOSSIBLE_TASK" or say "No go, and this is why and here's a good workaround" On 5/18/07, Tom

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

2007-05-20 Thread Ben Tilly
On 5/20/07, Uri Guttman <[EMAIL PROTECTED]> wrote: > > "BT" == Ben Tilly <[EMAIL PROTECTED]> writes: > > BT> The purpose of using goto there is in case some code uses caller() and > BT> could get confused about the extra subroutine. (For instance Carp > BT> would be likely to warn at the

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

2007-05-20 Thread Uri Guttman
> "BT" == Ben Tilly <[EMAIL PROTECTED]> writes: BT> The purpose of using goto there is in case some code uses caller() and BT> could get confused about the extra subroutine. (For instance Carp BT> would be likely to warn at the enclosing subroutine that you defined.) i ran into that pr

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 ta

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

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

2007-05-17 Thread Tom Metro
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 ponder this, but I believe using SymbolTable will just provi

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

2007-05-17 Thread Greg London
Gak. One more time. my $instance_to_skip = $mut; my $intercept_method2 = sub { my $obj=shift(@_); if($obj eq $instance_to_skip) { return; } else { return ($obj->method2(@_)); # may have to play with caller() to get return context if can return scalar and list context.

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

2007-05-17 Thread Greg London
Hm, not a sub{}. You'd have to insert a sub that would check the reference of the instance and compare it to the one you want to bypass. If they're equal, skip. if not equal then call method2. something like. my $instance_to_skip = $mut; my $intercept = sub { my $obj=shift(@_);

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

2007-05-17 Thread Greg London
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. http://backpan.cpan.org/authors/id/G/GS/GSLONDON/SymbolTable-0.02.readme (paste) SymbolTable - An easy interface to

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

2007-05-17 Thread Tom Metro
While writing unit tests for a module I ran across a few challenges... Given a module like: package Module::Under::Test; sub method1 { ... $self->method2( ... ); ... } To properly unit test this I want to replace method2 with a mock method so that I am only testing the actions