Rules / Types, classes & roles / basic

Proxy Reference

Item container with custom storage and retrieval

What it is #

Routines #

Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.

method new #

method new(:&FETCH!, :&STORE! --> Proxy:D)

Returns Proxy:D.

Creates a new Proxy object. &FETCH is called with one argument (the proxy object) when the value is accessed, and must return the value that the fetch produces. &STORE is called with two arguments (the proxy object, and the new value) when a new value is stored in the container.

Examples, run three ways #

Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.

1 no-output · 1 rakupp-differs

class Proxy {}

Not executed: the documentation states no expected output for this example.

sub double() is rw {
my $storage = 0;
Proxy.new(
    FETCH => method ()     { $storage * 2    },
    STORE => method ($new) { $storage = $new },
)
}
my $doubled := double();
$doubled = 4;
say $doubled;       # OUTPUT: «8␤»
Documentation
8
Rakudo
8
Raku++
0

Raku++ disagrees with both the documentation and Rakudo — a defect.