5

I'm using Sublime Text 2 editor for Perl development and now I faced next problem. I have my project under:

/home/alex/workspace/

In this project I have libraries under:

/home/alex/workspace/lib/

While I'm editing file:

/home/alex/workspace/test.pl

and in this file I try to load library:

/home/alex/workspace/lib/myLib.pm

I have a code like this:

#!/usr/bin/perl
use myLib;

sublimelinter is not able to find this library because it is not in default @INC path. Is there any way to modify Perl's @INC for sublimelinter without changing my scripts source code?

I tried to use per-project settings for linter like this:

{
"folders":
[
    {
        "path": "/home/alex/workspace"
    }
],
"settings":
{
    "SublimeLinter":
    {
        "Perl" :
        {
            "lint_args":
            [
                "-I", "/home/alex/workspace/lib",
                "-c",
                "{filename}"
            ]
        }
    }
}
}

But this does not help.

alexK
  • 963
  • 1
  • 7
  • 17
  • 1
    You can append `/home/alex/workspace/lib` to the `PERL5LIB` environment variable. But make sure, that `PERL5LIB` is part of the environment of the process from which the script is called. – user1146332 Jul 30 '13 at 16:28

2 Answers2

2

This should work. There may be better practices though, I'm not an expert.

#!/usr/bin/perl
use strict;
use warnings;
use lib "/home/alex/workspace/lib/";
use myLib;

Here's a link: http://perldoc.perl.org/lib.html

This would have some portability issues, but this question has some other related answers: How can my Perl script find its module in the same directory?

Another good source http://learn.perl.org/faq/perlfaq8.html#How-do-I-add-a-directory-to-my-include-path-INC-at-runtime-

Community
  • 1
  • 1
hmatt1
  • 4,939
  • 3
  • 30
  • 51
  • Wouldn't you be better off with `use lib "lib/myLib";` instead? Hardcoding in full paths is generally bad for portability's sake... – MattDMo Jul 30 '13 at 17:09
  • It looks like `use lib` has to have a directory as input, but you could do `use lib "./lib"` – hmatt1 Jul 30 '13 at 17:17
  • Actually this is not exactly I was looking for. My requirement was to configure sublime linter in some way to avoid changing every file in my project. – alexK Jul 30 '13 at 17:20
  • @Matt I see. My Perl is a little rusty, in Python one can `import .lib.myModule` all in one line – MattDMo Jul 30 '13 at 17:24
  • alexK, this last link referenced this on Linux, but check this out too: http://perlmaven.com/how-to-change-inc-to-find-perl-modules-in-non-standard-locations. You define the environment variable PERL5LIB like the user1146332 mention and it will add all those directories to your @INC – hmatt1 Jul 30 '13 at 17:35
  • 2
    Run this or put it in your .bashrc `export PERL5LIB=/home/alex/workspace/lib/` – hmatt1 Jul 30 '13 at 17:40
  • I am still having this problem with "SublimeLinter-perl" and ST3(build 3065). None of the proposed solutions on github worked for me, but @chilemagic has the quick fix. – Jake88 Jan 06 '15 at 19:20
2

These answers should be updated for sublime text 3

Open Preferences-> Package Setting->SublimeLinter->Settings-User.

Find this entry, and replace /path/to/my/project

  "linters": {
        "perl": {
            "include_dirs": ["/path/to/my/project"]
        }'