Compilation errors when connecting to MongoDB from Perl - perl

I'm trying to run the simple "MongoDB:Tutorial" tutorial:
http://search.cpan.org/dist/MongoDB/lib/MongoDB/Tutorial.pod
My goal is to connect to a MongoDB database from a Perl script. I've installed MongoDB using cpanm:
$ sudo cpanm MongoDB
MongoDB is up to date. (0.501.1)
I created a simple Perl script called loadRaw.pl:
use strict;
use warnings;
use MongoDB;
use MongoDB::Connection;
use MongoDB::OID;
print "hello\n";
When I try to run the script, I get a bunch of errors:
$ perl ./loadRaw.pl
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 271, near "confess "cannot set fields after querying""
(Do you need to predeclare confess?)
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 273, near "confess 'not a hash reference'"
(Do you need to predeclare confess?)
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 294, near "confess "cannot set sort after querying""
(Do you need to predeclare confess?)
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 296, near "confess 'not a hash reference'"
(Do you need to predeclare confess?)
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 317, near "confess "cannot set limit after querying""
(Do you need to predeclare confess?)
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 343, near "confess "Cannot set tailable state""
(Do you need to predeclare confess?)
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 366, near "confess "cannot set skip after querying""
(Do you need to predeclare confess?)
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 390, near "confess "cannot set snapshot after querying""
(Do you need to predeclare confess?)
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 408, near "confess "cannot set hint after querying""
(Do you need to predeclare confess?)
String found where operator expected at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 410, near "confess 'not a hash reference'"
(Do you need to predeclare confess?)
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 90, near "has started_iterating"
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 271, near "confess "cannot set fields after querying""
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 294, near "confess "cannot set sort after querying""
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 317, near "confess "cannot set limit after querying""
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 343, near "confess "Cannot set tailable state""
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 366, near "confess "cannot set skip after querying""
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 390, near "confess "cannot set snapshot after querying""
syntax error at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 408, near "confess "cannot set hint after querying""
BEGIN not safe after errors--compilation aborted at /usr/local/lib/perl/5.10.1/MongoDB/Cursor.pm line 564.
Compilation failed in require at /usr/local/lib/perl/5.10.1/MongoDB/Connection.pm line 26.
BEGIN failed--compilation aborted at /usr/local/lib/perl/5.10.1/MongoDB/Connection.pm line 26.
Compilation failed in require at /usr/local/lib/perl/5.10.1/MongoDB.pm line 30.
BEGIN failed--compilation aborted at /usr/local/lib/perl/5.10.1/MongoDB.pm line 30.
Compilation failed in require at ./loadRaw.pl line 7.
BEGIN failed--compilation aborted at ./loadRaw.pl line 7.
It seems like the MongoDB Perl module (specifically, the Cursor.pm file) has some syntax errors. The first batch of problems (those related to the confess keyword) are solved if I add the line use Carp; to the top of Cursor.pm. However, I don't think I should have to do this, and instead I'm doing something else incorrectly. Also, the second batch of errors (those related to the has keyword) are not solved by including Carp.
Has anyone else experienced this? Any ideas?

I never found out exactly what was going wrong, but it was surely unique to my system and my Perl configuration. Since others were able to execute the provided code without problem, I tried executing the code using Perlbrew (as suggested by friedo):
$ perlbrew install perl-5.16.0
(Output not shown)
$ perlbrew switch perl-5.16.0
(Output not shown)
$ perlbrew install-cpanm
(Output not shown)
$ /home/sthomas/perl5/perlbrew/bin/cpanm MongoDB
(Output not shown)
$ perlbrew exec perl ./loadRaw.pl
perl-5.16.0
==========
hello
Since it works fine with a Perlbrew installation, the problem is not with MongoDB or my sample code; it must be some weird quirk of my Perl environment. I guess I'll try a fresh install of Perl and all my required modules and see if that works.

Related

Getting error while executing makeinfo on cygwin

