Mojolicious + MongoDB: Can't locate MongoDB.pm error - perl

My app crashes each time it includes as much as "use MongoDB;" in my perl app file.
I have installed MongoDB successfully. I can check my databases use one or the other, check for collections, create new collections, all from the shell.
If I try to connect to mongoDb from mojolicious app like:
!/usr/bin/env perl
use Mojolicious::Lite;
use MongoDB;
use MongoDB::OID;
my $mongo_port = shift || 27017;
helper 'mongo' => sub {
my ($self, $name) = #_;
my $host = 'localhost:' . $mongo_port;
my $conn = MongoDB::MongoClient->new(host => $host);
my $db = $conn->get_database('test');
};
helper 'value2oid' => sub {
my ($self, $value) = #_;
MongoDB::OID->new($value);
};
If I have a working app and include as much as :
Use MongoDB;
I get:
Can't load application from file "/Users/eevitomperi/Desktop/Programming/Perl/mojoliciousApp/foodAbout/app.pl": Can't locate MongoDB.pm in #INC (you may need to install the MongoDB module) (#INC contains: /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2/darwin-thread-multi-2level /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at /Users/eevitomperi/Desktop/Programming/Perl/mojoliciousApp/foodAbout/app.pl line 4.
BEGIN failed--compilation aborted at /Users/eevitomperi/Desktop/Programming/Perl/mojoliciousApp/foodAbout/app.pl line 4.
I am completely new to mongo, mojolicious and perl so I guess I did not install some package?
Does the MongoDB files(mongo, mongod....) have to be within the mojolicious project ?
Not sure what I am missing and all documentation starts with the use of "Use MongoDB;" within mojolicious app so not sure what to do.
Hopefully someone can point out what I missed.

Install module:
cpanm Mojolicious::Plugin::Mongodb
Fix the following:
Can't write to /Library/Perl/5.18 and /usr/local/bin: Installing modules to /Users/eevitomperi/perl5
! To turn off this warning, you have to do one of the following:
! - run me as a root or with --sudo option (to install to /Library/Perl/5.18 and /usr/local/bin)
! - Configure local::lib your existing local::lib in this shell to set PERL_MM_OPT etc.
! - Install local::lib by running the following commands
By running:
cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
Now I can connect to Mongo from mojolicious

Related

wxPerl and PAR::Packer and missing dependencies

