kraih/mojo — pull request #518 by ChinaXing (2013-07-29 07:42:14+00:00)
Title: failed when use Mojo::UserAgent in some process whose name ($0) not valid for FindBin module

I have use Mojo::UserAgent in AnyEvent::Fork module, some error will be thrown out like this:

Cannot find current script [AnyEvent::Fork 23476]

which is a exception thrown from FindBin.pm, and the FindBin.pm module was used in Mojo::Server, and which was used in Mojo::UserAgent :

use Mojo::Base 'Mojo::Server'; # at Mojo::Server::Daemon

so I think Mojo::UserAgent should not has such a constraint : can not used in process whose name was not accepted by the FindBin module.

than I add the following code in Mojo::Server:

BEGIN{ $__PACKAGE__::zsave = $0 ; $0 = '-e' }
UNITCHECK{ $0 = $__PACKAGE__::zsave }
use FindBin;

by set $0 to "-e" temp , let use FindBin works. then reset it to the origin value when the module loaded.

maybe some other method is better, whatever , hope you fix it !