Permalink
Browse files

[crypt.pl] introduce X::Hanoi type

Now all the hanoi-related exceptions inherit from it.
moritz++ for suggestion.
  • Loading branch information...
1 parent 2fecc91 commit 1f2e689a6f4e303493315ff1b42004cb62e98ccf @masak committed Jul 2, 2012
Showing with 11 additions and 8 deletions.
  1. +11 −8 crypt.pl
View
@@ -32,7 +32,10 @@
has $.target;
}
-class X::Hanoi::LargerOnSmaller is Exception {
+class X::Hanoi is Exception {
+}
+
+class X::Hanoi::LargerOnSmaller is X::Hanoi {
has $.larger;
has $.smaller;
@@ -41,7 +44,7 @@
}
}
-class X::Hanoi::NoSuchRod is Exception {
+class X::Hanoi::NoSuchRod is X::Hanoi {
has $.rod;
has $.name;
@@ -50,15 +53,15 @@
}
}
-class X::Hanoi::RodHasNoDisks is Exception {
+class X::Hanoi::RodHasNoDisks is X::Hanoi {
has $.name;
method message($_:) {
"Cannot move from the {.name} rod because there is no disk there"
}
}
-class X::Hanoi::CoveredDisk is Exception {
+class X::Hanoi::CoveredDisk is X::Hanoi {
has $.disk;
has @.covered_by;
@@ -73,15 +76,15 @@
}
}
-class X::Hanoi::ForbiddenDiskRemoval is Exception {
+class X::Hanoi::ForbiddenDiskRemoval is X::Hanoi {
has $.disk;
method message($_:) {
"Removing the {.disk} is forbidden"
}
}
-class X::Hanoi::DiskHasBeenRemoved is Exception {
+class X::Hanoi::DiskHasBeenRemoved is X::Hanoi {
has $.disk;
has $.action;
@@ -90,15 +93,15 @@
}
}
-class X::Hanoi::NoSuchDisk is Exception {
+class X::Hanoi::NoSuchDisk is X::Hanoi {
has $.disk;
method message($_:) {
"Cannot add a {.disk} because there is no such disk"
}
}
-class X::Hanoi::DiskAlreadyOnARod is Exception {
+class X::Hanoi::DiskAlreadyOnARod is X::Hanoi {
has $.disk;
method message($_:) {

0 comments on commit 1f2e689

Please sign in to comment.