Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Mojolicious fails to respect @INC

by hesco (Deacon)
on Dec 28, 2017 at 17:12 UTC ( #1206342=perlquestion: print w/replies, xml ) Need Help??
hesco has asked for the wisdom of the Perl Monks concerning the following question:

Refactoring a 2006 perl cgi application (based on a 1999 php application) as a Mojolicious app, with the Moose having been introduced by earlier development, I have just in the last dozen commits begun to introduce Mojo to the mix. After a handful of successful tests with a Mojo::Lite app, as I make the transition to a non-Lite app, on my way to supporting the legacy features, I seem plagued by errors looking like this:

List::Util version 1.45 required--this is only version 1.38 at local/l +ib/perl5/x86_64-linux-gnu-thread-multi/Moose/ line 9. BEGIN failed--compilation aborted at local/lib/perl5/x86_64-linux-gnu- +thread-multi/Moose/ line 9. Compilation failed in require at local/lib/perl5/x86_64-linux-gnu-thre +ad-multi/ line 15. BEGIN failed--compilation aborted at local/lib/perl5/x86_64-linux-gnu- +thread-multi/ line 15. Compilation failed in require at /opt/local/vote/vagrant/cf_vote/bin/. +./lib/ line 5. BEGIN failed--compilation aborted at /opt/local/vote/vagrant/cf_vote/b +in/../lib/ line 5. Compilation failed in require at (eval 12) line 1.

having tried a number of strategies, the latest looking like that in the next code block. The grep in the BEGIN block was motivated by an inspection of `Dumper \@INC;` and `locate List/ | grep -v \.cpanm | xargs grep -i our.*version.*1.38` queries.

#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use FindBin; BEGIN { unshift @INC, "$FindBin::Bin/../lib", "$FindBin::Bin/../local/lib/pe +rl5", "$FindBin::Bin/../lib/perl5"; @INC = grep { $_ !~ /perl\/5.20.2/ } @INC; } print Dumper \@INC; my $listen_socket = '3000'; my $watch_paths = [ 'lib', 'templates', 'app', '/opt/local/vote' ]; # Start command line interface for application require Mojolicious::Commands; Mojolicious::Commands->start_app('Vote','daemon','-l',"http://*:$liste +n_socket");

the resulting @INC is as expected, excluding the problematic version of List::Util.

$VAR1 = [ '/opt/local/vote/vagrant/cf_vote/bin/../lib', '/opt/local/vote/vagrant/cf_vote/bin/../local/lib/perl5', '/opt/local/vote/vagrant/cf_vote/bin/../lib/perl5', '/etc/perl', '/usr/lib/x86_64-linux-gnu/perl5/5.20', '/usr/share/perl5', '/usr/lib/x86_64-linux-gnu/perl/5.20', '/usr/share/perl/5.20', '/usr/local/lib/site_perl', '.' ];

Running that same locate-xrgs-grep query for version 1.49, shows me:
which should be served by the second entry in my @INC array:

line 5 of reads `use Moose;` and its context looks like this:

package Vote; use lib qw( lib local/lib/perl5 ); use CGI; use Moose; use MooseX::NonMoose; extends 'Mojolicious::Controller'; use Mojolicious::Plugin::CGI;

The line blowing up in reads: `use Moose::Exporter;', and its context looks like this:

use strict; use warnings; package Moose; # git description: 2.2008-4-gf9468cd8f our $VERSION = '2.2009'; our $AUTHORITY = 'cpan:STEVAN'; use 5.008003; use Scalar::Util (); use Carp 'carp'; use Module::Runtime 'module_notional_filename'; use Class::Load 'is_class_loaded'; use Moose::Deprecated; use Moose::Exporter; use Class::MOP;

And the problematic Moose::Exporter line reads `use List::Util 1.45 qw( uniq );`, in a context of this:

package Moose::Exporter; our $VERSION = '2.2009'; use strict; use warnings; use Class::Load qw(is_class_loaded); use Class::MOP; use List::Util 1.45 qw( uniq ); use Moose::Util::MetaRole; use Scalar::Util 1.11 qw(reftype); use Sub::Exporter 0.980; use Sub::Name qw(subname);

I'm thinking that the v1.49 installed from a cpanfile entry reading: `requires 'List::Util', '1.49';`, ought to satisfy the 1.45 version requirement created by the Exporter, and do not know why the cpanfile libraries in local/lib/perl5 are not read in precedence over any other available libraries in the @INC stack.

What please might I be missing here?

-- Hugh 
if( $lal && $lol ) { $life++; }
if( $insurance->rationing() ) { $people->die(); }

Replies are listed 'Best First'.
Re: Mojolicious fails to respect @INC
by Corion (Pope) on Dec 28, 2017 at 21:22 UTC

    Somewhere, the wrong version of List::Util gets picked up. Maybe there is 1.38 somewhere in @INC and the 1.49 does not get picked up because file system permissions prohibit it.

    I recommend trying a simpler approach by reducing the problem and eliminating Mojolicious and Moose and instead running a simple program to find out which file gets loaded and expanding from there until you locate the actual problem. Start out with something like:

    #!perl -w use strict; use List::Util; use Data::Dumper; warn List::Util->VERSION; warn $INC{ "List/" }; warn Dumper \%INC; warn Dumper \@INC; warn "Perl $^W"; warn "Perl Version $]";

    This should point you to the 1.38 version. If it outputs the 1.49 version, then something else updates @INC, or your code is run by a version of Perl that you did not install 1.49 into. Check and correct until you have found the difference between your program, your expectation and the Mojolicious program.

      Thanks, Corion! I had abandoned the `use lib` strategy on an earlier project, to solve some issue which I do not remember at the moment. Rather than running the `mojo generate app` and adapting from there, I did some cut-n-paste from that previous project, and found myself in this mess. Thanks for steering me back to sanity.

      if( $lal && $lol ) { $life++; }
      if( $insurance->rationing() ) { $people->die(); }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1206342]
Approved by marto
Front-paged by marto
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-06-23 10:43 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.