On Thu, Dec 15, 2011 at 12:00 PM, Shawn H Corey <shawnhco...@gmail.com>wrote:

> On 11-12-15 09:02 AM, Ken Peng wrote:
>
>> BEGIN {
>>     my $module_dir = $INC{'Net/Evernote.pm'};
>>     $module_dir =~ s/Evernote\.pm$//;
>>     unshift @INC,$module_dir;
>> }
>>
>> This begin block setup the @INC by adding a path as the module itself,
>> it does work.
>>
>
> Try this instead (no BEGIN needed):
>
> package Net::Evernote;
>
> use File::Basename; # must be before `use lib`
> use lib dirname( $INC{ __PACKAGE__ . '.pm' } );
>
>
Close, but that won't work, because keys in %INC are paths, and you are
still leaving the ::'s unchanged.

use 5.014;
use File::Basename; # must be before `use lib`
use lib dirname( $INC{ __PACKAGE__ =~ s!::!/!r . '.pm' } );

That should do. Plus more mangling if you don't use /r :)

Reply via email to