While executing makeinfo on cygwin I am getting the following errors. I am using the perl version 5.32.1
23:16 Harshal:~> makeinfo
Can't locate if.pm in #INC (you may need to install the if module) (#INC contains: /usr/lib/texinfo /usr/share/texinfo/lib/Text-Unidecode/lib /usr/share/texinfo/lib/Unicode-EastAsianWidth/lib /usr/share/texinfo/lib/libintl-perl/lib /usr/share/texinfo /usr/share/texinfo /usr/local/lib/perl5/site_perl/5.32/x86_64-cygwin-threads /usr/local/share/perl5/site_perl/5.32 /usr/lib/perl5/vendor_perl/5.32/x86_64-cygwin-threads /usr/share/perl5/vendor_perl/5.32 /usr/lib/perl5/5.32/x86_64-cygwin-threads /usr/share/perl5/5.32) at /usr/share/texinfo/Texinfo/Structuring.pm line 27.
BEGIN failed--compilation aborted at /usr/share/texinfo/Texinfo/Structuring.pm line 27.
Compilation failed in require at /usr/share/texinfo/Texinfo/Convert/Converter.pm line 32.
BEGIN failed--compilation aborted at /usr/share/texinfo/Texinfo/Convert/Converter.pm line 32.
Compilation failed in require at /usr/bin/makeinfo line 99.
BEGIN failed--compilation aborted at /usr/bin/makeinfo line 99.
If someone can provide some pointer on how to resolve this issue would be helpful
I tried updating the perl version. I tried commetting out the code on line num 27 in structuring.pm didn;t workout. I am not from software background but i need the above thing for some RISCV based toolchain update.
Any help woudl be really appreciated .
Something's wrong with your system. This is a file included in the perl-5.32.1-2 package. It should be found at
/usr/share/perl5/5.32/if.pm
Try reinstalling the perl package. If the file isn't missing, something's wrong with the permissions.

DateTime Won't Load Properly Unless a Module Using Moo Launches First

