vadvs (vadvs) wrote in changelog,
vadvs
vadvs
changelog

[livejournal] r16106: use LJ::Request instead of Apache(->requ...

Committer: vsukhanov
use LJ::Request instead of Apache(->request)
U   branches/modernize2/cgi-bin/Apache/LiveJournal.pm
U   branches/modernize2/cgi-bin/LJ/Hooks/PingBack.pm
U   branches/modernize2/cgi-bin/LJ/PageStats.pm
U   branches/modernize2/cgi-bin/LJ/PingBack.pm
U   branches/modernize2/cgi-bin/LJ/Request/Apache.pm
U   branches/modernize2/cgi-bin/LJ/URI.pm
Modified: branches/modernize2/cgi-bin/Apache/LiveJournal.pm
===================================================================
--- branches/modernize2/cgi-bin/Apache/LiveJournal.pm	2010-01-19 11:20:00 UTC (rev 16105)
+++ branches/modernize2/cgi-bin/Apache/LiveJournal.pm	2010-01-19 11:26:37 UTC (rev 16106)
@@ -183,6 +183,13 @@
 }
 
 sub redir {
+    # TODO: remove debug code
+    if (@_ == 3){
+        require Carp;
+        Carp::cluck("get 3 args instead of 2");
+        shift @_; # assumes the first arg is a Apache->request obj. 
+    }
+    
     my ($url, $code) = @_;
     LJ::Request->content_type("text/html");
     LJ::Request->header_out(Location => $url);

Modified: branches/modernize2/cgi-bin/LJ/Hooks/PingBack.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/Hooks/PingBack.pm	2010-01-19 11:20:00 UTC (rev 16105)
+++ branches/modernize2/cgi-bin/LJ/Hooks/PingBack.pm	2010-01-19 11:26:37 UTC (rev 16106)
@@ -146,16 +146,15 @@
     my $html_ref = shift;
 
     my $entry = $opts->{ljentry};
-    my $r     = $opts->{r};
 
-    return unless $r;
+    return unless LJ::Request->is_inited;
     return unless $entry;
-    return unless $r->notes("view") eq 'entry';
+    return unless LJ::Request->notes("view") eq 'entry';
     return unless LJ::PingBack->has_user_pingback($entry->journal);
 
 
     if (LJ::PingBack->should_entry_recieve_pingback($entry)){
-        $r->header_out('X-Pingback', $LJ::PINGBACK->{uri});
+        LJ::Request->set_header_out('X-Pingback', $LJ::PINGBACK->{uri});
     }
     
     

Modified: branches/modernize2/cgi-bin/LJ/PageStats.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/PageStats.pm	2010-01-19 11:20:00 UTC (rev 16105)
+++ branches/modernize2/cgi-bin/LJ/PageStats.pm	2010-01-19 11:26:37 UTC (rev 16106)
@@ -1,5 +1,6 @@
 package LJ::PageStats;
 use strict;
+use LJ::Request;
 
 # loads a page stat tracker
 sub new {
@@ -58,11 +59,11 @@
     my $ctx = $self->get_context;
     return 0 unless ($ctx && $ctx =~ /^(app|journal)$/);
 
-    my $r = $self->get_request or return 0;
+    LJ::Request->is_inited or return 0;
 
     # Make sure we don't exclude tracking from this page or path
-    return 0 if grep { $r->uri =~ /$_/ } @{ $LJ::PAGESTATS_EXCLUDE{'uripath'} };
-    return 0 if grep { $r->notes('codepath') eq $_ } @{ $LJ::PAGESTATS_EXCLUDE{'codepath'} };
+    return 0 if grep { LJ::Request->uri =~ /$_/ } @{ $LJ::PAGESTATS_EXCLUDE{'uripath'} };
+    return 0 if grep { LJ::Request->notes('codepath') eq $_ } @{ $LJ::PAGESTATS_EXCLUDE{'codepath'} };
 
     # See if their ljuniq cookie has the PageStats flag
     if ($BML::COOKIE{'ljuniq'} =~ /[a-zA-Z0-9]{15}:\d+:pgstats([01])/) {
@@ -117,9 +118,8 @@
 
 sub filename {
     my ($self) = @_;
-    my $r = $self->get_request;
 
-    my $filename = $r->filename;
+    my $filename = LJ::Request->filename;
     $filename =~ s!$LJ::HOME/(?:ssldocs|htdocs)!!;
 
     return $filename;
@@ -127,9 +127,8 @@
 
 sub codepath {
     my ($self) = @_;
-    my $r = $self->get_request;
 
-    my $codepath = $r->notes('codepath');
+    my $codepath = LJ::Request->notes('codepath');
     # remove 's2.' or 's1.' prefix from codepath
     $codepath =~ s/^[Ss]\d{1}\.(.*)$/$1/;
 

Modified: branches/modernize2/cgi-bin/LJ/PingBack.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/PingBack.pm	2010-01-19 11:20:00 UTC (rev 16105)
+++ branches/modernize2/cgi-bin/LJ/PingBack.pm	2010-01-19 11:26:37 UTC (rev 16106)
@@ -113,7 +113,9 @@
     my $text = $args{text};
     my $mode = $args{mode};
 
-    return unless $mode =~ m!^[LO]$!; # (L)ivejournal only, (O)pen.
+    # Send ALL posts to PB server
+    # return unless $mode =~ m!^[LO]$!; # (L)ivejournal only, (O)pen.
+
     my $sclient = LJ::theschwartz();
     unless ($sclient){
         warn "LJ::PingBack: Could not get TheSchwartz client";

Modified: branches/modernize2/cgi-bin/LJ/Request/Apache.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/Request/Apache.pm	2010-01-19 11:20:00 UTC (rev 16105)
+++ branches/modernize2/cgi-bin/LJ/Request/Apache.pm	2010-01-19 11:26:37 UTC (rev 16106)
@@ -40,11 +40,6 @@
     return $instance;
 }
 
-sub LJ::Request::status_line {
-    die "Request is not provided to LJ::Request" unless $instance;
-    return $instance->{apr}->status_line(@_);
-}
-
 sub LJ::Request::is_inited {
     return $instance ? 1 : 0;
 }
@@ -292,6 +287,8 @@
 
 ## Returns Array (Key, Value, Key, Value) which can be converted to HASH.
 ## But there can be some params with the same name!
+#
+# TODO: do we need this and 'args' methods? they are much the same.
 sub LJ::Request::get_params {
     my $class = shift;
     if (wantarray) {

Modified: branches/modernize2/cgi-bin/LJ/URI.pm
===================================================================
--- branches/modernize2/cgi-bin/LJ/URI.pm	2010-01-19 11:20:00 UTC (rev 16105)
+++ branches/modernize2/cgi-bin/LJ/URI.pm	2010-01-19 11:26:37 UTC (rev 16106)
@@ -6,20 +6,20 @@
                          HTTP_MOVED_PERMANENTLY HTTP_MOVED_TEMPORARILY
                          M_TRACE M_OPTIONS);
 
-# Takes an Apache $r and a path to BML filename relative to htdocs
+# Takes an Apache a path to BML filename relative to htdocs
 sub bml_handler {
-    my ($class, $r, $filename) = @_;
+    my ($class, $filename) = @_;
 
-    $r->handler("perl-script");
-    $r->notes("bml_filename" => "$LJ::HOME/htdocs/$filename");
-    $r->push_handlers(PerlHandler => \&Apache::BML::handler);
+    LJ::Request->handler("perl-script");
+    LJ::Request->notes("bml_filename" => "$LJ::HOME/htdocs/$filename");
+    LJ::Request->push_handlers(PerlHandler => \&Apache::BML::handler);
     return OK;
 }
 
 # Handle a URI. Returns response if success, undef if not handled
 # Takes URI and Apache $r
 sub handle {
-    my ($class, $uri, $r) = @_;
+    my ($class, $uri) = @_;
 
     return undef unless $uri;
 
@@ -27,38 +27,38 @@
     if (my ($rpc) = $uri =~ m!^.*/__rpc_(\w+)$!) {
         my $bml_handler_path = $LJ::AJAX_URI_MAP{$rpc};
 
-        return LJ::URI->bml_handler($r, $bml_handler_path) if $bml_handler_path;
+        return LJ::URI->bml_handler($bml_handler_path) if $bml_handler_path;
     }
 
     # handle normal URI mappings
     if (my $bml_file = $LJ::URI_MAP{$uri}) {
-        return LJ::URI->bml_handler($r, $bml_file);
+        return LJ::URI->bml_handler($bml_file);
     }
 
     # handle URI redirects
     if (my $url = $LJ::URI_REDIRECT{$uri}) {
-        return Apache::LiveJournal::redir($r, $url, HTTP_MOVED_TEMPORARILY);
+        return Apache::LiveJournal::redir($url, HTTP_MOVED_TEMPORARILY);
     }
 
     # handle vertical URLs
-    my $args = $r->args;
+    my $args = LJ::Request->args;
     my $full_uri = $uri;
     $full_uri .= "?$args" if $args;
     if (my $v = LJ::Vertical->load_by_url($full_uri)) {
         if ($v->is_canonical_url($full_uri)) {
             my $args_for_redir = $args ? "?$args" : '';
-            return Apache::LiveJournal::redir($r, $v->url . $args_for_redir);
+            return Apache::LiveJournal::redir($v->url . $args_for_redir);
         } else {
-            return LJ::URI->bml_handler($r, "explore/index.bml");
+            return LJ::URI->bml_handler("explore/index.bml");
         }
     }
 
     if (my $c = LJ::Browse->load_by_url($full_uri)) {
-        return LJ::URI->bml_handler($r, "browse/index.bml");
+        return LJ::URI->bml_handler("browse/index.bml");
     }
 
     if ($uri =~ m!^/statistics(/.*|$)! or $uri =~ m!^/ratings(/.*|$)!) {
-        return LJ::URI->bml_handler($r, "statistics/index.bml");
+        return LJ::URI->bml_handler("statistics/index.bml");
     }
 
     return undef;

Tags: livejournal, pm, vadvs
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