wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r16096: Initial commit for refactoring to Apache...

Committer: gprochaev
Initial commit for refactoring to Apache2

A   branches/modernize2/cgi-bin/LJ/Request/Apache.pm
A   branches/modernize2/cgi-bin/LJ/Request/Apache2.pm
Added: branches/modernize2/cgi-bin/LJ/Request/Apache.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/Request/Apache.pm	                        (rev 0)
+++ branches/modernize2/cgi-bin/LJ/Request/Apache.pm	2010-01-18 10:02:18 UTC (rev 16096)
@@ -0,0 +1,367 @@
+package LJ::Request::Apache;
+use strict;
+
+use Apache::Constants;
+#*OK        = \&Apache::Constants::OK;
+#*DONE      = \&Apache::Constants::DONE;
+#*NOT_FOUND = \&Apache::Constants::NOT_FOUND;
+
+sub LJ::Request::M_OPTIONS { return Apache::Constants::M_OPTIONS() }
+
+require Apache::Request;
+require Apache::URI;
+
+my $instance = '';
+sub LJ::Request::request { $instance }
+sub LJ::Request::r {
+    die "Request is not provided to LJ::Request" unless $instance;
+    return $instance->{r};
+}
+
+
+sub LJ::Request::instance {
+    my $class = shift;
+    die "use 'request' instead";
+#    return $instance ? $instance : undef;
+}
+
+
+sub LJ::Request::REDIRECT {
+    return \&Apache::Constants::REDIRECT;
+}
+
+sub LJ::Request::init {
+    my $class = shift;
+    my $r     = shift;
+
+    $instance = bless {}, $class;
+    $instance->{apr} = Apache::Request->new($r, DISABLE_UPLOADS => 1);
+    $instance->{r} = $r;
+    return $instance;
+}
+
+sub LJ::Request::is_inited {
+    return $instance ? 1 : 0;
+}
+
+sub LJ::Request::update_mtime {
+    my $class = shift;
+    die "Request is not provided to LJ::Request" unless $instance;
+    return $instance->{apr}->update_mtime(@_);
+}
+
+sub LJ::Request::set_last_modified {
+    my $class = shift;
+    die "Request is not provided to LJ::Request" unless $instance;
+    return $instance->{apr}->set_last_modified(@_);
+}
+
+sub LJ::Request::request_time {
+    my $class = shift;
+    die "Request is not provided to LJ::Request" unless $instance;
+    return $instance->{apr}->request_time();
+}
+
+sub LJ::Request::read {
+    my $class = shift;
+    die "Request is not provided to LJ::Request" unless $instance;
+    return $instance->{apr}->read(@_);
+}
+
+sub LJ::Request::is_main {
+    my $class = shift;
+    die "Request is not provided to LJ::Request" unless $instance;
+    return $instance->{r}->is_main(@_);
+}
+
+sub LJ::Request::dir_config {
+    my $class = shift;
+    die "Request is not provided to LJ::Request" unless $instance;
+    return $instance->{apr}->dir_config(@_);
+}
+
+sub LJ::Request::header_only {
+    my $class = shift;
+    die "Request is not provided to LJ::Request" unless $instance;
+    return $instance->{apr}->header_only;
+}
+
+sub LJ::Request::content_languages {
+    my $class = shift;
+    die "Request is not provided to LJ::Request" unless $instance;
+    return $instance->{apr}->content_languages(@_);
+}
+
+sub LJ::Request::register_cleanup {
+    my $class = shift;
+    return $instance->{apr}->register_cleanup(@_);
+}
+
+sub LJ::Request::path_info {
+    my $class = shift;
+    return $instance->{apr}->path_info(@_);
+}
+
+sub LJ::Request::args {
+    my $class = shift;
+    return $instance->{apr}->args(@_);
+}
+
+sub LJ::Request::method {
+    my $class = shift;
+    $instance->{apr}->method;
+}
+
+sub LJ::Request::document_root {
+    my $class = shift;
+    $instance->{apr}->document_root;
+}
+
+sub LJ::Request::finfo {
+    my $class = shift;
+    $instance->{apr}->finfo;
+}
+
+sub LJ::Request::filename {
+    my $class = shift;
+    $instance->{apr}->filename(@_);
+}
+
+sub LJ::Request::add_httpd_conf {
+    my $class = shift;
+    Apache->httpd_conf(@_);
+}
+
+sub LJ::Request::is_initial_req {
+    my $class = shift;
+    $instance->{apr}->is_initial_req(@_);
+}
+
+sub LJ::Request::push_handlers_global {
+    my $class = shift;
+    Apache->push_handlers(@_);
+}
+
+sub LJ::Request::push_handlers {
+    my $class = shift;
+    return $instance->{r}->push_handlers(@_);
+}
+
+sub LJ::Request::set_handlers {
+    my $class = shift;
+    $instance->{apr}->set_handlers(@_);
+}
+
+sub LJ::Request::handler {
+    my $class = shift;
+    $instance->{apr}->handler(@_);
+}
+
+sub LJ::Request::method_number {
+    my $class = shift;
+    return $instance->{r}->method_number(@_);
+}
+
+sub LJ::Request::status {
+    my $class = shift;
+    return $instance->{r}->status(@_);
+}
+
+##
+##
+##
+sub LJ::Request::free {
+    my $class = shift;
+    $instance = undef;
+}
+
+
+sub LJ::Request::notes {
+    my $class = shift;
+    $instance->{apr}->notes (@_);
+}
+
+sub LJ::Request::pnotes {
+    my $class = shift;
+    $instance->{apr}->pnotes (@_);
+}
+
+sub LJ::Request::parse {
+    my $class = shift;
+    $instance->{apr}->parse (@_);
+}
+
+sub LJ::Request::uri {
+    my $class = shift;
+    $instance->{apr}->uri (@_);
+}
+
+sub LJ::Request::hostname {
+    my $class = shift;
+    $instance->{apr}->hostname (@_);
+}
+
+sub LJ::Request::header_out {
+    my $class = shift;
+    $instance->{apr}->header_out (@_);
+}
+
+sub LJ::Request::headers_out {
+    my $class = shift;
+    $instance->{apr}->headers_out (@_);
+}
+
+sub LJ::Request::header_in {
+    my $class = shift;
+    $instance->{apr}->header_in (@_);
+}
+
+sub LJ::Request::headers_in {
+    my $class = shift;
+    $instance->{apr}->headers_in (@_);
+}
+
+sub LJ::Request::param {
+    my $class = shift;
+    $instance->{apr}->param (@_);
+}
+
+sub LJ::Request::no_cache {
+    my $class = shift;
+    $instance->{apr}->no_cache (@_);
+}
+
+sub LJ::Request::content_type {
+    my $class = shift;
+    $instance->{apr}->content_type (@_);
+}
+
+sub LJ::Request::pool {
+    my $class = shift;
+    $instance->{apr}->pool;
+}
+
+sub LJ::Request::connection {
+    my $class = shift;
+    $instance->{apr}->connection;
+}
+
+sub LJ::Request::output_filters {
+    my $class = shift;
+    $instance->{apr}->output_filters;
+}
+
+sub LJ::Request::print {
+    my $class = shift;
+    $instance->{r}->print (@_);
+}
+
+sub LJ::Request::content_encoding {
+    my $class = shift;
+    $instance->{r}->content_encoding(@_);
+}
+
+sub LJ::Request::send_http_header {
+    my $class = shift;
+    $instance->{apr}->send_http_header (@_)
+}
+
+
+sub LJ::Request::err_headers_out {
+    my $class = shift;
+    $instance->{apr}->err_headers_out (@_)
+}
+
+
+
+## Returns Array (Key, Value, Key, Value) which can be converted to HASH.
+## But there can be some params with the same name!
+sub LJ::Request::get_params {
+    my $class = shift;
+    if (wantarray) {
+        my @params = $instance->{r}->args;
+        return @params;
+    } else {
+        my $query_string = $instance->{r}->args;
+        return $query_string;
+    }
+}
+sub LJ::Request::post_params {
+    my $class = shift;
+
+    ## $r->content
+    ## The $r->content method will return the entity body read from the client,
+    ## but only if the request content type is application/x-www-form-urlencoded.
+    ## ...
+    ## NOTE: you can only ask for this once, as the entire body is read from the client.
+    return () if $instance->{r}->headers_in()->get("Content-Type") =~ m!^multipart/form-data!;
+
+    return @{ $instance->{params} } if $instance->{params};
+    my @params = $instance->{r}->content;
+    $instance->{params} = \@params;
+    return @params;
+}
+
+
+sub LJ::Request::add_header_out {
+    my $class  = shift;
+    my $header = shift;
+    my $value  = shift;
+
+    $instance->{r}->err_headers_out->add($header, $value);
+    $instance->{r}->headers_out->add($header, $value);
+
+    return 1;
+}
+
+# TODO: maybe remove next method and use 'header_out' instead?
+sub LJ::Request::set_header_out {
+    my $class  = shift;
+    my $header = shift;
+    my $value  = shift;
+
+    $instance->{r}->err_header_out($header, $value);
+    $instance->{r}->header_out($header, $value);
+
+    return 1;
+}
+
+
+sub LJ::Request::log_error {
+    my $class = shift;
+    return $instance->{r}->log_error(@_);
+}
+
+sub LJ::Request::remote_ip {
+    my $class = shift;
+    return $instance->{r}->connection()->remote_ip(@_);
+}
+
+sub LJ::Request::remote_host {
+    my $class = shift;
+    return $instance->{r}->connection()->remote_host;
+}
+
+sub LJ::Request::user {
+    my $class = shift;
+    return $instance->{r}->connection()->user;
+}
+
+sub LJ::Request::aborted {
+    my $class = shift;
+    return $instance->{r}->connection()->aborted;
+}
+
+
+sub LJ::Request::sendfile {
+    my $class = shift;
+    my $filename = shift;
+    my $fh       = shift;
+
+    $instance->{r}->send_fd($fh);
+    $fh->close();
+
+}
+
+
+1;

Added: branches/modernize2/cgi-bin/LJ/Request/Apache2.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/Request/Apache2.pm	                        (rev 0)
+++ branches/modernize2/cgi-bin/LJ/Request/Apache2.pm	2010-01-18 10:02:18 UTC (rev 16096)
@@ -0,0 +1,230 @@
+package LJ::Request::Apache2;
+use strict;
+
+use constant MP2 => (exists $ENV{MOD_PERL_API_VERSION} &&
+                     $ENV{MOD_PERL_API_VERSION} == 2) ? 1 : 0;
+
+BEGIN {
+    if (MP2){
+        require Apache2::Const;
+        import Apache2::Const qw/REDIRECT/;
+        *OK        = \&Apache2::Const::OK;
+        *REDIRECT  = \&REDIRECT;
+        *DONE      = \&Apache2::Const::DONE;
+        *NOT_FOUND = \&Apache2::Const::NOT_FOUND;
+    } else {
+        require Apache::Constants;
+        *OK        = \&Apache::Constants::OK;
+        *REDIRECT  = \&Apache::Constants::REDIRECT;
+        *DONE      = \&Apache::Constants::DONE;
+        *NOT_FOUND = \&Apache::Constants::NOT_FOUND;
+    }
+}
+
+BEGIN {
+    if (MP2){
+        require Apache2::Request;
+        require Apache2::RequestUtil;
+        require Apache2::RequestRec;
+    } else {
+        require Apache::Request;
+        require Apache::URI;
+    }
+}
+
+my $instance = '';
+
+sub new {
+    my $class = shift;
+    my $apr   = shift;
+    
+    $instance ||= bless {}, $class;
+    $instance->{apr} = MP2
+                      ? Apache2::Request->new($apr)
+                      : Apache::Request->new($apr,
+                                             DISABLE_UPLOADS => 1
+                                            );
+    $instance->{r} = $apr;
+    return $instance;
+}
+
+sub content {
+}
+
+sub args {
+    my $self = shift;
+    $self->{apr}->args;
+}
+
+sub method {
+    my $self = shift;
+    $self->{apr}->method;
+}
+
+sub document_root {
+    my $self = shift;
+    if (MP2) {
+        ;
+    } else {
+        $self->{apr}->document_root;
+    }
+}
+
+sub finfo {
+    my $self = shift;
+    if (MP2) {
+        require APR::Finfo;
+        stat $self->{apr}->filename;
+        \*_;
+    } else {
+        $self->{apr}->finfo;
+    }
+}
+
+sub filename {
+    my $self = shift;
+    $self->{apr}->filename;
+}
+
+sub httpd_conf {
+    my $class = shift;
+    unless (MP2) {
+        Apache->httpd_conf(@_);
+    } else {
+####    Apache2::ServerUtil->server->add_config( [ split /\n/, $text ] );
+        Apache2::ServerUtil->server->add_config(@_);
+    }
+}
+
+sub is_initial_req {
+    my $self = shift;
+    $self->{apr}->is_initial_req(@_);
+}
+
+sub push_handlers {
+    my $self = shift;
+    if (MP2) {
+        Apache2::ServerUtil->push_handlers(@_);
+    } else {
+        Apache->push_handlers(@_);
+    }
+}
+
+sub set_handlers {
+    my $self = shift;
+    $self->{apr}->set_handlers(@_);
+}
+
+sub free {
+    my $class = shift;
+    $instance = undef;
+}
+
+sub instance {
+    my $class = shift;
+    return $instance ? $instance : undef;
+}
+
+sub notes {
+    my $self = shift;
+    $self->{apr}->pnotes (@_);
+}
+
+sub pnotes {
+    my $self = shift;
+    $self->{apr}->pnotes (@_);
+}
+
+sub parse {
+    my $self = shift;
+    $self->{apr}->parse (@_);
+}
+
+sub uri {
+    my $self = shift;
+    $self->{apr}->uri (@_);
+}
+
+sub hostname {
+    my $self = shift;
+    $self->{apr}->hostname (@_);
+}
+
+sub header_out {
+    my $self = shift;
+    if (MP2) {
+        $self->{apr}->headers_out->add (@_);
+    } else {
+        $self->{apr}->header_out (@_);
+    }
+}
+
+sub headers_out {
+    my $self = shift;
+    $self->{apr}->headers_out (@_);
+}
+
+sub header_in {
+    my $self = shift;
+    if (MP2) {
+        my $header = shift;
+        $self->{apr}->headers_in->{$header} || '';
+    } else {
+        $self->{apr}->header_in (@_);
+    }
+}
+
+sub headers_in {
+    my $self = shift;
+    $self->{apr}->headers_in (@_);
+}
+
+sub param {
+    my $self = shift;
+    $self->{apr}->param (@_);
+}
+
+sub no_cache {
+    my $self = shift;
+    $self->{apr}->no_cache (@_);
+}
+
+sub content_type {
+    my $self = shift;
+    $self->{apr}->content_type (@_);
+}
+
+sub pool {
+    my $self = shift;
+    $self->{apr}->pool;
+}
+
+sub connection {
+    my $self = shift;
+    $self->{apr}->connection;
+}
+
+sub output_filters {
+    my $self = shift;
+    $self->{apr}->output_filters;
+}
+
+sub print {
+    my $self = shift;
+    $self->{r}->print (@_);
+}
+
+sub dir_config {
+    my $self = shift;
+    $self->{r}->dir_config (@_);
+}
+
+sub send_http_header {
+    my $self = shift;
+    $self->{apr}->send_http_header (@_)
+        unless MP2;
+
+}
+
+1;
+

Tags: livejournal, pm, wisest-owl
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments