title: Close response under mod_perl 2
body: <p>I'm trying to find out if there's a way to complete a response under mod_perl 2 without returning to the main handler. Haven't been able to find a method for that in the docs so far. The following is an example of what I'm trying to achieve:</p>
  
  <pre><code>#!/usr/bin/perl
  # This is some mod_perl handler
  use strict;
  use warnings;
  use Apache2::Const ':common';
  
  sub handler {
      my $r = shift;
      if ($r-&gt;method eq 'POST') {
          # just to do something as example
          do_post_response($r);
      }
      $r-&gt;content_type('text/plain');
      print "Thank you, goodbye.";
      return Apache2::Const::OK;
  }
  
  sub do_post_response {
      my $r = shift;
      unless (check_somthing()) {
          # Suppose I find a situation that requires
          # a different response than normal...
          $r-&gt;content_type('text/plain');
          print "We have a situation...";
          $r-&gt;something_to_finish_the_request_immediatly(Apache2::Const::OK);
      }
  }
  </code></pre>
  
  <p>In a regular Perl script, running as stand alone or under mod_cgi, I could just <code>exit()</code> with the new response, but under <code>mod_perl</code> I need to return something in the original <code>handler</code>subroutine. This is leading me to keep track of a whole chain of calls where all of them have to return something until I get back to the main <code>handler</code>.</p>
  
  <p>For example, instead of:</p>
  
  <pre><code>unless (check_something()) { ...
  </code></pre>
  
  <p>I need to do things like:</p>
  
  <pre><code>my $check = check_something();
  return $check if $check;
  </code></pre>
  
  <p>and I also have to do something similar in the main handler, which is quite ungly for some situation handlings.</p>
  
  <p>Is there a way to close the request when inside a nested call, just like what I tried to illustrate with my example?</p>
  
  <p><strong>EDIT:</strong> I've found that I can call a <code>goto LABEL</code> and place that label just before the last return in the main <code>handler</code>subroutine. It works, but still feels like a dirty hack. I really hope there's a nicer way.</p>