blob: a600b4325243ed489b757564eaa425996d0fb578 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package Enigmatic::Rotor; use DAKKAR::p 'class'; use Enigmatic::Types qw(WiringMap Letter RotorPos); has wiring => ( is => 'ro', isa => WiringMap, coerce => 1, ); has ring_setting => ( is => 'rw', isa => RotorPos, default => 0, ); around BUILDARGS => sub { my $orig = shift; my $class = shift; if ( @_ == 1 && !ref $_[0] ) { return $class->$orig( wiring => $_[0] ); } else { return $class->$orig(@_); } }; sub map { my $self = shift; my ($letter) = pos_validated_list( \@_, { isa => Letter }, ); return $self->wiring->at($self->_apply_ring_setting($letter)); } sub _apply_ring_setting { my $self = shift; my ($letter) = pos_validated_list( \@_, { isa => Letter }, ); return chr( (ord($letter) - ord('A') + $self->ring_setting) % 26 +ord('A') ); }
|