Background:  I know many of you aren't working with Perl 6 and if you're not 
interested, feel free to ignore :)

I'm working on Test.pm, the core Perl 6 testing module.  I'm trying to get it 
up to speed, including diagnostics.  What follows is a tiny problem with &skip.

The skip multisub in Rakudo's Test.pm is defined like this:

  multi sub skip()              is export() { proclaim(1, "# SKIP"); }
  multi sub skip($desc)         is export() { proclaim(1, "# SKIP " ~ $desc); }
  multi sub skip($count, $desc) is export() {
      for 1..$count {
          proclaim(1, "# SKIP " ~ $desc);
      }
  }

The
first is reasonable, but the second and third are awkward.  We have
positional parameters whose position changes based upon the number of
arguments.  We could do something like this:

  multisub skip();
  multisub skip(Int $count);
  multisub skip(Str $desc);
  multisub skip(Int $count, Str $desc);

However, that's going to break if $count is a string, right?  Thought this 
might work as a heuristic for that third definition:

  # Won't get called unless the string has a non-digit in it
  multisub skip( Str $desc where { $desc ~~ /\D/ } );

Thus, you could call this and it will still DWIM:

  if $cond {
      skip "3";
  else {
      # run three tests
  }

Obviously, not having a description is bad, but so are straightjackets.  Also, 
I'm not comfortable with the heuristic nature of this.

I am thinking that the Perl 5 way may be better here.  We have (effectively):

  multisub skip(Str $desc);
  multisub skip(Str $desc, Int $count);

Otherwise, we stick with named parameters, but that's a bit odd since every 
other function exported uses positional parameters.

Thoughts?

Cheers,
Ovid
--
Buy the book         - http://www.oreilly.com/catalog/perlhks/
Tech blog            - http://use.perl.org/~Ovid/journal/
Twitter              - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6

Reply via email to