Skip to content

Instantly share code, notes, and snippets.

@Xliff
Created November 1, 2020 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xliff/f4af67ed380d1024a19d68975e4ed759 to your computer and use it in GitHub Desktop.
Save Xliff/f4af67ed380d1024a19d68975e4ed759 to your computer and use it in GitHub Desktop.
Default values in MAIN

This to replace the code at src/core.c/Main.pm6#L258:

if $param.WHY and (@arg-help.grep:{ .key eq $argument}) == Empty {
  my $why = $param.WHY.contents; # Use first defined
  if $param.default -> $d {
    my $def = $d();
    given $def {
      # Long number
      # Long string
      when Cool {
        when Match    { $_ = 'default Match object' }
        when Rational { $_ .= Num;      proceed     }
        when IO::Path { $_ .= absolute; proceed     }
        default  {
          $_ .= perl;
          if .chars > 20 {
            $_ .= substr(0, 16);
            $_ ~= '';
          }
        }
      }

      default {
        $_ = "default { .^name } object"
      }
    }
    $why ~= "[default: { $def }]";
  }
  @arg-help.push($argument => $why);
}

Any thoughts? If you'd rather this be a PR, I'll have to work more on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment