@@ -1192,7 +1192,58 @@ C<$?FILE> and C<$?LINE> are also available from L<CallFrame|/type/CallFrame> as
1192
1192
the L < C < file > |/type/CallFrame#method_file> and
1193
1193
L < C < line > |/type/CallFrame#method_line> methods, respectively.
1194
1194
1195
- = head3 Other compile-time variables:
1195
+ = head3 X < %?RESOURCES >
1196
+
1197
+ A compile-time variable available within code of a X < Distribution > .
1198
+
1199
+ It contains a hash that provides compile and runtime access to files
1200
+ associated with the Distribution of the current compilation unit. It
1201
+ is used to access a special storage for Distribution-wide static files
1202
+ (for example, examples of configuration files, templates etc).
1203
+
1204
+ To add a file to a distribution, it is placed under C < resources > directory:
1205
+
1206
+ = begin code :lang<text>
1207
+ Module-Foo/
1208
+ ├── lib
1209
+ │ └── Module
1210
+ │ └── Foo.pm6
1211
+ ├── META6.json
1212
+ ├── README.md
1213
+ └── resources
1214
+ └── images
1215
+ └── foo.jpg
1216
+ = end code
1217
+
1218
+ Then a relative path (starting from root directory of a distribution)
1219
+ to a file is specified under C < "resources" > field in META6.json file:
1220
+
1221
+ = begin code :lang<js>
1222
+ "resources": [
1223
+ "images/foo.jpg"
1224
+ ]
1225
+ = end code
1226
+
1227
+ Every resource file is added to an installed Distribution and is
1228
+ accessible using a Hash-like access to C < %?RESOURCES > :
1229
+
1230
+ = begin code :skip<resources-example>
1231
+ my $foo-IO = %?RESOURCE < images/foo.jpg > ; # gets an object you can slurp
1232
+ my $foo-IO = %?RESOURCE < images/foo.jpg > .absolute; # gets an absolute path to a file
1233
+ my $foo-IO = %?RESOURCE < images/foo.jpg > .open; # gets an opened IO::Handle to work with
1234
+ = end code
1235
+
1236
+ Note that paths and names of resource files can be mangled in an
1237
+ installed distribution, so do not rely on their values in any other
1238
+ case besides using them as keys for C < %?RESOURCES > variable.
1239
+
1240
+ C < %?RESOURCES > variable is not implemented as a plain Hash, but an
1241
+ instance of C < Distribution::Resources > type, so do not expect to see
1242
+ all available resource files in a distribution by printing or other
1243
+ ways to inspect its value. Instead, use the API described above to
1244
+ access particular files.
1245
+
1246
+ = head3 Introspection compile-time variables
1196
1247
1197
1248
X < |$?PACKAGE > X < |$?MODULE > X < |$?CLASS > X < |$?ROLE >
1198
1249
X < |$?TABSTOP > X < |$?NL > X < |$?DISTRIBUTION >
@@ -1211,6 +1262,8 @@ The following compile time variables allow for a deeper introspection:
1211
1262
With particular regard to the C < $?NL > , see the L < newline
1212
1263
pragma|/language/pragmas > .
1213
1264
1265
+ = head3 Rakudo-specific compile-time variables
1266
+
1214
1267
These variables are Rakudo specific, with all the corresponding caveats:
1215
1268
= for table
1216
1269
$?BITS Number of data-path bits of the platform the program is being compiled upon.
0 commit comments