O wise and busy monks, I find myself pulling out valuable hair once again, and come seeking respite and enlightenment.

I'm writing something that will bake and eat cookies in an Apache2/mod_perl2 environment (environment2?) using HTML::Mason. After a bit of wrestling I got Apache2::Cookie and the rest of the libapreq2 things installed.

But now I can't figure out how to test this stuff. The documentation features a mysterious $r, who is supposed to be an Apache2::RequestRec. But then:

$ perl -MApache2::RequestRec -e 'Apache2::RequestRec->new()' Can't locate object method "new" via package "Apache2::RequestRec" at +-e line 1.

Well, maybe there's just another constructor. But I can't find it, and the docs for Apache::RequestUtil actually say that's supposed to work:

new Create a new Apache2::RequestRec object. $r = Apache2::RequestRec->new($c); $r = Apache2::RequestRec->new($c, $pool);

I understand that the $r is, in a running server, automagically provided by mod_perl2. But it seems like a Very Bad Idea ™ to have a running apache2/mod_perl2 system be a prerequisite for unit-testing your cookie recipes, so perhaps I'm just unclear on the concept.

The test I want to run, by the way, would look something like this in its most minimal form:

use strict; use warnings; use Test::More tests => 1; use Apache2::Cookie 2.08; use Apache2::RequestRec 2.0; use Apache2::RequestUtil 2.0; # This, of course, doesn't work: my $r = Apache2::RequestRec->new(); # This is straight out of the synopsis, # but where do I get that blasted $r? my $cookie = Apache2::Cookie->new( $r, -name => "mycookie", -value => "whatever" ); isa_ok( $cookie, 'Apache2::Cookie' );

As much as I'd like to sit around and complain about the mystery meat in that documentation, I have to actually get this thing done, and I believe my options are:

  1. Fall back to CGI::Cookie and hope nothing breaks.
  2. Live without tests and hope nothing breaks. **shudder**
  3. Bite the bullet, dig around in the Apache2::* code, and figure out how to make a Test::MockObject that is sufficiently $r.
  4. Have my dumb mistake(s) pointed out to me by a wise monk who has already solved this problem.

What, dear Monks, would you recommend, and have any of you faced similar troubles in the past?


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.