diff options
author | dakkar <dakkar@thenautilus.net> | 2011-08-29 13:54:58 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2011-08-29 13:54:58 +0100 |
commit | 1776bd778db4f6ed72eed47602877ab7a8fb904f (patch) | |
tree | e04b0500dbe53aed33be95d311f46e8e40775017 /lib/Enigmatic/Types.pm | |
parent | rotor boxes (diff) | |
download | Enigmatic-1776bd778db4f6ed72eed47602877ab7a8fb904f.tar.gz Enigmatic-1776bd778db4f6ed72eed47602877ab7a8fb904f.tar.bz2 Enigmatic-1776bd778db4f6ed72eed47602877ab7a8fb904f.zip |
reflectors, in box, and some refactor
Diffstat (limited to 'lib/Enigmatic/Types.pm')
-rw-r--r-- | lib/Enigmatic/Types.pm | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/lib/Enigmatic/Types.pm b/lib/Enigmatic/Types.pm index 12cb414..ed0be32 100644 --- a/lib/Enigmatic/Types.pm +++ b/lib/Enigmatic/Types.pm @@ -1,6 +1,6 @@ package Enigmatic::Types; use DAKKAR::p; -use MooseX::Types -declare => [qw(Letter WiringMap RotorPos)]; +use MooseX::Types -declare => [qw(Letter WiringMap ReflWiringMap RotorPos)]; use MooseX::Types::Moose qw(Str Int); use MooseX::Types::Structured qw(Map); @@ -16,16 +16,29 @@ subtype WiringMap, $in eq $out and $in eq ['A'..'Z']->join; }; +subtype ReflWiringMap, + as WiringMap, + where { + my %reverse; @reverse{values %$_} = keys %$_; + (join '',@reverse{keys %$_}) eq $_->values->join; + }; + +sub _coerce_wiring { + my @out = $_[0]->uc->split(qr//)->flatten; + croak "invalid wiring string <$_>" + unless @out == 26; + my %ret; + @ret{'A'..'Z'}=@out; + \%ret; +} + coerce WiringMap, from Str, - via { - my @out = $_->uc->split(qr//)->flatten; - croak "invalid wiring string <$_>" - unless @out == 26; - my %ret; - @ret{'A'..'Z'}=@out; - \%ret; - }; + via \&_coerce_wiring; + +coerce ReflWiringMap, + from Str, + via \&_coerce_wiring; subtype RotorPos, as Int, |