Skip to content

Instantly share code, notes, and snippets.

@alabamenhu
Created April 29, 2019 01:58
Show Gist options
  • Save alabamenhu/df1a9657b7d2ab8b87c2fb23cfdab3db to your computer and use it in GitHub Desktop.
Save alabamenhu/df1a9657b7d2ab8b87c2fb23cfdab3db to your computer and use it in GitHub Desktop.
Using selective import/export for modules
============ Inside a module file ============
unit module Sustenance;
sub eat-apples is export(:apples, :eat) { … }
sub eat-oranges is export(:oranges, :eat) { … }
sub eat-bananas is export(:bananas, :eat) { … }
sub drink-water is export(:water, :drink) { … }
sub drink-coke is export(:coke, :drink) { … }
=========== Inside your main script ==========
use Sustenance :apples; # only makes eat-apples available.
use Sustenance :apples, :oranges; # only makes eat-apples and eat-oranges available
use Sustenance :eat; # makes eat-apples, eat-oranges, and eat-bananas available
use Sustenance :drink; # makes drink-water, drink-coke available
use Sustenance :apples, :water; # makes eat apples and drink-water available
use Sustenance :eat, :drink; # makes all of the subs available
use Sustenance :ALL; # also makes all of the subs available
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment