Solstice::Server::ModPerl::API - An interface to mod_perl that abstracts the differences in versions.


Solstice documentation  | view source Contained in the Solstice distribution.

Index


NAME

Top

Solstice::Server::ModPerl::API - An interface to mod_perl that abstracts the differences in versions.

SYNOPSIS

Top

  use Solstice::Server::ModPerl::API;

DESCRIPTION

Top

An interface to mod_perl that abstracts the differences in versions.

Methods

new()
useApacheRequest()

Returns a boolean for whether Apache[2]::Request should be used in preference of CGI.

_setVersion($version)

Sets the version of mod_perl

version()

Gets the version of mod_perl.

setPostMax($post_max)

Sets the maximum post size.

getPostMax()

Gets the maximum post size.

is2()

Returns whether the version is 2.

is1()

Returns whether the version is 1.

_setRequest($r)

Sets the apache request object that is passed to the mod_perl handler.

request()

Gets the apache request object.

apacheRequest()

Gets the apache request object that is provided by libapreq.

mod_perl wrappers

sendfile() =cut

sub sendfile { my $self = shift; if ($self->is2()) { return $self->request()->sendfile(@_); } else { return $self->request()->send_fd(@_); } }

uri() =cut

sub uri { my $self = shift; return $self->request()->uri(@_); }

args() =cut

sub args { my $self = shift; return $self->request()->args(@_); }

filename() =cut

sub filename { my $self = shift; return $self->request()->filename(@_); }

set_last_modified() =cut

sub set_last_modified { my $self = shift; return $self->request()->set_last_modified(@_); }

set_etag() =cut

sub set_etag { my $self = shift; return $self->request()->set_etag(@_); }

set_content_length() =cut

sub set_content_length { my $self = shift; return $self->request()->set_content_length(@_); }

set_content_disposition() =cut

sub set_content_disposition { my $self = shift; my $input = shift; return $self->header_out('Content-Disposition', $input); }

set_content_type() =cut

sub set_content_type { my $self = shift; return $self->content_type(@_); }

content_type() =cut

sub content_type { my $self = shift; my $type = shift; if( $type ){ $self->request()->content_type($type); }else{ return $self->request()->content_type(); } }

update_mtime() =cut

sub update_mtime { my $self = shift; return $self->request()->update_mtime(@_); }

meets_conditions() =cut

sub meets_conditions { my $self = shift; return $self->request()->meets_conditions(@_);

}

method() =cut

sub method { my $self = shift; return $self->request()->method(@_); }

header_only() =cut

sub header_only { my $self = shift; return $self->request()->header_only(@_); }

header_in('header') =cut

sub header_in { my $self = shift; my $header = shift;

    if($self->is2()){
        return $self->request()->headers_in->{$header};
    }else{
        return $self->request()->header_in($header);
    }
}

header_out() =cut

sub header_out { my $self = shift; my $header = shift; my $value = shift;

    my $r = $self->request();

    if ($self->is2()) {
        return $r->headers_out->add($header => $value);
    } else {
        return $self->request()->header_out($header => $value);
    }
}

#I don't believe this method is used any longer, if you see this after nov 2007 or so, remove it sub send_http_header { my $self = shift;

    if($self->is2()) {
        #there is no equivalent to send_http_header in mp2
        #mp2 should handle this correctly now, we might need to look into rflush if we find this
        #is not good enough
    }else {
        return $self->request()->send_http_header();
    }
}




status (return code)

Sets the statuscode of the response

const($constant_name)

Returns the equivalent Apache::Constant or Apache2::Const, depending on what version of mod_perl you're using.

mod_perl server wrappers

get_handlers('hook_name') =cut

sub get_handlers { my $self = shift; if ($self->is2()) { # Allegedly you can just do the following: # return Apache2::ServerUtil->server->get_handlers(@_); # but i always get nothing. So, instead i traverse the config tree. # TODO: See if this is a known mod_perl2 bug, that we can upgrade past

        my $handler_name = $_[0];
        my $virtual_root = $ENV{'SOLSTICE_VIRTUAL_ROOT'};
        my $tree = Apache2::Directive::conftree();
        my $conf_data = $tree->as_hash;

        my $vhost_data = $conf_data->{'VirtualHost'};

        return [] unless defined $vhost_data;

        foreach my $vhost (keys %{$vhost_data}) {
            my $location_data = $vhost_data->{$vhost}->{'Location'};
            return [] unless defined $location_data;

            foreach my $location (keys %{$location_data}) {
                # If this is handling the path given in config, and it's handled by Solstice, assume that this is the place.
                # If there are multiple VHosts with Solstice handling the same virtual root, this could be problematic.
                # Hopefully before that happens, we'll be able to use the get_handlers() method mentioned above.
                if ($location eq $virtual_root && 'Solstice::Handler' eq $location_data->{$location}->{'PerlResponseHandler'}) {
                    return [$location_data->{$location}->{$handler_name}];
                }
            }
        }

        return [];
    }
    elsif ($self->is1()) {
        return $self->request()->get_handlers(@_);
    }

    return [];
}

1; __END__

AUTHOR

Top

Catalyst Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision$

COPYRIGHT

Top


Solstice documentation  | view source Contained in the Solstice distribution.