in reply to Unable to preload Data::Dumper with mod_perl

use is two parts:

require Data::Dumper; Data::Dumper->import('Dumper');

The first part is done in your startup.pl.

The ->import(...) part is also only done in your startup.pl instead of (what you intend to) in every module.

The solution would be to either explicitly import it, to explicitly call it as Data::Dumper::Dumper( ... ), or to have one central module, App::Nysus::Utils(), which exports Data::Dumper::Dumper into every caller:

use App::Nysus::Utils; # import all the stuff
package App::Nysus::Utils; use strict; use Data::Dumper (); # just for completeness / offline testing outside + of Apache sub import { (my $target) = caller(); no strict 'refs'; *{ "$target\::Dumper" } = \&Data::Dumper::Dumper; }; 1;

I'm not sure which route I would go. They all have disadvantages and advantages:

  1. explicit import - makes everything explicit, allows for easy offline testing, clutters your source code
  2. explicit calling - makes everything even more explicit, doesn't allow for offline testing, clutters your source code even more
  3. utility module - keeps everything implicit, allows for easy offline testing, keeps your source code as is, but hides where stuff comes from

Replies are listed 'Best First'.
Re^2: Unable to preload Data::Dumper with mod_perl
by nysus (Parson) on Dec 04, 2017 at 13:10 UTC

    I went with an explicit call. I only use these calls sporadically and just added a vim abbreviation to my vimrc to make adding in the call painless. Thanks!

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks