in reply to Same function multiples unknown modules

OK, thanks, for the information, however, this, I don't think, is going to work for what I'm asking. Essentually, I wanted to do a 'dummy' call method. Not worrying about packaging etc. The goal is, is to write the 'main' file, then simply add pm files to the directory, and have them called (use), more or less automatically, and then call a specific function that is found in each file, without knowing the pm file name (not knowing the pm file name is the catch to it all). Hence 'like calling out someone's name in a room and letting everyone with that name answer'.

The goal is to have a single function in each pm file that is called, sorta like an init() or something along those lines. The main file wouldn't be edited in order to use a new pm file, the file would be loaded, and the init() (or what ever) would be started and execution would begin. At this point, the only item in the 'global function' is a 'menu' which the main script should call, and choosing the menu, starts the specific function in the specific pm (which only exists once). The actual showing of the 'menu item' is variable based, so if X eq 1 show me else skip.

I'm starting to guess this may not be possible, however, Perl is powerfull enough that I beleive it is. I'd prefer doing this with the standard modules, if external modules are required, for compatibility.
  • Comment on Re: Same function multiples unknown modules

Replies are listed 'Best First'.
Re^2: Same function multiples unknown modules
by Delusional (Beadle) on Sep 26, 2005 at 10:13 UTC
    Thanks again Zaxo,
    I ran a test using this, however, the $eval fails on me (in a browser I get Error 500)...

    I use logging in the scripting to catch errors as well as MySQL calls (and anything else I choose to log). The log shows the following when the script is executed:

    Sep 26, 2005 (10:49:52) : ERROR SITUATION: Interface Crash, error message:
    syntax error at Main/Menu.pm line 101, near "$_::runonce(" Compilation failed in require at d:\PROGRA~1\APACHE~1\apache\cgi-bin\intern2.cgi line 31.

    In the file Main/Menu.pm I have your code as:
    sub sub_menus { for (keys %INC) { next unless m/^Main|Addins/; s!/!::!g; s/\.pm$//; #print "<font face=\"Arial\" size=\"2\">$_<br></font>\n"; eval { $_::runonce() }; } }
    The function, runonce (sub runonce), is available in exactly one file. Perhaps I shouldn't use sub, rather someother addressing scheme that I'm unawear of?

    If I comment out the eval line and use the print line, execution runs clean (with the exception of runonce not running).

    I assume the problem lye with the logging I have to catch problems and log them:
    $SIG{__DIE__} = \&error_crash_trapper; $SIG{__WARN__} = \&warn_crash_trapper;
    Is there any other way to achieve this? Essentially I'm looking for simplicity and the use of a 'dummy' routine that doesn't rely on hard coded information which then allows for dynamic implementation.