Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Can't locate Test/JSON.pm in @INC

by zuverlassig (Novice)
on Dec 27, 2013 at 15:32 UTC ( [id://1068524]=perlquestion: print w/replies, xml ) Need Help??

zuverlassig has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use Test::JSON in my perl code. I do not have sudo access to install the module on the linux machine. Hence, I have downloaded JSON.pm from cpan and placed it in Test folder. Also, I have another use JSON in my code, which again I downloaded from cpan and placed in JSON folder

I have included them as

use lib '/abc/xyz/JSON'; use JSON; use lib '/abc/xyz/Test'; use Test::JSON;
when i try to run it, it gives me compilation error as Can't locate Test/JSON.pm in @INC. However, it is able to use the first JSON.pm module, not the second JSON.pm module (Both the modules are JSON.pm). I tried various combinations for using the second Test::JSON module, but wont work.

Replies are listed 'Best First'.
Re: Can't locate Test/JSON.pm in @INC
by toolic (Bishop) on Dec 27, 2013 at 15:43 UTC
    You should not include the module name as part of the lib path. Try:
    use lib '/abc/xyz';
      thanks toolic, you are right, but I have two folders, JSON and Test, and each of them contains a different JSON.pm module. And the module in JSON folder works in my code, but the module in my Test folder gives me compilation error.
Re: Can't locate Test/JSON.pm in @INC
by aitap (Curate) on Dec 27, 2013 at 17:56 UTC
    I have downloaded JSON.pm from cpan and placed it in Test folder.
    While Test::JSON is pure-Perl and doesn't have a lot of dependencies, so it's possible to install it manually, it's usually easier to make the computer do the installation for you. Yes, even you can use CPAN! And cpanm automagically installs modules in your home directory and sets up all environment variables using local::lib, not requiring root priviledges.
      thanks aitap, will try this too.
Re: Can't locate Test/JSON.pm in @INC
by taint (Chaplain) on Dec 27, 2013 at 16:56 UTC
    Greetings, zuverlassig.

    As a rule, I'd have to say toolic is right. I'm inclined to think you might be experiencing a namespace-clash. I don't suppose you're calling the lib relative to your script, are you? It would make it easier to diagnose, implement. In any case, given that you're using two Modules with the same name, and that they generally have a PACKAGE declaration at, or near the top. How are yours defined? In other words; can you post the declarations you're using in your JSON modules? eg;

    package JSON;
    Given that traditionally the double-colon is used as a path separator. I suspect you're declarations are incorrect; Test::JSON assumes Test/JSON

    --Chris

    UPDATE: Given you didn't share the actual error. I don't suppose it (Perl) was trying to find Test/Test/JSON, was/did it?

    ¡λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH

      These are the package declarations: for the first:- package JSON; for the other:- package Test::JSON; Now, I checked using print($INC{"JSON.pm"}, "\n"); to find out which JSON.pm it was using. It turns out tht it uses, /usr/dir/packages/perl/perl-5.8.8/lib/site_perl/5.8.8/JSON.pm and after I try to use only a specific method, it gives me this error: Can't locate object method "is_valid_json" via package "Test::JSON" (perhaps you forgot to load "Test::JSON"?)
        That's why I indicated that using a directory relative would make it easier to diagnose/implement.

        If both of your custom JSON modules declare

        package JSON;
        You should, as toolic initially asserted, be able to use
        use lib '/abc/xyz';
        or
        use lib ('/abc/xyz');
        then
        use JSON; use Test::JSON
        because as I noted earlier; the double-colon is a path/directory separator. Meaning; Test::JSON == Test/JSON.

        You might also try

        use lib '/abc/xyz/';
        as that negates the need to preface a slash before your custom modules.

        In any case; you must ensure that the path to your custom JSON modules preceeds (is before) your system Perl module path.
        That's why you see reference to conflicts within the system's perl, in the latest error you quoted.

        --Chris

        ¡λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1068524]
Approved by taint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-20 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found