in reply to Where can I buy an $r with which to test Apache2::Cookie?

You can't run Apache2:: classes outside of the mod_perl environment. They interact directly with a C API to data structures that don't exist when apache is not running. However, there is a high-quality testing framework developed specifically for this purpose called Apache::Test. It handles all the details of starting a test server for you. It's what the mod_perl project uses for testing and you can use it too.
  • Comment on Re: Where can I buy an $r with which to test Apache2::Cookie?

Replies are listed 'Best First'.
Re^2: Where can I buy an $r with which to test Apache2::Cookie?
by frostman (Beadle) on Feb 11, 2008 at 05:38 UTC

    Thanks. That's what I feared, and I have heard of (and seen in action, with mixed results) Apache::Test, for which there is probably now an Apache2::Test... but I must say I still don't think that's a reasonable prerequisite for testing cookie generation.

    For testing cookie dispatch to the server, maybe... but for testing the generation per se, nope. At this point I'm hoping I can get it working with Test::MockObject.

    So I suppose if your warning applies to all Apache2:: classes then I'm going to waste some time, and if it just applies to the RequestRec then I'm golden.

      It's not going to work. Apache2::Cookie and the rest of libapreq are a perl interface to a C data structure provided by apache. It's like trying to test your database without running a database.

      If you're determined to test apache without apache, the best you can do is make a mock object of Apache2::Cookie and test that you sent it the right data.

        Oddly, I think it's working fine with the solution in my last comment.

        I'm determined to test, without apache2, the parts of Apache2::* code that shouldn't need apache2, at least for my private values of $shouldn_t.

        But even if I succeed with ::Cookie, I may well fail elsewhere, and so will keep your warning in mind.