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; }
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.