vadvs (vadvs) wrote in changelog,
vadvs
vadvs
changelog

[livejournal] r16209: LJSUP-5445: added die with stack backtra...

Committer: vsukhanov
LJSUP-5445: added die with stack backtrace when called uninitialized LJ::Request.
U   trunk/cgi-bin/Apache/DebateSuicide.pm
U   trunk/cgi-bin/Apache/SendStats.pm
U   trunk/cgi-bin/LJ/Request/Apache.pm
Modified: trunk/cgi-bin/Apache/DebateSuicide.pm
===================================================================
--- trunk/cgi-bin/Apache/DebateSuicide.pm	2010-02-05 07:24:25 UTC (rev 16208)
+++ trunk/cgi-bin/Apache/DebateSuicide.pm	2010-02-05 08:14:11 UTC (rev 16209)
@@ -15,7 +15,9 @@
 # oh btw, this is totally linux-specific.  gtop didn't work, so so much for portability.
 sub handler
 {
-    #my $r = shift;
+    my $r = shift;
+    LJ::Request->init($r) unless LJ::Request->is_inited;
+    
     return LJ::Request::OK if LJ::Request->main;
     return LJ::Request::OK unless $LJ::SUICIDE && LJ::ModuleCheck->have("GTop");
 

Modified: trunk/cgi-bin/Apache/SendStats.pm
===================================================================
--- trunk/cgi-bin/Apache/SendStats.pm	2010-02-05 07:24:25 UTC (rev 16208)
+++ trunk/cgi-bin/Apache/SendStats.pm	2010-02-05 08:14:11 UTC (rev 16209)
@@ -15,6 +15,9 @@
 
 sub handler
 {
+    my $r = shift;
+    LJ::Request->init($r) unless LJ::Request->is_inited;
+
     return LJ::Request::OK if LJ::Request->main;
     return LJ::Request::OK unless $LJ::HAVE_AVAIL && $LJ::FREECHILDREN_BCAST;
 

Modified: trunk/cgi-bin/LJ/Request/Apache.pm
===================================================================
--- trunk/cgi-bin/LJ/Request/Apache.pm	2010-02-05 07:24:25 UTC (rev 16208)
+++ trunk/cgi-bin/LJ/Request/Apache.pm	2010-02-05 08:14:11 UTC (rev 16209)
@@ -23,27 +23,23 @@
 
 
 
-
-
-
 require Apache::Request;
 require Apache::URI;
 
 my $instance = '';
+
+sub _die_if_no_request {
+    Carp::confess("Request is not provided to LJ::Request") unless $instance;
+}
+
 sub LJ::Request::request { $instance }
 sub LJ::Request::r {
-    Carp::confess("Request is not provided to LJ::Request") unless $instance;
+    _die_if_no_request();
     return $instance->{r};
 }
 
 
-sub LJ::Request::instance {
-    my $class = shift;
-    die "use 'request' instead";
-#    return $instance ? $instance : undef;
-}
-
-
+sub LJ::Request::instance { Carp::confess("use 'request' instead") }
 sub LJ::Request::init {
     my $class = shift;
     my $r     = shift;
@@ -66,95 +62,103 @@
 
 sub LJ::Request::set_last_modified {
     my $class = shift;
-    die "Request is not provided to LJ::Request" unless $instance;
+    _die_if_no_request();
     return $instance->{apr}->set_last_modified(@_);
 }
 
 sub LJ::Request::request_time {
     my $class = shift;
-    die "Request is not provided to LJ::Request" unless $instance;
+    _die_if_no_request();
     return $instance->{apr}->request_time();
 }
 
 sub LJ::Request::meets_conditions {
     my $class = shift;
-    die "Request is not provided to LJ::Request" unless $instance;
+    _die_if_no_request();
     return $instance->{apr}->meets_conditions();
 }
 
 sub LJ::Request::read {
     my $class = shift;
-    die "Request is not provided to LJ::Request" unless $instance;
+    _die_if_no_request();
     return $instance->{apr}->read(@_);
 }
 
 sub LJ::Request::is_main {
     my $class = shift;
-    die "Request is not provided to LJ::Request" unless $instance;
+    _die_if_no_request();
     return $instance->{r}->is_main(@_);
 }
 
 sub LJ::Request::main {
     my $class = shift;
-    die "Request is not provided to LJ::Request" unless $instance;
+    _die_if_no_request();
     return $instance->{r}->main(@_);
 }
 
 sub LJ::Request::dir_config {
     my $class = shift;
-    die "Request is not provided to LJ::Request" unless $instance;
+    _die_if_no_request();
     return $instance->{apr}->dir_config(@_);
 }
 
 sub LJ::Request::header_only {
     my $class = shift;
-    die "Request is not provided to LJ::Request" unless $instance;
+    _die_if_no_request();
     return $instance->{apr}->header_only;
 }
 
 sub LJ::Request::content_languages {
     my $class = shift;
-    die "Request is not provided to LJ::Request" unless $instance;
+    _die_if_no_request();
     return $instance->{apr}->content_languages(@_);
 }
 
 sub LJ::Request::register_cleanup {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{apr}->register_cleanup(@_);
 }
 
 sub LJ::Request::path_info {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{apr}->path_info(@_);
 }
 
 sub LJ::Request::args {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{apr}->args(@_);
 }
 
 sub LJ::Request::method {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->method;
 }
 
 sub LJ::Request::bytes_sent {
     my $class = shift;
+    _die_if_no_request();
     $instance->{r}->bytes_sent(@_);
 }
 
 sub LJ::Request::document_root {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->document_root;
 }
 
 sub LJ::Request::finfo {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->finfo;
 }
 
 sub LJ::Request::filename {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->filename(@_);
 }
 
@@ -165,6 +169,7 @@
 
 sub LJ::Request::is_initial_req {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->is_initial_req(@_);
 }
 
@@ -175,31 +180,37 @@
 
 sub LJ::Request::push_handlers {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{r}->push_handlers(@_);
 }
 
 sub LJ::Request::set_handlers {
     my $class = shift;
+    _die_if_no_request();
     $instance->{r}->set_handlers(@_);
 }
 
 sub LJ::Request::handler {
     my $class = shift;
+    _die_if_no_request();
     $instance->{r}->handler(@_);
 }
 
 sub LJ::Request::method_number {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{r}->method_number(@_);
 }
 
 sub LJ::Request::status {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{r}->status(@_);
 }
 
 sub LJ::Request::status_line {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{r}->status_line(@_);
 }
 
@@ -214,97 +225,116 @@
 
 sub LJ::Request::notes {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->notes (@_);
 }
 
 sub LJ::Request::pnotes {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->pnotes (@_);
 }
 
 sub LJ::Request::parse {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->parse (@_);
 }
 
 sub LJ::Request::uri {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->uri (@_);
 }
 
 sub LJ::Request::hostname {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->hostname (@_);
 }
 
 sub LJ::Request::header_out {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->header_out (@_);
 }
 
 sub LJ::Request::headers_out {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->headers_out (@_);
 }
 
 sub LJ::Request::header_in {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->header_in (@_);
 }
 
 sub LJ::Request::headers_in {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->headers_in (@_);
 }
 
 sub LJ::Request::param {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->param (@_);
 }
 
 sub LJ::Request::no_cache {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->no_cache (@_);
 }
 
 sub LJ::Request::content_type {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->content_type (@_);
 }
 
 sub LJ::Request::pool {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->pool;
 }
 
 sub LJ::Request::connection {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->connection;
 }
 
 sub LJ::Request::output_filters {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->output_filters;
 }
 
 sub LJ::Request::print {
     my $class = shift;
+    _die_if_no_request();
     $instance->{r}->print (@_);
 }
 
 sub LJ::Request::content_encoding {
     my $class = shift;
+    _die_if_no_request();
     $instance->{r}->content_encoding(@_);
 }
 
 sub LJ::Request::send_http_header {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->send_http_header (@_)
 }
 
 
 sub LJ::Request::err_headers_out {
     my $class = shift;
+    _die_if_no_request();
     $instance->{apr}->err_headers_out (@_)
 }
 
@@ -316,12 +346,14 @@
 # TODO: do we need this and 'args' methods? they are much the same.
 sub LJ::Request::get_params {
     my $class = shift;
+    _die_if_no_request();
     my @params = $instance->{r}->args;
     return @params;
 }
 
 sub LJ::Request::post_params {
     my $class = shift;
+    _die_if_no_request();
 
     ## $r->content
     ## The $r->content method will return the entity body read from the client,
@@ -342,6 +374,8 @@
     my $header = shift;
     my $value  = shift;
 
+    _die_if_no_request();
+    
     $instance->{r}->err_headers_out->add($header, $value);
     $instance->{r}->headers_out->add($header, $value);
 
@@ -354,6 +388,8 @@
     my $header = shift;
     my $value  = shift;
 
+    _die_if_no_request();
+
     $instance->{r}->err_header_out($header, $value);
     $instance->{r}->header_out($header, $value);
 
@@ -363,31 +399,39 @@
 sub LJ::Request::unset_headers_in {
     my $class = shift;
     my $header = shift;
+    
+    _die_if_no_request();
+    
     $instance->{r}->headers_in->unset($header);
 }
 
 sub LJ::Request::log_error {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{r}->log_error(@_);
 }
 
 sub LJ::Request::remote_ip {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{r}->connection()->remote_ip(@_);
 }
 
 sub LJ::Request::remote_host {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{r}->connection()->remote_host;
 }
 
 sub LJ::Request::user {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{r}->connection()->user;
 }
 
 sub LJ::Request::aborted {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{r}->connection()->aborted;
 }
 
@@ -397,6 +441,7 @@
     my $filename = shift;
     my $fh       = shift;
 
+    _die_if_no_request();
     $instance->{r}->send_fd($fh);
     $fh->close();
 
@@ -404,16 +449,19 @@
 
 sub LJ::Request::parsed_uri {
     my $class = shift;
+    _die_if_no_request();
     $instance->{r}->parsed_uri; # Apache::URI
 }
 
 sub LJ::Request::current_callback {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{r}->current_callback;
 }
 
 sub LJ::Request::child_terminate {
     my $class = shift;
+    _die_if_no_request();
     return $instance->{r}->child_terminate;
 }
 

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