Skip to content

Commit

Permalink
Ban .length and .bytes from method not found handler
Browse files Browse the repository at this point in the history
As suggested on #perl6
  • Loading branch information
lizmat committed Mar 7, 2014
1 parent 17c92be commit ef8b8f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
14 changes: 0 additions & 14 deletions src/core/Any.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ my class Pair { ... }
my class Range { ... }
my class X::Bind::Slice { ... }
my class X::Bind::ZenSlice { ... }
my class X::Method::Banned { ... }

my class Any { # declared in BOOTSTRAP
# my class Any is Mu {
Expand Down Expand Up @@ -264,19 +263,6 @@ my class Any { # declared in BOOTSTRAP

method KeySet() { DEPRECATED("'SetHash'"); self.SetHash }
method KeyBag() { DEPRECATED("'BagHash'"); self.BagHash }

method length is hidden_from_backtrace {
fail X::Method::Banned.new(
banned => ".length",
didyoumean => ".chars, .graphs or .codes",
);
}
method bytes is hidden_from_backtrace {
fail X::Method::Banned.new(
banned => ".bytes",
didyoumean => ".encode(\$encoding).bytes",
);
}
}
Metamodel::ClassHOW.exclude_parent(Any);

Expand Down
22 changes: 10 additions & 12 deletions src/core/Exception.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,16 @@ my class X::Method::NotFound is Exception {
has $.typename;
has Bool $.private = False;
method message() {
$.private
?? "No such private method '$.method' for invocant of type '$.typename'"
!! "No such method '$.method' for invocant of type '$.typename'";
my $message = $.private
?? "No such private method '$.method' for invocant of type '$.typename'"
!! "No such method '$.method' for invocant of type '$.typename'";
if $.method eq 'length' {
$message ~= "\nDid you mean 'chars', 'graphs' or 'codes'?";
}
elsif $.method eq 'bytes' {
$message ~= "\nDid you mean '.encode(\$encoding).bytes'?";
}
$message;
}
}

Expand All @@ -86,15 +93,6 @@ my class X::Method::InvalidQualifier is Exception {
}
}

my class X::Method::Banned is Exception {
has $.banned = "something";
has $.didyoumean = "something else";
method message() {
qq{"$.banned" is banned in Perl 6.
Did you mean $.didyoumean instead?}
}
}

sub EXCEPTION(|) {
my Mu $vm_ex := nqp::shift(nqp::p6argvmarray());
my Mu $payload := nqp::getpayload($vm_ex);
Expand Down

0 comments on commit ef8b8f9

Please sign in to comment.