Skip to content

Commit fdd5ef4

Browse files
authored
Merge pull request #2530 from ugexe/current-distribution
Add docs on $?DISTRIBUTION
2 parents aa2eb63 + 7f67183 commit fdd5ef4

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

doc/Language/variables.pod6

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,19 +1136,20 @@ L<C<line>|/type/CallFrame#method_line> methods, respectively.
11361136
=head3 Other compile-time variables:
11371137
11381138
X<|$?PACKAGE>X<|$?MODULE>X<|$?CLASS>X<|$?ROLE>
1139-
X<|$?GRAMMAR>X<|$?TABSTOP>X<|$?NL>X<|$?ENC>
1139+
X<|$?GRAMMAR>X<|$?TABSTOP>X<|$?NL>X<|$?ENC>X<|$?DISTRIBUTION>
11401140
11411141
The following compile time variables allow for a deeper introspection:
11421142
11431143
=for table
1144-
$?PACKAGE Which package am I in?
1145-
$?MODULE Which module am I in?
1146-
$?CLASS Which class am I in? (as variable)
1147-
$?ROLE Which role am I in? (as variable)
1148-
$?GRAMMAR Which grammar am I in?
1149-
$?TABSTOP How many spaces is a tab in a heredoc or virtual margin?
1150-
$?NL What a vertical newline "\n" means: LF, CR or CRLF
1151-
$?ENC Default encoding of various IO methods, e.g., Str.encode, Buf.decode
1144+
$?PACKAGE Which package am I in?
1145+
$?MODULE Which module am I in?
1146+
$?CLASS Which class am I in? (as variable)
1147+
$?ROLE Which role am I in? (as variable)
1148+
$?GRAMMAR Which grammar am I in?
1149+
$?TABSTOP How many spaces is a tab in a heredoc or virtual margin?
1150+
$?NL What a vertical newline "\n" means: LF, CR or CRLF
1151+
$?ENC Default encoding of various IO methods, e.g., Str.encode, Buf.decode
1152+
$?DISTRIBUTION The L<Distribution|/type/Distribution> of the current compilation unit.
11521153
11531154
With particular regard to the C<$?NL>, see the L<newline pragma|/language/pragmas>.
11541155
@@ -1189,6 +1190,27 @@ for '.' {
11891190
}
11901191
=end code
11911192
1193+
=head3 X<$?DISTRIBUTION>
1194+
1195+
C<$?DISTRIBUTION> provides access to the L<Distribution|/type/Distribution>
1196+
of the current compilation unit. This gives module authors a way to reference
1197+
other files in the distribution by their original relative path names, or to
1198+
view the meta data, without needing to know the underlying file structure (such as
1199+
how C<CompUnit::Repository::Installation> changes the file layout on installation).
1200+
1201+
=begin code
1202+
unit module MyFoo;
1203+
1204+
sub module-version {
1205+
say "MyFoo is version:";
1206+
say $?DISTRIBUTION.meta<ver>;
1207+
}
1208+
1209+
sub module-source {
1210+
say "MyFoo source code:";
1211+
say $?DISTRIBUTION.content('lib/MyFoo.pm6');
1212+
}
1213+
=end code
11921214
11931215
=head2 Dynamic variables
11941216

0 commit comments

Comments
 (0)