Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make Dynamic variable not found a proper exception
  • Loading branch information
lizmat committed Sep 7, 2014
1 parent bf66354 commit e9181cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -72,6 +72,12 @@ my class X::AdHoc is Exception {
method Numeric() { $.payload.Numeric }
}

my class X::Dynamic::NotFound is Exception {
has $.name;
method message() {
"Dynamic variable $.name not found";
}
}
my class X::Method::NotFound is Exception {
has $.invocant;
has $.method;
Expand Down
13 changes: 10 additions & 3 deletions src/core/stubs.pm
Expand Up @@ -9,6 +9,7 @@ my class X::AdHoc { ... }
my class FatRat { ... }
my class Enum { ... }
my class X::OutOfRange { ... }
my class X::Dynamic::NotFound { ... }

my role QuantHash { ... }
my role Setty { ... }
Expand All @@ -27,9 +28,15 @@ sub DYNAMIC(\name) is rw {
my Mu $x := nqp::getlexdyn(nqp::unbox_s(name));
if nqp::isnull($x) {
my str $pkgname = nqp::replace(nqp::unbox_s(name), 1, 1, '');
if nqp::existskey(GLOBAL.WHO, $pkgname) { $x := nqp::atkey(GLOBAL.WHO, $pkgname) }
elsif nqp::existskey(PROCESS.WHO, $pkgname) { $x := nqp::atkey(PROCESS.WHO, $pkgname) }
else { fail "Dynamic variable {name} not found" }
if nqp::existskey(GLOBAL.WHO, $pkgname) {
$x := nqp::atkey(GLOBAL.WHO, $pkgname);
}
elsif nqp::existskey(PROCESS.WHO, $pkgname) {
$x := nqp::atkey(PROCESS.WHO, $pkgname);
}
else {
fail X::Dynamic::NotFound.new(:name(name));
}
}
$x
}
Expand Down

0 comments on commit e9181cd

Please sign in to comment.