syntax %?RESOURCES

Documentation for syntax %?RESOURCES assembled from the following types:

language documentation Variables

From Variables

(Variables) %?RESOURCES

A compile-time variable available within code of a Distribution.

It contains a hash that provides compile and runtime access to files associated with the Distribution of the current compilation unit. It is used to access a special storage for Distribution-wide static files (for example, examples of configuration files, templates etc).

To add a file to a distribution, it is placed under resources directory:

Module-Foo/
├── lib
│   └── Module
│       └── Foo.pm6
├── META6.json
├── README.md
└── resources
    └── images
        └── foo.jpg

Then a relative path (starting from the root directory of a distribution) to a file is specified under "resources" field in META6.json file:

"resources": [
    "images/foo.jpg"
]

Every resource file is added to an installed Distribution and is accessible using a Hash-like access to %?RESOURCES:

my $foo-IO = %?RESOURCES<images/foo.jpg>;          # gets an object you can slurp 
my $foo-IO = %?RESOURCES<images/foo.jpg>.absolute# gets an absolute path to a file 
my $foo-IO = %?RESOURCES<images/foo.jpg>.open;     # gets an opened IO::Handle to work with 

Note that paths and names of resource files can be mangled in an installed distribution, so do not rely on their values in any other case besides using them as keys for the %?RESOURCES variable.

The %?RESOURCES variable is not implemented as a plain Hash, but as an instance of the Distribution::Resources type, so do not expect to see all available resource files in a distribution by printing or other ways to inspect its value. Instead, use the API described above to access particular files.