-
-
Save ab5tract/1ee13c094f0ccc34a180 to your computer and use it in GitHub Desktop.
More proxy adventures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Codeword { | |
has Sub $.scrambler is rw; | |
has Str $!encoded-string; | |
submethod BUILD { | |
my sub scrambler { $^s.trans: 'a..mn..z' => 'n..za..m', :ii } | |
$!scrambler = &scrambler; | |
$!encoded-string = scrambler("good"); | |
} | |
method codeword returns Str is rw { | |
return Proxy.new( | |
FETCH => sub ($) { $!encoded-string }, | |
STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($s) } | |
); | |
} | |
} | |
my $code = Codeword.new; | |
$code.codeword; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ proxy-test.p6 (19 - 21) | |
| | |
| my $code = Codeword.new; | |
| say $code.encoded-string; | |
> | |
+ proxy-test.p6 (11 - 18) | |
| | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
| } | |
| } | |
> | |
+ proxy-test.p6 (12 - 16) | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
> | |
+ proxy-test.p6 (12 - 16) | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
> | |
+ proxy-test.p6 (12 - 16) | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
> | |
+ proxy-test.p6 (12 - 16) | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
> | |
+ proxy-test.p6 (12 - 16) | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
> | |
+ proxy-test.p6 (12 - 16) | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
> | |
+ proxy-test.p6 (12 - 16) | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
> | |
+ proxy-test.p6 (12 - 16) | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
> | |
+ proxy-test.p6 (12 - 16) | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
> | |
+ proxy-test.p6 (12 - 16) | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
> | |
+ proxy-test.p6 (12 - 16) | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
> | |
+ proxy-test.p6 (12 - 16) | |
| method encoded-string returns Str is rw { | |
| return Proxy.new( | |
| FETCH => sub ($) { $!encoded-string }, | |
| STORE => sub ($, Str $s) { $!encoded-string = $!scrambler($... | |
| ); | |
> | |
tbbq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment