Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Making Class::Std work with mod_perl

by Pic (Scribe)
on Mar 04, 2006 at 23:06 UTC ( #534535=perlquestion: print w/replies, xml ) Need Help??
Pic has asked for the wisdom of the Perl Monks concerning the following question:

Hello all.

I'm currently working on a mod_perl project where I'd like to use Class::Std to simplify and standardise my classes. But I've noticed that Class::Std doesn't work very well with mod_perl due to the BEGIN{} block it depends on. However I read a comment from Damian that he's got a workaround he's going to add to the next version.

Does anyone know what he's planning on doing so that I might be able to do something about it in the mean time?

Replies are listed 'Best First'.
Re: Making Class::Std work with mod_perl
by stvn (Monsignor) on Mar 05, 2006 at 01:01 UTC
    But I've noticed that Class::Std doesn't work very well with mod_perl due to the BEGIN{} block it depends on.

    Actually it is a CHECK block that is the problem. Because of the way that mod_perl loads code, it does this after the CHECK and INIT phases of the perl compiler have run. This is the code which causes the issue (about line 258 in the lastest version on CPAN):

    { no warnings qw( void ); CHECK { initialize() } }
    Now, I am not sure if this version (0.0.8) works with mod_perl or not, but I did find this code on line 417:
    Class::Std::initialize(); # Ensure run-time (and mod_perl) setup is +done
    So it is possible that this version will work with mod_perl, but even if it does, then it should be possible1, to actually just put that same line of code at the very end of a mod_perl file, and things should just work.

    (1) - I stress should, because I am not TheDamian, and while I have read over the Class::Std code, I do not profess to understand all it's funky corners and details. However, logic and common sense dictate that if the CHECK block is not run, then just running the same code from the CHECK block should just work. But then again, this is TheDamian we are talking about ;)


      Oooh. Thank you. That does indeed look mighty promising. This should probably work (once I upgrade my local Class::Std that is).

      Thanks a bunch.

Re: Making Class::Std work with mod_perl
by xdg (Monsignor) on Mar 05, 2006 at 02:05 UTC
Re: Making Class::Std work with mod_perl
by spiritway (Vicar) on Mar 05, 2006 at 01:03 UTC

    I suggest you /msg TheDamian and ask him, since he's the most likely person to know the answer to your question.

Re: Making Class::Std work with mod_perl
by TheDamian (Priest) on Mar 05, 2006 at 20:30 UTC
    Class::Std 0.0.8 should now "just work" with mod_perl. From the docs:
    "Class::Std::initialize()" This subroutine sets up all the infrastructure to support your Class::Std- based class. It is usually called automatically in a "CHECK" block, or (if the "CHECK" block fails to run -- under "mod_perl" or "require Class::Std" or "eval "..."") during the first constructor call made to a Class::Std-based object. In rare circumstances, you may need to call this subroutine directly yourself. Specifically, if you set up cumulative, restricted, private, or automethodical class methods (see below), and call any of them before you create any objects, then you need to call "Class::Std::initialize()" first.
    So you shouldn't need to call the new subroutine yourself in most cases.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2017-06-26 14:42 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (582 votes). Check out past polls.