@@ -20,6 +20,11 @@ There are many syntaxes for creating C<Pair>s:
20
20
:key<value1 value2>; # But this is key => <value1 value2>
21
21
:foo(127); # short for foo => 127
22
22
:127foo; # the same foo => 127
23
+
24
+ You can also use an I < identifier-like literal > as key; this will not need the
25
+ quotes as long as it follows the syntax of
26
+ L < ordinary identifiers|/syntax/%20identifiers.html#Ordinary_identifiers > :
27
+
23
28
(foo => 127) # the same foo => 127
24
29
25
30
Variants of this are
@@ -62,9 +67,9 @@ Any variable can be turned into a C<Pair> of its name and its value.
62
67
say $p; # OUTPUT: «bar => 10»
63
68
64
69
65
- It is worth noting that when assigning a L < Scalar|/type/Scalar > as value of a C < Pair >
66
- the value holds the container of the value itself. This means that it is possible to change the
67
- value from outside of the C < Pair > itself:
70
+ It is worth noting that when assigning a L < Scalar|/type/Scalar > as value of a
71
+ C < Pair > the value holds the container of the value itself. This means that it is
72
+ possible to change the value from outside of the C < Pair > itself:
68
73
69
74
= begin code
70
75
my $v = 'value A';
@@ -75,12 +80,13 @@ $v = 'value B';
75
80
$pair.say; # OUTPUT: a => value B
76
81
= end code
77
82
78
- Please also note that this behavior is totally unrelated to the way used to build the C < Pair > itself
79
- (i.e., explicit usage of C < new > , use of colon, fat arrow), as well as if the C < Pair > is bound
80
- to a variable.
83
+ Please also note that this behavior is totally unrelated to the way used to
84
+ build the C < Pair > itself (i.e., explicit usage of C < new > , use of colon, fat
85
+ arrow), as well as if the C < Pair > is bound to a variable.
81
86
82
- It is possible to change the above behaviour forcing the C < Pair > to remove the scalar container
83
- and to hold the effective value itself via the method L < freeze|/type/Pair#method_freeze > :
87
+ It is possible to change the above behaviour forcing the C < Pair > to remove the
88
+ scalar container and to hold the effective value itself via the method
89
+ L < freeze|/type/Pair#method_freeze > :
84
90
85
91
= begin code
86
92
my $v = 'value B';
@@ -116,18 +122,19 @@ it and checks invocant's value C<.ACCEPTS> that value:
116
122
say %(:42a) ~~ :42a; # OUTPUT: «True»
117
123
say %(:42a) ~~ :10a; # OUTPUT: «False»
118
124
119
- If C < topic > is another L < Pair|/type/Pair > , checks the invocant's value C < .ACCEPTS > the
120
- C < topic's > value. Note that the keys are not considered and can be different:
125
+ If C < topic > is another L < Pair|/type/Pair > , checks the invocant's value
126
+ C < .ACCEPTS > the C < topic's > value. Note that the keys are not considered and can
127
+ be different:
121
128
122
129
say :42a ~~ :42a; # OUTPUT: «True»
123
130
say :42z ~~ :42a; # OUTPUT: «True»
124
131
say :10z ~~ :42a; # OUTPUT: «False»
125
132
126
133
If C < topic > is any other value, uses the invocant's key as the name of the
127
134
method to call on C < topic > and check's its L « C < .Bool > |/routine/Bool» is the same
128
- as C < .Bool > of the invocant's value. This form can be used to check L < Bool|/type/Bool > values
129
- of multiple methods on the same object, such as L < IO::Path > , by using
130
- L < Junctions|/type/Junction > :
135
+ as C < .Bool > of the invocant's value. This form can be used to check
136
+ L < Bool|/type/Bool > values of multiple methods on the same object, such as
137
+ L < IO::Path > , by using L < Junctions|/type/Junction > :
131
138
132
139
say "foo" .IO ~~ :f & :rw; # OUTPUT: «False»
133
140
say "/tmp".IO ~~ :!f; # OUTPUT: «True»
0 commit comments