I'm cleaning up code and removed the now deprecated Forecast::IO module from my Perl script. When I did, I started getting this error:
[root#server cgi-bin]# perl Weather.pm
Undefined subroutine &B::perlstring called at /usr/local/share/perl5/Params/ValidationCompiler/Compiler.pm line 248.
Compilation failed in require at /usr/local/lib64/perl5/DateTime.pm line 13.
BEGIN failed--compilation aborted at /usr/local/lib64/perl5/DateTime.pm line 13.
Compilation failed in require at Weather.pm line 1340.
BEGIN failed--compilation aborted at Weather.pm line 1340.
Line 1340 where the error occurs is innocuously enough, use DateTime;.
I wasn't sure what DateTime could be up to that would cause it to be upset I wasn't using the unrelated Forecast::IO module any longer, so I started taking apart the latter module to figure out what code was preventing the error. The essential part seems to be that Moo is included in Forecast::IO and it has at least one Moo has declaration:
package Forecast::IO;
use Moo;
has testkey => ( is => 'ro' );
1;
For some reason, if that module with at least those lines exists, DateTime loads fine. Otherwise, the error I mentioned above occurs, choking on DateTime's line 13, use Carp;. Even if I put use Moo; has testkey => ( is => 'ro' ); into my own module, it fails upon use DateTime.
Even though I've used grep -r Forecast::IO to traverse the codebase to look for some errant reference and come up empty. So, I decided to try to just load the DateTime module: perl -MDateTime. That too produces the error:
[root#server cgi-bin]# perl -MDateTime
Undefined subroutine &B::perlstring called at /usr/local/share/perl5/Params/ValidationCompiler/Compiler.pm line 248.
Compilation failed in require at /usr/local/lib64/perl5/DateTime.pm line 13.
BEGIN failed--compilation aborted at /usr/local/lib64/perl5/DateTime.pm line 13.
Compilation failed in require.
BEGIN failed--compilation aborted.

Bugzilla-VCS installation Error in Extension.pm

While installing the bugzilla-vcs extension for SVN integration on My windows server 2008, I have encountered this issue. After a lot of searching on google i have finally run out of options. Can somebody assist me in resolving this issue. I am absolutely unfamiliar with perl so am not able to do much this error. The error log is as follows...
Checking for MySQL (v5.0.15) ok: found v5.6.10-log
"my" variable $vcs_repos masks earlier declaration in same scope at ./extensions/VCS/Extension.pm line 180.
"state" variable #_ masks earlier declaration in same scope at ./extensions/VCS/Extension.pm line 196.
"my" variable $self masks earlier declaration in same scope at ./extensions/VCS/Extension.pm line 208.
"state" variable #_ masks earlier declaration in same scope at ./extensions/VCS/Extension.pm line 208.
syntax error at ./extensions/VCS/Extension.pm line 145, near "$type qw(Bzr Cvs Git Hg Svn)"
Global symbol "$type" requires explicit package name at ./extensions/VCS/Extension.pm line 147.
syntax error at ./extensions/VCS/Extension.pm line 172, near "}"
Can't use global #_ in "my" at ./extensions/VCS/Extension.pm line 179, near "= #_"
syntax error at ./extensions/VCS/Extension.pm line 189, near "}"
Can't use global #_ in "my" at ./extensions/VCS/Extension.pm line 196, near "= #_"
syntax error at ./extensions/VCS/Extension.pm line 201, near "}"
Can't use global #_ in "my" at ./extensions/VCS/Extension.pm line 208, near "= #_"
Global symbol "$args" requires explicit package name at ./extensions/VCS/Extension.pm line 209.
syntax error at ./extensions/VCS/Extension.pm line 211, near "}"
./extensions/VCS/Extension.pm has too many errors.
Compilation failed in require at Bugzilla/Extension.pm line 68.
It was able to solve the syntax error issues with a couple very minor code edits on Ubuntu I expect the same would work on windows but I haven't tried it.
in VCS/Extension.pm line 145
change
foreach my $typl qw(Bzr Cvs Git Hg Svn) {
to
my #types = qw(Bzr Cvs Git Hg Svn);
foreach my $type (#types) {
and VCS/lib/Commit.pm line 130
foreach my $key qw(revision revno author message uuid) {
to
my #keys = qw(revision revno author message uuid);
foreach my $key (#keys) {

Pb installing Date::Manip with cpan

I am struggling for one day installing date: with cpan (I am using os x). I always get this message
Warning: prerequisite Test::Inter 0 not found.
Bareword found where operator expected at ./Makefile.PL line 1, near "30 mtime"
(Missing operator before mtime?)
Number found where operator expected at ./Makefile.PL line 2, near "30"
(Missing semicolon on previous line?)
Bareword found where operator expected at ./Makefile.PL line 2, near "30 atime"
(Missing operator before atime?)
Number found where operator expected at ./Makefile.PL line 3, near "30"
(Missing semicolon on previous line?)
Bareword found where operator expected at ./Makefile.PL line 3, near "30 ctime"
(Missing operator before ctime?)
ERROR from evaluation of /Users/mehdibenchoufi/.cpan/build/SBECK-QEN4kY/Date-Manip-6.36/Makefile.PL: ERROR from evaluation of /Users/mehdibenchoufi/.cpan/build/SBECK-QEN4kY/Date-Manip-6.36/PaxHeaders.11917/Makefile.PL: syntax error at ./Makefile.PL line 1, near "30 mtime"
Warning: No success on command[/opt/local/bin/perl5.12 Makefile.PL]
'YAML' not installed, will not store persistent state
SBECK/Date-Manip-6.36.tar.gz
/opt/local/bin/perl5.12 Makefile.PL -- NOT OK
Running make test
Make had some problems, won't test
Running make install
Make had some problems, won't install
Failed during this command:
SBECK/Date-Manip-6.36.tar.gz : writemakefile NO '/opt/local/bin/perl5.12 Makefile.PL' returned status 65280
Does anyone knows how to debug ?
I ran into the same issue and these steps worked for me:
> sudo cpan
cpan[1]> install CPAN
cpan[2]> exit
> sudo rm -rf ~/.cpan/build/SBECK-*
> sudo cpan Date::Manip
Start by installing YAML.pm and Test::Iter.pm
But. You might not want to mess with the system perl on OS X.
You might want to give serious consideration to using perlbrew to manage a local install of perl wiith its own set of modules, separate form the system install.

Why do I get "version (5.12.2) doesn't match executable version" with Perl's PAR?

When I run the following to create an executable out of my Perl script:
pp -o process_target_mode_data Process_Target_Mode_Data.pl
I get the following error output:
Perl lib version (5.12.2) doesn't match executable version (v5.12.0) at /home/Neil/ActivePerl-5.12/lib/Config.pm line 50.
Compilation failed in require at /home/Neil/ActivePerl-5.12/lib/Errno.pm line 8.
BEGIN failed--compilation aborted at /home/Neil/ActivePerl-5.12/lib/Errno.pm line 8.
Compilation failed in require at /home/Neil/ActivePerl-5.12/lib/File/Temp.pm line 148.
BEGIN failed--compilation aborted at /home/Neil/ActivePerl-5.12/lib/File/Temp.pm line 148.
Compilation failed in require at /home/Neil/ActivePerl-5.12/lib/Archive/Zip.pm line 14.
BEGIN failed--compilation aborted at /home/Neil/ActivePerl-5.12/lib/Archive/Zip.pm line 14.
Compilation failed in require at -e line 459.
/home/Neil/ActivePerl-5.12/site/bin/pp: Failed to extract a parl from 'PAR::StrippedPARL::Static' to file 'parleNrP2Xi' at /home/Neil/ActivePerl-5.12/site/lib/PAR/Packer.pm line 1172, <DATA> line 1.
Could someone explain to me what is going on and how I can resolve this problem?
Info brian d foy requested:
[bash-3.2][Neil#willy]$ which pp
/home/Neil/ActivePerl-5.12/site/bin/pp
[bash-3.2][Neil#willy]$ /home/Neil/ActivePerl-5.12/site/bin/pp -o process_target_mode_data Process_Target_Mode_Data.pl
Perl lib version (5.12.2) doesn't match executable version (v5.12.0) at /home/Neil/ActivePerl-5.12/lib/Config.pm line 50.
Compilation failed in require at /home/Neil/ActivePerl-5.12/lib/Errno.pm line 8.
BEGIN failed--compilation aborted at /home/Neil/ActivePerl-5.12/lib/Errno.pm line 8.
Compilation failed in require at /home/Neil/ActivePerl-5.12/lib/File/Temp.pm line 148.
BEGIN failed--compilation aborted at /home/Neil/ActivePerl-5.12/lib/File/Temp.pm line 148.
Compilation failed in require at /home/Neil/ActivePerl-5.12/lib/Archive/Zip.pm line 14.
BEGIN failed--compilation aborted at /home/Neil/ActivePerl-5.12/lib/Archive/Zip.pm line 14.
Compilation failed in require at -e line 459.
/home/Neil/ActivePerl-5.12/site/bin/pp: Failed to extract a parl from 'PAR::StrippedPARL::Static' to file 'parludZfldz' at /home/Neil/ActivePerl-5.12/site/lib/PAR/Packer.pm line 1172, line 1.
[bash-3.2][Neil#willy]$
[bash-3.2][Neil#willy]$ /home/Neil/ActivePerl-5.12/bin/cpan -l | grep PAR
PAR 1.002
PAR::Dist 0.47
PAR::Heavy 0.12
PAR::Filter 0.03
PAR::SetupTemp 1.002
PAR::SetupProgname 1.002
PAR::Packer 1.006
PAR::StrippedPARL::Dynamic 0.958
PAR::StrippedPARL::Static 0.958
PAR::StrippedPARL::Base 0.975
PAR::Filter::Bytecode undef
PAR::Filter::Bleach undef
PAR::Filter::Obfuscate undef
PAR::Filter::PatchContent undef
PAR::Filter::PodStrip undef
App::Packer::PAR 0.91
Perl lib version (5.12.2) doesn't match executable version (v5.12.0)
Some parts of your Perl installation are at a different version than others. More specifically, if you look at /home/Neil/ActivePerl-5.12/lib/Config.pm line 50, you will see that there is an explicit comparison of the version of Perl being executed (which is 5.12.0) to the version of the Config.pm library being used (5.12.2).
If you perform a new installation of ActivePerl 5.12.2 (to bring all components up to the same version), this error should go away.
I had same issue. I installed PAR::Packer from Activestate Perl Package Manager (PPM). As mentioned above in one of the replies, there is version mismatch between the perl and pp binaries. Here's how I fixed it:
Uninstall PAR-Packer from PPM.
Open DOS command line.
Run cpan install PAR::Packer
This will download, compile, and install the package from CPAN. MinGW compiler toolchain will be downloaded as well, if needed. The whole process may take a while on slower cpus.
Find the location of that pp, then figure out its version. I bet it's left over from an earlier installation. Ensure that you have PAR for your new version of Perl.
You can also try specifying the location of the particular pp you want to use so you know exactly what one you are using:
$ /full/path/to/5.12.2/pp ...
Go to the perl/lib/Config.pm and changed the condition in the lines:
die "$0: Perl lib version (5.32.0) doesn't match executable '$^X' version ($])" unless $^V;
to
die "$1: Perl lib version (5.32.1) doesn't match executable '$^X' version ($])" unless $^V;
and the next line
$^V eq 5.32.0 or die sprintf "%s: Perl lib version (5.32.0) doesn't match executable '$^X' version (%vd)", $0, $^V;
to
$^V eq 5.32.1 or die sprintf "%s: Perl lib version (5.32.1) doesn't match executable '$^X' version (%vd)", $0, $^V;
this worked for me, at least it won't complain... yes, i know, PERL and Python are f***d up.