stas        2004/05/03 23:05:17

  Added:       xs/APR/Error APR__Error.h Error_pm
  Log:
  the perl interface for the new exception handling code
  
  Revision  Changes    Path
  1.1                  modperl-2.0/xs/APR/Error/APR__Error.h
  
  Index: APR__Error.h
  ===================================================================
  /* Copyright 2002-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  #define mpxs_APR__Error_strerror(rc) modperl_error_strerror(aTHX_ rc)
  
  
  
  
  1.1                  modperl-2.0/xs/APR/Error/Error_pm
  
  Index: Error_pm
  ===================================================================
  require Carp;
  require Carp::Heavy;
  
  use APR::Util ();
  
  use overload
      nomethod => \&fatal,
      'bool'   => \&str,
      '=='     => \&num,
      '0+'     => \&num,
      '""'     => \&str;
  
  sub fatal {  die __PACKAGE__ . ": Can't handle '$_[3]'" }
  
  # normally the object is created on the C side, but if you want to
  # create one from Perl, you can. just pass a hash with args:
  # rc, file, line, func
  sub new {
      my $class = shift;
      my %args = @_;
      bless \%args, $class;
  }
  
  sub str {
      sprintf "%s: %s at %s line %d", $_[0]->{func},
          APR::Error::strerror($_[0]->{rc}),
          $_[0]->{file}, $_[0]->{line};
  }
  
  sub num { $_[0]->{rc} }
  
  # skip the wrappers from this package from the long callers trace
  $Carp::CarpInternal{+__PACKAGE__}++;
  
  # XXX: Carp::(confess|cluck) see no calls stack when Perl_croak is
  # called with Nullch (which is the way execption objects are
  # returned), so we fixup it here (doesn't quite work for croak
  # caller).
  sub cluck {
      if (ref $_[0] eq __PACKAGE__) {
          Carp::cluck("$_[0]->{func}: " .
                      APR::Error::strerror($_[0]->{rc}));
      }
      else {
          &Carp::cluck;
      }
  }
  
  sub confess {
      if (ref $_[0] eq __PACKAGE__) {
          Carp::confess("$_[0]->{func}: " .
                      APR::Error::strerror($_[0]->{rc}));
      }
      else {
          &Carp::confess;
      }
  }
  
  1;
  __END__
  
  
  

Reply via email to