Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add custom path to Perl libraries for SublimeLinter

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.

like image 722
alexK Avatar asked Oct 03 '22 09:10

alexK


2 Answers

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"]
        }'
like image 67
Alexei Kotlar Avatar answered Oct 13 '22 10:10

Alexei Kotlar


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-

like image 23
hmatt1 Avatar answered Oct 13 '22 10:10

hmatt1