ACME::Error - Never have boring errors again!


ACME-Error documentation Contained in the ACME-Error distribution.

Index


Code Index:

NAME

Top

ACME::Error - Never have boring errors again!

SYNOPSIS

Top

  use ACME::Error SHOUT;

  warn "Warning"; # WARNING!

DESCRIPTION

Top

ACME::Error is a front end to Perl error styles. $SIG{__WARN__} and $SIG{__DIE__} are intercepted. Backends are pluggable. Choose a backend by specifying it when you use ACME::Error SomeStyle;

Writing Backends

Writing backends is easy. See ACME::Error::SHOUT for a simple example. Basically your backend needs to be in the ACME::Error namespace and defines just two subroutines, warn_handler and die_handler. The arguments passed to your subroutine are the same as those passed to the signal handlers, see perlvar for more info on that. You are expected to return what you want to be warned or died.

You can also run use an import function. All arguments passed to ACME::Error after the style to use will be passed to the backend.

AUTHOR

Top

Casey West <casey@geeknest.com>

COPYRIGHT

Top

SEE ALSO

Top

perl(1).


ACME-Error documentation Contained in the ACME-Error distribution.

package ACME::Error;

use strict;

use vars qw[$VERSION];
$VERSION = '0.03';

sub import {
  my $class = shift;
  if ( my $style = shift ) {
    my $package = qq[ACME::Error::$style];
    my $args    = join q[', '], @_;
    eval qq[use $package '$args'];
    die $@ if $@;
    
    my $nested = -1;

    { no strict 'refs';
      $SIG{__WARN__} = sub {
        local $SIG{__WARN__};
        $nested++;
        my $handler = $package . q[::warn_handler];
        warn &{$handler}(@_) unless $nested;
        warn @_ if $nested;
        $nested--;
      };

      $SIG{__DIE__}  = sub {
        local $SIG{__DIE__};
        $nested++;
        my $handler = $package . q[::die_handler];
        die &{$handler}(@_) unless $nested;
        die @_ if $nested;
        $nested--;
      };
    }

#    $SIG{__WARN__} = sub {
#      my $handler = $package . q[::warn_handler];
#      {
#       no strict 'refs';
#       warn &{$handler} , "\n" if exists &{$handler};
#      }
#    };

#    $SIG{__DIE__}  = sub {
#      my $handler = $package . q[::die_handler];
#      {
#       no strict 'refs';
#       die &{$handler}, "\n" if exists &{$handler};
#      }
#    };
  }
}

1;
__END__