Skip to content

Instantly share code, notes, and snippets.

@ab5tract
Created March 13, 2015 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ab5tract/1ee13c094f0ccc34a180 to your computer and use it in GitHub Desktop.
Save ab5tract/1ee13c094f0ccc34a180 to your computer and use it in GitHub Desktop.
More proxy adventures
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;
+ 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