File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ Synatax features:
19
19
20
20
API docs:
21
21
* KeyReducer
22
- * Proxy
23
22
24
23
Builtins:
25
24
* Str.substr-eq
Original file line number Diff line number Diff line change
1
+ = begin pod
2
+
3
+ = TITLE class Proxy
4
+
5
+ = SUBTITLE Container with custom storage and retrieval
6
+
7
+ class Proxy { ... }
8
+
9
+ A Proxy is an object that allows you to execute whenever a value is retrieved
10
+ from a contaner (C < FETCH > ) or when it is set (C < STORE > ).
11
+
12
+ To create a container that returns twice of what was stored in it, you do
13
+ something like this:
14
+
15
+ sub double() is rw {
16
+ my $storage = 0;
17
+ Proxy.new(
18
+ FETCH => method () { $storage },
19
+ STORE => method ($new) { $storage = 2 * $new }
20
+ )
21
+ }
22
+ my $doubled := double();
23
+ $doubled = 4;
24
+ say $doubled; # 8
25
+
26
+ = head1 Methods
27
+
28
+ = head2 method new
29
+
30
+ method new(:&FETCH!, :&STORE!) returns Proxy:D
31
+
32
+ Creates a new C < Proxy > object. C < &FETCH > is called with one argument (the
33
+ proxy object) when the value is accessed, and must return the value that the
34
+ fetch produces. C < &STORE > is called with two arguments (the proxy object, and
35
+ the new value) when a new value is stored in the container.
36
+
37
+ = end pod
You can’t perform that action at this time.
0 commit comments