Julian Lishev > Errors-1.02 > Errors::Errors

Download:
Errors-1.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.02   Source  

NAME ^

 Errors.pm - Full featured error management module

DESCRIPTION ^

Error module is created as base "error" catcher module especially for Web

SYNOPSIS ^

 use Errors::Errors;
 
 use strict;

 my $obj = Errors::Errors->new();
 
 $obj->content(0);
 $obj->header();

 $obj->attach('xreader');  # Attach sub object (sobject) for error of type 'xreader'.
 $obj->attach('myown');    # Attach sub object for error of type 'myown'.
 
 my $hash = {
             name=>'July',
             born_year=>'81',
            };
 
 $obj->attach_object('xreader',$hash); # Hash ref or object
 
 $obj->install('onTerm',\&custom);            # Install sub for term event.
 $obj->install('onError',\&anysub,'xreader'); # Install sub for xreader sobject which will be called when error occure.
 $obj->install('onExit',\&leave);             # Install sub for exit event.
 $obj->install('onTerm',\&custom,'myown');    # Install additional term sub for 'myown' sobject.
 
 $obj->error(7,'xreader');  # Set error '7' for 'xreader' sobject and force execution of error chain.
 
 #my $h = $obj->fetch_object('xreader');  # Fetch attached object from xreader.
 #$obj->print($h->{name}."\n");
 
 $obj->uninstall('onError','xreader');  # Remove 'xreader' sub from 'error' chain.
 
 $obj->detach_object('xreader'); # Remove attached object from xreader.
 $obj->detach('xreader'); # Remove xreader (and attached objects).
 
 $obj->install('onTimeOut',\&timeout); # Install timeout sub routine.
 eval 'alarm(1);';    # Force alarm after 1s
 sleep(2);            # Wait 2 sec, so alarm will be activeted and 'timeout' chain will be turned.
 #Note: Press CTRL+C to active 'INT' signal ('onTerm' event) before time to flow out.
 
 #$obj->exit();       # Force exit of program.
 #$obj->die();        # Force die of program.
 
 #By default script close 'normally', so 'destroy' chain will be executed.

 sub custom {
  my $obj   = shift;         # 'Errors' object
  my %in    = @_;
  my $type  = $in{'type'};   # Error type: 'term'
  my $name  = $in{'name'};   # Custom error name
  my $sig   = $in{'signal'}; # Invoked signal (term,quit,pipe...)
  # ...blah...blah...
  print "Custom($name)\n";
 }
 sub leave {
  my $obj    = shift;
  my %in     = @_;
  my $type   = $in{'type'};   # Error type: 'exit','die','destroy'
  my $err    = $in{'error'};  # Error value
  my $name   = $in{'name'};   # Custom error name
  my $params = $in{'params'}; # Additional parameters (ref to @)
  my @params = @$params;
  # ...blah...blah...
  print "$type\n";
 }
 sub timeout
 {
  my $obj   = shift;
  my %in    = @_;
  my $type  = $in{'type'};    # Error type: 'term'
  my $name  = $in{'name'};    # Custom error name
  my $sig   = $in{'signal'};  # Invoked signal: 'alrm'
  # ...blah...blah...
  print "Timeout\n";
 }
 sub anysub {
  my $obj    = shift;
  my %in     = @_;
  my $type   = $in{'type'};   # Error type: 'error'
  my $err    = $in{'error'};  # Error message
  my $name   = $in{'name'};   # Custom error name
  my $to     = $in{'to'};     # Message is sent "to"
  my $params = $in{'params'}; # Additional parameters (ref to @)
  my @params = @$params;
  
  
  if($name eq $to && $to eq 'xreader')
   {
    $obj->print ("Error in Xreader!!!\n");  # If error is raised in 'xreader'
    my $h = $obj->fetch_object('xreader');
    $obj->print ($h->{born_year}."\n");
   }
  else
   {
    $obj->print ("Error in ... I don't know ;-)!!!\n");
   }
 }

AUTHOR ^

 Julian Lishev - Bulgaria,Sofia
 e-mail: julian@proscriptum.com

 Copyright (c) 2001, Julian Lishev, Sofia 2003
 All rights reserved.
syntax highlighting: