Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Unable to preload Data::Dumper with mod_perl

by nysus (Priest)
on Dec 04, 2017 at 12:06 UTC ( #1204846=perlquestion: print w/replies, xml ) Need Help??
nysus has asked for the wisdom of the Perl Monks concerning the following question:

So I'm working with mod_perl. It is blazing fast! HTML pages are consistently generated in 10 to 20 ms even immediately after a server restart. Total page generation time is under 200 ms with jQuery mobile.

In order to accomplish this, I've preloaded all the modules in my startup.pl file. However, one module that doesn't seem to preload is Data::Dumper. Even though it's in my startup file, I still have to do use Data::Dumper qw (Dumper) in each of my modules to be able to use it. Even if I do use Data::Dumper qw(Dumper) in my startup file, it still has no effect. I'm not sure why this is, though. Anyone know?

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

Replies are listed 'Best First'.
Re: Unable to preload Data::Dumper with mod_perl
by Corion (Pope) on Dec 04, 2017 at 12:12 UTC

    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

      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

Re: Unable to preload Data::Dumper with mod_perl
by Your Mother (Chancellor) on Dec 04, 2017 at 13:10 UTC

    I'm sorry to hijack the thread but since Corion already gave a great answer I want to inject what I consider important context for newcomers to Perl webwork who read a glowing endorsement of modperl on the cusp of 2018.

    Apache is like Microsoft Word. It has a million options but you only need six. NGINX does those six things, and it does five of them 50 times faster than Apache. Chris Lea

    modperl is somewhat analogous to CGI at this point. It was the cat's meow in its day but really shouldn't be used on new work unless you have a compelling reason; i.e. an Apache hook that is impossible to implement in another webserver. My context, I'm no hater: I used modperl personally for years and I still use it at work—and like it—but only because the codebase is from the 90s.

    I argue that Perl best practice today—and for a few years now—is nginx with uWSGI as the Perl application server. Excepting the edge cases modperl affords where direct interaction with the webserver is necessary, this new deployment combination is better in every single way.

      I'm definitely open to trying something new under the hood. Thanks! For now, I was more interested in having fun developing my own little web framework to see what was involved (using jQuery Mobile as a front end). I was going to kick the tires of Dancer to see what it can do for me. I'll try it with nginx per your suggestion. So can you give me a rough idea of how it works? Can I store all the Perl modules in memory like with mod_perl? If not, how does it achieve results on par with mod_perl?

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

        I started a reply but it got out of control with covering too many topics. So, for now, because I might have time to finish what I started later, I'll just say I am a huge fan of development for development's sake. A lot of my chops came from toy apps and home code. So, never read my "best practices" soapbox as a critique of programming for self-directed fun. :P If I get time to finish a "modern" deployment write-up, I will.

      I fired up nginx and for a minimalist web page with jQuery I'm seeing page rendering times of under 100ms on a pretty consistent basis on a clone of the same server. So that's about 1/2 of what I was seeing with apache and mod_perl. Note, however, I haven't connected it to a database and backend or used any perl code. It'll be interesting to see what happens when I add that to the mix.

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

Re: Unable to preload Data::Dumper with mod_perl
by Anonymous Monk on Dec 04, 2017 at 12:23 UTC
    In your modules use ::Dumper() its same as writing main::Dumper() Since thAt is where it currently is exported

    but are you really dumpering that much all over so that adding use line is a hassle? Why?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2018-01-23 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (240 votes). Check out past polls.

    Notices?