FWIW, this indeed feels as a bug to me

> On 27 Nov 2016, at 00:51, brian d foy (via RT) <perl6-bugs-follo...@perl.org> 
> wrote:
> 
> # New Ticket Created by  "brian d foy" 
> # Please include the string:  [perl #130185]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/Ticket/Display.html?id=130185 >
> 
> 
> Here's a short Perl 6 program that declare a `MAIN` subroutine. I
> should only see output if I execute the program directly:
> 
> $ cat main.pm6
> sub MAIN { say "Called as a program!" }
> 
> And I see output when I execute the program directly:
> 
> $ perl6 main.pm6
> Called as a program!
> 
> If I load it as a module, I see no output:
> 
> $ perl6 -I. -Mmain -e "say 'Hey'"
> Hey
> 
> Same if I `use` it from inside the program, I see no output:
> 
> $ perl6 -I. -e 'use main'
> 
> But, if I use `require`, I get output:
> 
> $ perl6 -I. -e 'require <main.pm6>'
> Called as a program!
> 
> [Synopsis 06](http://design.perl6.org/S06.html#Declaring_a_MAIN_subroutine)
> literally says _the compilation unit was directly invoked rather than
> by being required_. Is there something else going on because `require`
> works at runtime (although S06 doesn't exclude that)?
> 
> I get the same behaviour with Rakudo Star 2016.07 and 2016.10.
> 
> I realize that the Synopses are dated. Absent anything else noting
> divergence from the design docs or the lack of documentation of the
> feature in the docs, I think most people are going to assume the
> original intent.
> 
> MAIN is very lightly documented in Language/functions.pod6. The
> verbiage "relevant phasers" should be expanded so a reader knows whats
> relevant. I didn't find anything in the docs that said MAIN shouldn't
> run in some circumstances and not others. The docs seem to say that it
> will always run, but that's not true either.
> 
> Also asked on Stackoverflow: http://stackoverflow.com/q/40778852/2766176

Reply via email to