hollie / misterhouse

Perl open source home automation program. It's fun, it's free, and it's entirely geeky.
242 stars 130 forks source link

Problem with Perl include path: default module search path not used? #247

Open hollie opened 11 years ago

hollie commented 11 years ago

Hello,

I'm experiencing the following 'problem': I installed a local Perl on my user account where I run MisterHouse on using perlbrew on OS X 10.8.4 because I don't want to interfere with and depend on the system Perl (an oldish 5.12 version of which I prefer not to touch the installed modules).

I see that when I enable IMAP mail access in MiseterHouse I get an unexpected error that Perl cannot find the module it is searching for:

Error in loading imap_utils: Can't locate Mail/IMAPClient.pm in @INC (@INC contains: ./../lib ./../lib/site /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.4 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at ../lib/imap_utils.pl line 46.
BEGIN failed--compilation aborted at ../lib/imap_utils.pl line 46.
Compilation failed in require at (eval 31) line 1.

To use imap, you need check the dependancies
Can't locate Mail/IMAPClient.pm in @INC (@INC contains: ./../lib ./../lib/site /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.4 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at ../lib/imap_utils.pl line 46.
BEGIN failed--compilation aborted at ../lib/imap_utils.pl line 46.
Compilation failed in require at (eval 31) line 1.
    ...propagated at ./get_email line 134.

The module is installed however and available to the default Perl on that account (= the perlbrew one) in the default module search path of perlbrew (I did not define PERL5LIB):

nessie:mrhouse lieven$ perl -e "use Mail::IMAPClient;"
nessie:mrhouse lieven$ echo $PERL5LIB

nessie:mrhouse lieven$ which perl
/Users/lieven/perl5/perlbrew/perls/perl-5.16.0/bin/perl

I run MisterHouse from master like this:

export mh_parms=/Users/lieven/projects/mrhouse/local/mh.private.ini
cd misterhouse/bin
./mhl

I haven't examined the code yet, but why would get_email try to look for the module in the system Perl path (Perl-5.12) and not in my default Perl path (Perl-5.16.0)? Is this expected behavior?

Regards, Lieven.

hollie commented 11 years ago

I also verified that if I do a which perl in bin/mhl it returns the expected local Perl 5.16.

hollie commented 11 years ago

OK, so the path gets modified in mh in the setup_INC subroutine. However, it still does not explain why the search path gets 'corrupted' with the system Perl libs.

perl -e 'print join"\n",@INC'
/Users/lieven/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level
/Users/lieven/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0
/Users/lieven/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/darwin-2level
/Users/lieven/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0

And all setup_INC does is to append the module folders that are local to the MisterHouse installation (as expected). So why are the perlbrew folders not in @INC when Mail::IMAPClient needs them?

hollie commented 11 years ago

I found that the module search path problem is caused by the hardcoded Perl path in bin/get_email

Instead of using the user-preferred Perl the system installed Perl is referenced (/usr/bin/perl).

Should we not change this to

#!/bin/env perl

instead?

We already discussed this on the mailing list but we did not come to a conclusion as far as I know.

As an alternative we can change the Process_Item command call to bin/get_email to 'perl get_email' (I still need to test this).