From: Bryan Donlan Date: Fri, 15 Aug 2008 19:31:25 GMT Subject: Re: [PATCH] Git.pm: Make File::Spec and File::Temp requirement lazy Message-ID: <3e8340490808151231p700ca76fub16700708f2942bb@mail.gmail.com> In-Reply-To: <1218813032-18203-1-git-send-email-marcus@griep.us> On Fri, Aug 15, 2008 at 11:10 AM, Marcus Griep wrote: > This will ensure that the API at large is accessible to nearly > all Perl versions, while only the temp file caching API is tied to > the File::Temp and File::Spec modules being available. > > Signed-off-by: Marcus Griep > --- > > Eric Wong wrote: > > What about just lazy requiring inside _temp_cache() so it > > won't get loaded by folks that don't need it? (completely untested): > > > > eval { require File::Temp }; > > if ($@) { > > throw Error::Simple("couldn't require File::Temp: $@"); > > } > > eval { require File::Spec }; > > if ($@) { > > throw Error::Simple("couldn't require File::Spec: $@"); > > } > > > > It'll also remove the minor performance hit CGI/gitweb users got since > > we won't load these extra modules during startup. > > This recommendation is implemented with this patch, but in such a way that only > the first test will be used, and that result cached. That way we aren't doing > a compile _every_ time we want a temporary file, just the first time. perl's 'require' will only attempt to load a module the first time it is used; subsequent attempts will result in a quick no-op, so there's no need to further cache. Unless you mean to cache a negative result? In which case, the require should be quite fast, as it'll quickly get a 'file not found' error without needing to do any compilation.