pugs-comm...@feather.perl6.nl wrote:
+All package bodies (including module and class bodies) execute at the
+normal execution time of the code in which they are embedded.  For normal
+mainline code, this is the normal flow of execution; if this is too late
+to initialize something in the package that you want to be initialized, 
consider
+use of a MAIN subroutine, which is invoked at the end of normal execution.
+See L<S06/Declaring a C<MAIN> subroutine>.

It is sounding like you are saying every Perl module can have its own MAIN subroutine ...

Just to clarify, is there really no structural distinction between a Perl program and a Perl module, such that you could have either a .pl or a .pm be the "main program"?

For example, if I wanted to write Perl in a manner a bit more Java-like where everything is in a class, and so I wrote a MyProgram.pm file containing something like:

  class MyProgram {

    submethod MAIN {
      ...
    }

    submethod other_meth {
    }

  }

... then could someone just say "perl MyProgram.pm" and it would just DWIM?

I would find it attractive to be able to structure my main program file as a class like this if I wanted to.

Currently when I write a Perl 5 program I essentially do just that already, and my main.pl doesn't do anything except explicitly invoke MyProgram->main(); I would rather in Perl 6 to not have to have that file wrapper.

Another reason I ask is that if, conceptually some day one might store a Perl 6 program in a database, maybe using a separate database for each module, and so that say connecting to a database is semantically the same as use/require-ing a module/library, that the database format for the main program can be entirely the same as one for a used module, and so just as you say something like "use MyModule from <database connect string>", one could implicitly from the command line or a command prompt just say the same thing but if a MAIN() was in MyModule then it would run implicitly as a program. For the interest of being a bit more dynamic, in such a situation I would expect that an analogy of Perl's "require" would be used instead to bring in other modules, at runtime.

-- Darren Duncan

Reply via email to