My application is made with wxPerl, and I make an executable with PAR::Packer. It works fine on my machines (macOS and Windows), but not on a machine without a Perl/wxPerl installation; in fact, it doesn't work on my machines either if I change the name of the directory which holds the Perl installation, e.g. to perl5X or StrawberryX, before running the executable.
On macOS I can get error messages from the terminal:
Can't load '/var/folders/[...]/ca54e36a.bundle' for module Wx:
dlopen(/var/folders/[...]/ca54e36a.bundle,
1): Library not loaded: /[...]/Alien/wxWidgets/osx_cocoa_3_0_2_uni/lib/libwx_osx_cocoau_core-3.0.0.2.0.dylib
Referenced from: /var/folders/[...]/libwx_osx_cocoau_adv-3.0.dylib
Reason: image not found at <embedded>/DynaLoader.pm line 197.
at <embedded>/PAR/Heavy.pm line 140.
I have tried to --link all the .dylib/.dll files (errors about other files occur too), but the same error occurs.
I have use Wx::Perl::Packager in my source file as explained here, and run pp (or, on Windows, wxpar; on macOS that doesn't work) like:
pp -x -c -o MyApp.exe script/app.pl -a assets/collections
The data files included with -a gets unpacked into the right place when the executable is run, so it works that far. But then it stops.
So, what am I missing?
-- EDIT 1
Edited for clarity.
-- EDIT 2
I include a Minimal (not) Working Example:
use warnings;
use strict;
package MyFrame;
use Wx::Perl::Packager;
use Wx;
use base 'Wx::Frame';
sub new {
my $class = shift;
my $self
= $class->SUPER::new( undef, -1, 'Test', [ -1, -1 ], [ 250, 150 ], );
return $self;
}
1;
package MyApp;
use base 'Wx::App';
sub OnInit {
my ($self) = #_;
my $frame = MyFrame->new();
$frame->Show();
}
1;
package main;
MyApp->new->MainLoop;
I then run pp like this:
#!/bin/bash
pp -x -c -o minimal.app \
-l /Users/Patrik/perl5/perlbrew/perls/perl-5.30.0/lib/site_perl/5.30.0/darwin-2level/Alien/wxWidgets/osx_cocoa_3_0_2_uni/lib/libwx_osx_cocoau_core-3.0.0.2.0.dylib \
minimal.pl
But after "hiding" the Perl installation and running the app I get
...
Library not loaded: /Users/Patrik/perl5/perlbrew/perls/perl-5.30.0/lib/site_perl/5.30.0/darwin-2level/Alien/wxWidgets/osx_cocoa_3_0_2_uni/lib/libwx_osx_cocoau_core-3.0.0.2.0.dylib
...

why does perl's Module::Load::Conditional::check_install find uninstalled module?

--> perl -v
This is perl 5, version 24, subversion 0 (v5.24.0) built for x86_64-linux
I'm trying to conditionally load a perl module if it's installed using...
#!/usr/bin/env perl
use strict;
use Module::Load::Conditional qw[can_load check_install requires];
if(check_install( module => 'dvm_common')) {
use dvm_common;
print "Looks like dvm_common is installed, so it was loaded.\n";
} else {
print "Looks like dvm_common is not installed.\n";
}
exit;
Won't compile, complains about missing module...
--> perl -c ./mod_load_cond_test.pl
Can't locate dvm_common.pm in #INC (you may need to install the dvm_common module) (#INC contains: etc... .) at ./mod_load_cond_test.pl line 6.
BEGIN failed--compilation aborted at ./mod_load_cond_test.pl line 6.
I thought the whole point of using this was to test for the existence of the module before loading it ?
use is a compile-time statement, so the interpreter will load a module immediately when it it passing through the source and encounters a use statement, as if you had written
BEGIN { require Module; Module->import }
To load a module at run-time, you can use require
if(check_install( module => 'dvm_common')) {
require dvm_common;
dvm_common->can("import") && dvm_common->import; # optional
...
or string eval:
if(check_install( module => 'dvm_common')) {
eval "use dvm_common;1" or die $#;
...

Installing cpan Modules in cygwin fails

I am trying to install different Perl Modules from CPAN in a cygwin-32bit enviroment and always get Errors of the same kind. This one is from trying to install Net::SSLeay, did make, install and tried force install too, nothing seemed to work.
drmariad#drmariad-MOBL ~/.cpan/build/Net-SSLeay-1.70-eDSzRW$ make install
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
chmod 755 /usr/lib/perl5/site_perl/5.14/i686-cygwin-threads-64int/auto//Net/SSLeay/SSLeay.dll
/bin/find /usr/lib/perl5/site_perl/5.14/i686-cygwin-threads-64int/auto/ -xdev -name \*.dll /bin/rebase -sOT -
/bin/find: paths must precede expression: /bin/rebase
Usage: /bin/find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
Makefile:731: recipe for target 'pure_install' failed
make: *** [pure_install] Error 1
Most of the time it is the bin/find fails message i get in the installations, but i don't know how to change that behaviour. I got errors and failures with most of the modules i tryed to install.
My update-to-date Cygwin comes with
ExtUtils::MakeMaker 6.57_05
ExtUtils::MM_Cygwin 6.57_07
That's odd for a few reason, but what we care about is that version of MM_Cygwin is buggy.
sub install {
my($self, %attribs) = #_;
my $s = ExtUtils::MM_Unix::install($self, %attribs);
return '' unless $s;
return $s unless %{$self->{XS}};
my $INSTALLDIRS = $self->{INSTALLDIRS};
my $INSTALLLIB = $self->{"INSTALL". ($INSTALLDIRS eq 'perl' ? 'ARCHLIB' : uc($INSTALLDIRS)."ARCH")};
my $dop = "\$\(DESTDIR\)$INSTALLLIB/auto/";
my $dll = "$dop/$self->{FULLEXT}/$self->{BASEEXT}.$self->{DLEXT}";
$s =~ s|^(pure_install :: pure_\$\(INSTALLDIRS\)_install\n\t)\$\(NOECHO\) \$\(NOOP\)\n|$1\$(CHMOD) \$(PERM_RWX) $dll\n\t/bin/find $dop -xdev -name \\*.$self->{DLEXT} /bin/rebase -sOT -\n|m if (( $Config{myarchname} eq 'i686-cygwin') and not ( exists $ENV{CYGPORT_PACKAGE_VERSION} ));
$s;
}
You could add the missing | to /usr/lib/perl5/5.14/ExtUtils/MM_Cygwin.pm as a quick permanent fix.
Alternatively, Cygwin has a package named perl-ExtUtils-MakeMaker that upgrade the distribution to 7.04_01.
...Except the bug is still present there. If you have this package installed, the file to fix is /usr/lib/perl5/vendor_perl/5.14/ExtUtils/MM_Cygwin.pm.
Alternatively, you can upgrade ExtUtils::MakeMaker to the latest dev release (which uses a completely different command).
cpan B/BI/BINGOS/ExtUtils-MakeMaker-7.05_22.tar.gz

Open2 Api failure while installing Mead software

I am running into some issues trying to install a software called MEAD . I would appreciate if someone could have alook .
I get the following error while installing
/mead/bin # ./mead.pl GA3
Using system rc-file: /home/karosh/mead/bin/../.meadrc
Warning: Can't find user rc-file
Cluster: /home/karosh/mead/bin/../data/GA3/GA3.cluster
open2: exec of /home/karosh/mead/bin/driver.pl failed at ./mead.pl line 230
THe mead software is not written by me so I have not changed any of the perl scrips . I line 230 in the driver.pl file is
sub run_mead {
my %options = #_;
my $reader = FileHandle->new();
my $writer = FileHandle->new();
unless ( open2($reader, $writer, "$FindBin::Bin/driver.pl") ) {
die "Unable to run MEAD.\n";
}
...
...
}
Does this error mean that open2 was not found . The mead folks have put the following line in the file:
use strict;
use File::Spec;
use FileHandle;
use IPC::Open2;
Or does it mean that i need to install the rpm that contains the API . I see that this API is a part of the core perl bundle http://perldoc.perl.org/IPC/Open2.html. So why was it not installed ? Do i need to install perl again .
Someone has earlier faced this problem - http://www.summarization.com/~radev/mead/email/0160.html but the solution is not working for me . I find no Perl files with the incorrect perl directives . The mead team has been dissolved and there is no one to ask questions but I need to use this software.
I think if some one can explain me the meaning of the error than I can do deeper. Anyone?
It probably means that .../driver.pl doesn't have execute permission. Change the file permissions or call it like
open2($reader, $writer, "perl $FindBin::Bin/driver.pl")
open2($reader, $writer, "$^X $FindBin::Bin/driver.pl")

Why does Perl's Net::SFTP->new complain about "Not an ARRAY reference"?

I am trying to use Net::SFTP to get connected to remote server.
My script is:
my %args = (
ssh_args => {
user => 'canneu_scp',
identity_files => [ '/home/home1/cgrshah/responsys/capgemini.private' ],
debug => 1,
} );
my $targetserver='files.responsys.net';
my $sftp = Net::SFTP->new($targetserver, %args)
or die "could not open connection to $targetserver\n";
But when I run this, I get an error stating:
Not an ARRAY reference at /usr/lib/perl5/site_perl/5.8.1/Net/SFTP.pm line 36.
Can anyone help me with this?
This is just a wild shot in the dark, but the user option should not be in the hash handed to ssh_args, it is at the same level. Try using this code instead:
my $sftp = Net::SFTP->new(
$targetserver,
user => 'canneu_scp',
ssh_args => {
identity_files => [ '/home/home1/cgrshah/responsys/capgemini.private' ],
debug => 1,
}
) or die "could not open connection to $targetserver\n";
It sounds like the code above got you further along, and now you are having problems because your version of Math::BigInt is too old. I see three ways to move forward:
switch to an RSA key instead of a DSA key
find an RPM of Math::BigInt version 1.78 or later
manually install a copy of Math::BigInt
The third option has many pitfalls, and if you decide to go with it I would suggest the following steps:
install App::cpanminus
make sure you have a gcc installed
run wget -O- http://cpanmin.us | perl - --local-lib=~/perl5 App::cpanminus
add ~/perl5/bin to your path
install Math::BigInt into your home directory with cpanm --local-lib=~/perl5 Math::BigInt
add use lib "$ENV{HOME}/perl5"; to the start of your script so it can find the new modules