Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Beatnik (493)

Beatnik
  (email not shown publicly)
http://www.ldl48.org/

A 29 year old belgian who likes Mountain Dew, Girl Scout Cookies, Tim Hortons French Vanilla Flavoured Cappucinno, Belgian beer, Belgian chocolate, Belgian women, Magners Cider, chocolate chipped cookies and Perl. Likes snowboarding, snorkling, sailing and silence. Bach can really cheer him up! He still misses his dog.

Project Daddy of Spine [sf.net], a mod_perl based CMS.

In his superhero time (8.30 AM to 5.30 PM), he works on world peace.

Journal of Beatnik (493)

Thursday May 04, 2006
07:00 AM

mod_perl(2) abstraction

[ #29527 ]
I'm writing a quick abstraction layer so I can use my app in both mod_perl and mod_perl 2. I'm not using any of the fancy bucket stuff in mod_perl 2 ofcourse. I don't want to depend on Apache2::Compat too much so I cooked up something really quick:

sub new {
my $proto  = shift;
my $class  = ref($proto) || $proto;
my $self = {};
$self->{REQUEST} = shift; #This would be Apache::Request or Apache2::Request
if (ref($self->{REQUEST}) eq "Apache::Request")
{ eval qq|use Apache::Cookie; \$self->{COOKIES} = Apache::Cookie->fetch; |;
  eval qq|use Apache::Request; \$self->{REMOTE_HOST} = \$self->{REQUEST}->get_remote_host(); |;
  }
if (ref($self->{REQUEST}) eq "Apache2::Request")
{ eval qq|use Apache2::Cookie; \$self->{COOKIES} = Apache2::Cookie->fetch; |;
  eval qq|use Apache2::Request; \$self->{REMOTE_HOST} = \$self->{REQUEST}->connection->get_remote_host(); |;
}
bless $self,$class;
return $self;
}

I've taken some ideas from a module on CPAN (guessing it was OpenInteract but I'm not sure anymore). For most part, the other Apache(2)::Request method names are the same (but I guess, time will tell if that's true if my app starts falling apart). Now all I need is a way to test changes in my main code for both platforms. I guess I'll have the same problem when I want to test my code on both mysql and postgresql. I'll cook something up in Mech probably.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Is there a reason why you don’t do $self->{REQUEST}->isa("Apache::Request")? In this case, it’s not likely to be a big deal, but there doesn’t seem to be any good reason not to do it, and you never know when you’ll need the flexibility.