Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Having to use a stripped down activestate perl 5.005. I can't add the module i want to (Win32::Daemon), because all the machines the script will go to will also need the module. Question is: Can I simply cut and paste the code into my script from the module to get the functionality?...I can't see much code in this module's .pm & .ppd, where is it? Chris
  • Comment on Can I include a package as part of my script?

Replies are listed 'Best First'.
Re: Can I include a package as part of my script?
by BrowserUk (Patriarch) on Apr 29, 2003 at 07:50 UTC

    Win32::Daemon relies upon a dll, Daemon.dll which if the installation on your development machine is correct, you should find installed in

    X:/perl/site/lib/auto/win32/daemon/

    or somewhere similar. I've never used 5.005, so I am unsure whether the blib paths were different back then.

    Adding the contents of Win32::Daemon.pm to the top of your script would work and be trivial, but the seems little point it adding its 20k to your script to save "polluting the install", when you would need to place a 72/76 kb binary in the appropriate place in the perl directory tree anyway. In any case, the general method of using Win32::Daemon appears to be to have two scripts: The first is the deamon itself (which used Win32::Daemon) and the second is a short script to install the first (which also needs Win32::Daemon). So, all you would be doing is wasting 20k of space. Whilst it wouldn't be too hard to combine the install and service scripts into one, the next time you want to create another service script your back to square one.

    The bottom line is that you are going to have to put Deamon.dll somewhere. You might get away will placing it in on a server somewhere and loading it across the network to each machine, though your going to have to play some nasty tricks with Dynaloader.pm to make that work. You might even encode the dll using mime64 or similar and tack it onto the end of your script and reconstitute it at run-time, but the chances of making this work at all, never mind reliably are pretty darn slim.


    Examine what is said, not who speaks.
    1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
    2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
    3) Any sufficiently advanced technology is indistinguishable from magic.
    Arthur C. Clarke.
      thanks to everyone for the responses. love you all :)
      ------------------------
      <if the answer you get is not what you want> <ask a different question>
Re: Can I include a package as part of my script?
by dragonchild (Archbishop) on Apr 28, 2003 at 22:17 UTC
    What's wrong with requiring that all target machines have Win32::Daemon compiled?

    Also, it very likely is that Win32::Daemon has a bunch of XS, meaning you'd have to compile it on the target machine, anyways?

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

•Re: Can I include a package as part of my script?
by merlyn (Sage) on Apr 28, 2003 at 22:55 UTC
      thank you very much. Unfortunatelly Win32::Daemon seems a little more complicated in loading than CGI, and fails with: Can't locate loadable object for module Win32::Daemon in @INC (@INC contains: D:/Perl/lib D:/Perl/site/lib .) at D:/Perl /lib/DynaLoader.pm line 108 btw all that my code does is update password for some services. Chris

        One trick that I've used in the past is to modify @INC to also point to a directory I can modify (e.g. lib in my software release) and then require the module:

        my $dir = Cwd::getcwd() . "/" . $0; $dir =~ s#([/\\])[^/\\]+$#/lib#; push(@INC,$dir); require PrivateModule;

        That way you are only affecting your own script and you can use the standard module.

Re: Can I include a package as part of my script?
by marinersk (Priest) on Apr 28, 2003 at 22:20 UTC
    I'm not experienced enough with Perl to be sure I'd be answering your question thoroughly, and it deserves a thorough answer so I'll withhold for the moment and let those who can, do.

    I will address what seems the obvious issue to me -- you are going to be running this Perl script on all those remote machines, so something is going to be copying it out there -- Can it not also copy the modules you need?

    I don't understand why you think you are limited to one script's worth of code.

      Cannot pollute the remote machine perl environment as it's part of a large system. it is totally out of the question for me to do so. Chris