File tree Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ sub url-munge($_) {
33
33
my @ menu =
34
34
(' language' ,' ' ) => (),
35
35
(' type' , ' Types' ) => <basic composite domain-specific exceptions >,
36
- (' routine' , ' Routines' ) => <sub method term operator >,
36
+ (' routine' , ' Routines' ) => <sub method term operator trait >,
37
37
# ('module', 'Modules' ) => (),
38
38
# ('formalities','' ) => ();
39
39
;
Original file line number Diff line number Diff line change
1
+ = begin pod
2
+
3
+ = TITLE class Variable
4
+
5
+ = SUBTITLE Object representation of a variable for use in traits
6
+
7
+ class Variable { ... }
8
+
9
+ Variables have a wealth of compile-time information, but at run time, accesses
10
+ to to a variable usually act on the value stored inside the variable, not the
11
+ variable itself.
12
+
13
+ Class C < Variable > holds the compile-time information that traits can use to
14
+ introspect and manipulate variables.
15
+
16
+ = head1 Routines
17
+
18
+ = head2 method name
19
+
20
+ method name(Variable:D: str)
21
+
22
+ Returns the name of the variable, including the sigil.
23
+
24
+ = head2 trait is default
25
+
26
+ multi sub trait_mod:<is>(Variable:D, :$default!)
27
+
28
+ Sets the default value with which a variable is initialized, and to which it
29
+ is reset when Nil is assigned to it.
30
+
31
+ my Int $x is default(42);
32
+ say $x; # 42
33
+ $x = 5;
34
+ say $x; # 5
35
+ # explicit reset:
36
+ $x = Nil;
37
+ say $x; # 42
38
+
39
+ = head2 trait is dynamic
40
+
41
+ multi sub trait_mod:<is>(Variable:D, :$dynamic)
42
+
43
+ Marks a variable as dynamic, that is, accessible from inner dynamic scopes
44
+ without being in an inner lexical scope.
45
+
46
+ = begin code :allow<B L>
47
+ sub introspect() {
48
+ say B < $CALLER::x > ;
49
+ }
50
+ my $x B < is dynamic > = 23;
51
+ introspect; # 23
52
+ {
53
+ # not dynamic
54
+ my $x;
55
+ introspect() # dies with an exception of L < type X::Caller::NotDynamic|/type/X::CallerNotDynamic >
56
+ }
57
+ = end code
58
+
59
+ = end pod
You can’t perform that action at this time.
0 commit comments