Skip to content

Instantly share code, notes, and snippets.

@ugexe
Last active July 5, 2017 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugexe/8817d4244fe13b6a6be33e2026fb8a0d to your computer and use it in GitHub Desktop.
Save ugexe/8817d4244fe13b6a6be33e2026fb8a0d to your computer and use it in GitHub Desktop.

CHANGES

%?RESOURCES

Return IO::Handle-like object (same as Distribution.content)

Currently you can pass rakudo a Distribution object to be installed that pipes all of its content from some (possibly remote, encoded, etc) source, but %?RESOURCES returns an IO::Path. This means you have to save the content of anything in %?RESOURCES to disk.

Instead %?RESOURCES{$key} could mimick Distribution.content("resources/$key"), returning an IO::Handle-like object. The "path" can then be accessed as %?RESOURCES{$key}.path, or the content itself as %?RESOURCES{$key}.open.slurp.

This requires some change in mindset usage wise, because although .open.slurp should always work (access to the resource's bytes) .path might be a url, nil, etc instead of a file path. In other words: this allows something like zef to be loaded without writing to disk (which just uses %?RESOURCES to access config data - it doesn't care about location) but something like Inline::Perl5 that needs to pass an actual path string would need to cope... some naive solutions:

  • Authors using %RESOURCES should add logic to complain if the CUR loading it doesn't give a IO::Path for %?RESOURCES.path. Something like requiring Distribution::Locally somewhere, or adding it conditionally like/with Distribution::Builder?

  • Do it like auto-precompile where the content gets turned into an actual path somewhere if .path is ever called (by saving the content to a temporary file). example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment