Skip to content

Instantly share code, notes, and snippets.

@masak
Created June 12, 2013 15:59
Show Gist options
  • Save masak/5766668 to your computer and use it in GitHub Desktop.
Save masak/5766668 to your computer and use it in GitHub Desktop.
MAIN subs in modules in Perl 6
$ cat Foo.pm
module Foo;
sub MAIN() {
say "OH HAI";
}
$ perl6 Foo.pm
$ # no output
According to S06:3364:
At the end of
the mainline code, however, a C<MAIN> subroutine will be called with
whatever command-line arguments remain in C<@*ARGS>. This call is
performed if and only if:
=over
=item a)
the compilation unit was directly invoked rather than
by being required by another compilation unit, and
=item b)
the compilation unit declares a C<Routine> named "C<MAIN>", and
=item c)
the mainline code is not terminated prematurely, such as with an explicit call
to C<exit>, or an uncaught exception.
=back
I contend that the above example does a), b), and c). Is it a bug that it doesn't invoke MAIN?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment