* Ovid <[EMAIL PROTECTED]> [2006-09-26T09:19:46]
> > It would be nice if I could just write 'use My::Test::More' in my
> > test scripts and have that provide what I need
> 
> Side note:  yes, it's trivial for me to write an extra module which provide
> an environment variable or something similar for this, but I like the idea of
> hooking this onto Test::More since we rely on this module for *every* test
> script and thus can't forget to include it.

I thought this could be done in a nice simple way by exporting curried methods,
but then I remembered that using methods would chomp prototypes.  The attached
code has a few jagged edges (doesn't use exported_to, etc), but I gave up on
polishing them when I realized the prototype issue; maybe B::something can fix
that.

This would have made it possible to "subclass" Test::More, but maintain the
interface, so you could write:

  package Test::Most;
  use base qw(Moog);
  sub ok {
    my ($class, $bool, $comment) = @_;

    for (1..10) { $class->SUPER($bool, $comment); }
  }

This was probably more a way to waste a couple minutes than a good path
forward, but YMMV.

-- 
rjbs
package Moog;

use strict;
use warnings;

use Test::More ();
use Sub::Exporter ();
use Sub::Exporter::Util ();
use base qw(Test::Builder::Module);

BEGIN {
  no strict 'refs';
  for my $sub (@Test::More::EXPORT) {
    *{$sub} = sub { shift; &{"Test::More::$sub"}(@_); };
  }

  Sub::Exporter::setup_exporter({
    as         => 'import_code',
    exports    => [
      map { $_ => Sub::Exporter::Util::curry_class($_) } @Test::More::EXPORT
    ],
    groups     => { default => [':all'] },
  });
}

sub import_extra {
  my ($class, $things) = @_;
  my %ok = map { $_ => 1 } @Test::More::EXPORT;
  $class->import_code(
    { into_level => 2, },
    grep { $ok{$_} } @$things
  );
}

1;

Reply via email to