Skip Menu |
Report information
Id: 130185
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: comdog <brian.d.foy [at] gmail.com>
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



From: brian d foy <brian.d.foy [...] gmail.com>
To: rakudobug [...] perl.org
Date: Sat, 26 Nov 2016 18:50:24 -0500
Subject: Fwd: Should Perl 6 run MAIN if the file is required?
Download (untitled) / with headers
text/plain 1.4k
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
Date: Sun, 27 Nov 2016 11:39:00 +0100
To: "brian d foy (via RT)" <perl6-bugs-followup [...] perl.org>
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
Subject: Re: [perl #130185] Fwd: Should Perl 6 run MAIN if the file is required?
Download (untitled) / with headers
text/plain 1.8k
FWIW, this indeed feels as a bug to me Show quoted text
> On 27 Nov 2016, at 00:51, brian d foy (via RT) <perl6-bugs-followup@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
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 217b
On Sun, 27 Nov 2016 02:39:29 -0800, elizabeth wrote: Show quoted text
> FWIW, this indeed feels as a bug to me >
To me also. We may also want to consider what happens with `EVAL` and `EVALFILE`, while we get this nailed down. /jnthn


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org