Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: nested requires, name-space override Message-ID: <1991May23.052317.5608@jpl-devvax.jpl.nasa.gov> Date: 23 May 91 05:23:17 GMT References: <1991May22.193037.12166@cherokee.uswest.com> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 58 In article <1991May22.193037.12166@cherokee.uswest.com> rampson@flash (Michael T. Rampson) writes: : Howdy, : I was wondering if you are suppose to be able to do nested requires. Yes. : I haven't been able to get them to work ("I get Can't locate dodat.pl in @INC : at do_this.pl line 1."). What I'm trying to do is create an abstract interface : of things you have to do to handle different types of program builders : (ie., make, gmake, imake, mkmf, etc). Originally I found that there was : some invariant code (ie., code that did not depend on what type of make you : were using), and some code that was very specific to the MAKER that you : were using. But after thinking about it, what I would really like to do : is be able to override a function defined in the default library (default : being things to do with make), with a function that is specific to the MAKER : needed (that would be in another library). The reason I'm splitting this stuff : out is so that you don't end up basically the same code replicated all over the : place. Below is an example of what I would like to be able to do. : : require 'maker.pl'; : &make(blah, blah, target) || die "a horrible death:$!"; : : maker.pl would look like this : package maker; : eval require $ENV{'MAKER'}.pl; That won't do what you think it does. You want something like eval q/require "$ENV{'MAKER'}.pl"/; warn $@ if $@; You can also get finer control by using "do" instead of "require". It won't keep track of what you've already done, but you don't have to use eval to trap a bad return from it. : sub main'make { : local(blah,blah,$target)=@_; : 'make $target'; : if ($?) { : warn "make died:$!"; : return(0); : } : return(1); : } : 1; : : an example MAKER.pl would look something like the above only redefine : main'make to do whatever is needed for this particular kind of MAKER. That should be possible, since the require will happen after the compilation of the current main'make, so any main'make defined by the require should override the current one. Incidentally, I hope it's just a typo that you said 'make $target' using single quotes instead of backticks. Also, just because $? is set doesn't mean that $! will have a meaningful value. Larry