Skip to content

Commit

Permalink
[crypt.pl] introduce X::Hanoi type
Browse files Browse the repository at this point in the history
Now all the hanoi-related exceptions inherit from it.
moritz++ for suggestion.
  • Loading branch information
Carl Masak committed Jul 2, 2012
1 parent 2fecc91 commit 1f2e689
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions crypt.pl
Expand Up @@ -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;

Expand All @@ -41,7 +44,7 @@
}
}

class X::Hanoi::NoSuchRod is Exception {
class X::Hanoi::NoSuchRod is X::Hanoi {
has $.rod;
has $.name;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -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($_:) {
Expand Down

0 comments on commit 1f2e689

Please sign in to comment.