in reply to Re: "Safe" ways for Carp to report errors to browser?
in thread "Safe" ways for Carp to report errors to browser?
FWIW, the reason I overlooked this might be a common one that others (doing a search) might also overlook, so I think it deserves a tad clarification --please correct me if I'm wrong on this:
"require" waits until runtime to bring the code in, unlike "use", which compiles the function into place before running. Hence, using "use" as I did causes the fatalsToBrowser() function to be called irrespective of the conditional in the if statement. The solution you showed, using the "require"/"import" combination, assures that the code doesn't get imported and used until runtime, allowing the conditional will be tested beforehand.
The reason this eluded me in the first place is because this is all taking place within a BEGIN block, which is executed at compile-time, not runtime. Here, it would have seemed irrelevant whether to use use or require, till I realized that all I'm doing is defining the function, set_message(). This function isn't getting called yet--it's just being defined. Later, if there are syntax errors that perl's compile phase will catch, then set_message() is called, which will then do the test, which then determines whether to imports fatalsToBrowser().
If my explanation is accurate, it could be useful for people who are looking to learn the subtle nuances between use and require.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: "Safe" ways for Carp to report errors to browser?
by dave_the_m (Monsignor) on Jan 10, 2005 at 19:46 UTC | |
by argv (Pilgrim) on Jan 10, 2005 at 22:41 UTC |