Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: interface.pm explained

by fergal (Chaplain)
on Aug 02, 2004 at 13:56 UTC ( [id://379282]=note: print w/replies, xml ) Need Help??


in reply to Re^2: interface.pm explained
in thread interface.pm explained

I didn't test it but INIT kicks in when everything is finished compiling, perlsub -
"INIT" blocks are run just before the Perl runtime begins execution, in "first in, first out" (FIFO) order. For example, the code generators documented in perlcc make use of "INIT" blocks to initialize and resolve pointers to XSUBs.

So various modules can register INIT blocks. The INIT blocks are all postponed until just before perl starts executing, at which point it runs all the INIT blocks in the order they were registered and then finally it goes to line 1 of your program.

$@ is the only place where an error from an eval will show up, if you don't do something about it, the error will disappear forever, that's what makes it possible to ignore an error with eval. Of course if there is something wrong with the module and we ignore the error, the program will probably fail anyway however it will fail with a confusing error message. For example if mod.pm is

package mod; sub foo{ print "hello world\n; # eek! missing a double quote } 1;
and we do
eval "use mod"; mod::foo();
we get
Undefined subroutine &mod::foo called at - line 2.
because foo didn't compile however what we really want is
eval "use mod"; die $@ if $@; mod::foo();
Can't find string terminator '"' anywhere before EOF at mod.pm line 3.
Compilation failed in require at (eval 1) line 2.
BEGIN failed--compilation aborted at (eval 1) line 2.

Replies are listed 'Best First'.
Re^4: interface.pm explained
by diotalevi (Canon) on Aug 02, 2004 at 14:27 UTC

    You'll want to name the code you called inside INIT/CHECK because mod_perl doesn't call those. This gives mod_perl-using code the ability to manually call your INIT-time code at the appropriate time.

    INIT { init(); } sub init { # INIT-time code goes here. mod_perl users are expected to call th +is function as appropriate for them. # perl will not automatically trigger this function for them. ... }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://379282]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-23 20:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found