On Fri, Jul 09, 2004 at 10:40:54AM +0100, Fergal Daly wrote:
> Is there a LexWrap equivalent of
> 
> use Test::Builder::Vapour::Override;
> 
> sub diag {
>   my ($self, $diag) = @_;
>   $self->SUPER::diag(colour_me($diag));
> }
> 
> ? It seems that LexWrap wrappers can't do this as they can't change the
> args.

Never underestimate The Damian.

#!/usr/bin/perl -w

use Hook::LexWrap;
use Test::Builder;
use Term::ANSIColor;

wrap *Test::Builder::diag, pre => sub {
    $_[1]   = color('red') . $_[1];
    $_[-2]  =~ s/$/color 'reset'/e;
};

use Test::More tests => 1;

fail("Its fun to COLOR!");

Seems altering the elements of @_ works but adding them does not.  He's
relying on @_ aliasing rather than passing @_ around explicitly.  I guess
only the elements of @_ are aliased, not the whole array.

If you need to add/delete from @_ you can write your wrappers the long
way around using Sub::Uplevel or, if you don't need a posthandler, 
goto &sub.


> If you want to make it all possible, via events and hooks then I think it
> does require putting callbacks into or around all the relevant methods -
> which is what I thought you were proposing in the first mail. Not difficult
> but not trivial either.

I'm considering it for The Future.  I'll have my robot zip on down in my 
flying car to pick you up and we'll talk about it some more.


> While you're here, any chance you'd consider converting Test::Builder to be
> hash based rather than class based with a way of creating new instances.
> Obviously there should be only 1 real Test::Builder object but allowing
> other instances would make test-module testing easier and test nesting
> (suites of suites etc) possible,

Yes, this is planned for 0.50.  If nothing else it will let Test::Builder
test itself and make Mark Fowler handy.


-- 
Michael G Schwern        [EMAIL PROTECTED]  http://www.pobox.com/~schwern/
Death was thought to be fatal.
        -- Craig A. Berry in <[EMAIL PROTECTED]>

Reply via email to