File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -146,7 +146,16 @@ private function importsIn($use) {
146146 * @throws lang.Throwable
147147 */
148148 public function run ($ argv = []) {
149- $ this ->modules ->require ($ this ->namespace );
149+
150+ // Defer requiring modules until class loading time - if XP runners
151+ // have already done this for us, we'll not do this twice. See this
152+ // pull request: https://github.com/xp-runners/reference/pull/85
153+ spl_autoload_register ($ defer = function ($ class ) use (&$ defer ) {
154+ $ this ->modules ->require ($ this ->namespace );
155+
156+ spl_autoload_unregister ($ defer );
157+ spl_autoload_call ($ class );
158+ });
150159
151160 Script::$ code [$ this ->name ]= '<?php ' .$ this ->head ().str_repeat ("\n" , $ this ->line ).$ this ->fragment ."\nreturn null; " ;
152161 try {
@@ -155,6 +164,7 @@ public function run($argv= []) {
155164 } catch (\Throwable $ t ) {
156165 throw Throwable::wrap ($ t );
157166 } finally {
167+ spl_autoload_unregister ($ defer );
158168 unset(Script::$ code [$ this ->name ]);
159169 }
160170 }
You can’t perform that action at this time.
0 commit comments