Skip to content

Instantly share code, notes, and snippets.

@treyharris
Last active June 21, 2019 21:29
Show Gist options
  • Save treyharris/4c5983b9b5c9f9eb0ad5ebe30235defd to your computer and use it in GitHub Desktop.
Save treyharris/4c5983b9b5c9f9eb0ad5ebe30235defd to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
proto MAIN($) is export { * }
package My-Fourth-Modules-Script {
multi MAIN($x) {
say "This is the inside MAIN called with $x";
}
}
# multi sub MAIN($x) {
# say "This is the outer MAIN called with $x";
# My-Second-Modules-Script::MAIN($x);
# }
# $ ./My-Fourth-Modules-Script.pm6
# No usage information could be determined
# $ ./My-Fourth-Modules-Script.pm6 32
# No usage information could be determined
#!/usr/bin/env perl6
module My-Modules-Script {
sub MAIN($x) { # Note that `is export` here makes no change in behavior
say "This is the inside MAIN called with $x";
}
}
sub MAIN($x) {
say "This is the outer MAIN called with $x";
My-Modules-Script::MAIN($x);
}
#!/usr/bin/env perl6
module My-Second-Modules-Script {
sub NOT-MAIN($x) is export {
say "This is the inside MAIN called with $x";
}
}
sub MAIN($x) {
say "This is the outer MAIN called with $x";
My-Second-Modules-Script::NOT-MAIN($x);
}
# Output:
# % ./My-Second-Modules-Script.pm6
# Usage:
# ./My-Second-Modules-Script.pm6 <x>
# % ./My-Second-Modules-Script.pm6 42
# This is the outer MAIN called with 42
# Could not find symbol '&NOT-MAIN'
# in sub MAIN at ./My-Second-Modules-Script.pm6 line 11
# in block <unit> at ./My-Second-Modules-Script.pm6 line 3
#!/usr/bin/env perl6
proto MAIN($) is export { ... }
module My-Third-Modules-Script {
multi MAIN($x) {
say "This is the inside MAIN called with $x";
}
}
multi sub MAIN($x) {
say "This is the outer MAIN called with $x";
My-Second-Modules-Script::NOT-MAIN($x);
}
# % ./My-Third-Modules-Script.pm6 32
# Stub code executed
# in sub MAIN at ./My-Third-Modules-Script.pm6 line 3
# in block <unit> at ./My-Third-Modules-Script.pm6 line 5
# % ./My-Third-Modules-Script.pm6
# Usage:
# ./My-Third-Modules-Script.pm6 <x>
% ./My-Modules-Script.pm6
Usage:
./My-Modules-Script.pm6 <x>
% ./My-Modules-Script.pm6 42
This is the outer MAIN called with 42
No such method 'MAIN' for invocant of type 'My-Modules-Script'
in sub MAIN at ./My-Modules-Script.pm6 line 11
in block <unit> at ./My-Modules-Script.pm6 line 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment