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.
`ref()` is suboptimal (Score:1)
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.