>
> 2. requrire'ing a file that defines some functions sometimes gives me
>    an error that the functions in that file are _not_ defined...
>

I append you a mail I write last month that should explain what happens...

> 3. I have a hard time understanding when to use [- -] and when to use
>    [! !] or [* *]. Most of what I've done so far uses [- -] and
>    [$ $] (which I so far have no trouble with). The scoping and
>    execution time issues are not that clear to me.
>

Don't use [*  *] (only if you need recursions), because it is still
experminetal in the current version and has some problems. Use  [!  !] to
define Perl-subroutines, in all other cases use [- -].

For scoping read:

http://perl.apache.org/embperl/Embperl.pod.5.html#Variable_scope_and_cleanup


> Last but not least I'd like some kind of pretty printer since my
> Emacs won't help me here. I tried the two things mentioned on the
> web, but to no avail (one requiring Xemacs instead of Emacs, too).
>

I don't use Emacs, so I can't help you on this issuse, but I am happy to put
anything up on the web, if available.

Gerald

P.S. Support for Embperl is now on the Embperl Mailing list
([EMAIL PROTECTED])

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of
> Gerald Richter
> Sent: Friday, April 21, 2000 9:10 PM
> To: Ulrike Schepp; Steven D. Arnold
> Cc: Embperl Mailingliste
> Subject: RE: use module in Embperl (was: problem solved, but still
> weird!)
>
>
> >
> > Standard workaround here is now "apachectl restart" after the change of
> > modules :-/ weird but it really works!
> >
>
> Nothing weird here. Everything is well defined. Just let us try to
> understand how Perl, mod_perl and Embperl works together:
>
> "perldoc -f use" tells us:
>
>   Imports some semantics into the current package from the named module,
>   generally by aliasing certain subroutine or variable names into your
>   package.  It is exactly equivalent to
>
>      BEGIN { require Module; import Module LIST; }
>
>   except that Module must be a bareword.
>
> So what's important here for us is, that use executes a require
> and this is
> always done before any other code is executed.
>
> "perldoc -f require" says (among other things):
>
>   ..., demands that a library file be included if it hasn't already
>   been included.
>
> and
>
>   Note that the file will not be included twice under the same specified
>   name.
>
> So now we know (or should know) that mod_perl starts the Perl interpreter
> once when Apache is started and the Perl interpreter is only
> terminated when
> Apache is terminated. Out of these two things follows, that a
> module that is
> loaded via use or require is only loaded once and will never be reloaded,
> regardless if the source changes or not.
>
> So far this is just standard Perl. Things get's a little bit more
> difficult
> when running under mod_perl (only Unix), because Apache forks a
> set of child
> processes as neccessary and from the moment they are forked, they run on
> their own and don't know of each other. So if a module is loaded at server
> startup time (before the fork), it is loaded in all childs (this
> can be used
> to save memory, because the code will actually only reside once
> in memory),
> but when the modul is loaded inside the child and the source changes, it
> could be happen, that one child has loaded an ealier version and another
> child has loaded a later version of that module, depending on the time the
> module is actualy loaded by the child.
>
> That explains, why sometimes it works and sometimes it doesn't, simply
> because different childs has loaded different versions of the same module
> and when you reload your page you hit different childs of Apache!
>
> Now there is one point that is special to Embperl to add. Since Embperl
> compiles every page in a different namespace, a module that
> doesn't contains
> a "package foo" statement is compiled in the namespace of the
> page where it
> is first loaded. Because Perl will not load the module a second
> time, every
> other page will not see subs and vars that are defined in the
> loaded module.
> This could be simply avoided by giving every module that should be loaded
> via use/require an explicit namespace via the package statement.
>
> So what can we do?
> - If a module change, simply restart Apache. That's works always.
> - use Apache::StatInc. This will do a stat on every loaded module and
> compare the modification time. If the source has changed the module is
> reloaded. This works most times (but not all modules can be cleanly
> reloaded) and as the number of loaded modules increase, your
> sever will slow
> down, because of the stat it has to do for every module.
> - Use "do" instead of "require". do will execute your file everytime it is
> used. This also adds overhead, but this may be accpetable for
> small files or
> in a debugging environement. (NOTE: Be sure to check $@ after a
> do, because
> do works like eval)
>
> I hope now it's seem a little bit less weird..
>
> Gerald
>

Reply via email to