GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  CLASS::ERROR (3)

.ds Aq ’

NAME

Class::Error - Delayed checking of object failure

CONTENTS

VERSION 2.21

Included in OOTools 2.21 distribution.

The latest versions changes are reported in the Changes file in this distribution.

The distribution includes:
o Class::constr

Pragma to implement constructor methods

o Class::props

Pragma to implement lvalue accessors with options

o Class::groups

Pragma to implement groups of properties accessors with options

o Class::Error

Delayed checking of object failure

o Object::props

Pragma to implement lvalue accessors with options

o Object::groups

Pragma to implement groups of properties accessors with options

o Class::Util

Class utility functions

INSTALLATION

Prerequisites


    Perl version >= 5.6.1



CPAN


    perl -MCPAN -e install OOTools



Standard installation From the directory where this file is located, type:



    perl Makefile.PL
    make
    make test
    make install



SYNOPSIS



  package My::Package ;

  use Class::Error ;

  $undef_obj = Class::Error->new($error, $errnum)

  $undef_obj->any_method ;              # wont die and will return $undef_obj
  print is false unless $undef_obj ;  # is false
  print "$undef_obj" ;                  #  with warning "Use of uninitialized
                                        # value in string..."
  print $undef_obj->any_method ;        #  with same warning

  $empty_obj = Class::Error->new($error, $errnum, )

  $empty_obj->any_method ;              # wont die and will return $empty_obj
  print is false unless $empty_obj ;  # is false
  print "$empty_obj" ;                  #  no warnings
  print $empty_obj->any_method ;        #  no warnings



DESCRIPTION

You can use this module to return a Class::Error object instead of a simple false value (e.g. when a sub or a property may return an object OR the undef value on failure).

That feature allows to check on the object itself, or delay the checking after calling any method on the object.



   $obj = AnyClass->new or die $obj->error
   AnyClass->new->any_method or die Class::Error->error  # static



For example, compare the difference between the behaviour of obj_A and obj_B if the AnyClass->new would return false:



   use Object::props
     ( { name    => obj_A,
         default => sub{ AnyClass->new or undef }
       },
       { name    => obj_B,
         default => sub{ AnyClass->new
                         or Class::Error->new(AnyClass->new failed) }
       }
     );

   # if AnyClass->new would fail (returning a false value)

   # this would die "Cant call method "any_method" on an undefined value..."
   $s->obj_A->any_method or do{ warn doing something else...;
                                do_something_else()
                              };
   # but this would execute the do{} block
   $s->obj_B->any_method or do{ warn doing something else...;
                                do_something_else()
                              };



METHODS

    AUTOLOAD

All the methods called on the Class::Error object (regardless the arguments) return a reference to the object itself, thus allowing you to call methods on methods:



   $error_obj->any_method(a, b)->any_other_method...



METHODS

    new ([ error [, errnum [, false]]] )



   $undef_obj = Class::Error->new($error, $errnum)       # undef
   $empty_obj = Class::Error->new($error, $errnum, )   # empty
   $zero_obj  = Class::Error->new($error, $errnum, 0)    # 0



The constructor accepts 3 optional arguments and returns a Class::Error object.

error sets the error, which could be a simple string or any other value (also stored in $Class::Error::error), errnum sets the error number (also stored in $Class::Error::errnum) which you can retrieve with the error and errnum static or dynamic methods.

You can also pass a third argument (which must be false) to the new method or leave it undef: the scalar reference to the false argument will be used as the object value in any contexts (internally using overload).

For example, if you leave the false argument as undef, the Class::Error object itself is evaluated as undef in any contexts (e.g. false in boolean context like the undef value), but unlike the undef value, it is defined and allows you to call any methods on it.

<B>NoteB>: If you want to avoid the use of uninitialized value... warning when you use the object itself (or the result of its methods) in string context, you can pass an empty string to the constructor, or the 0 value for numeric context. Use that feature only if you know what you are doing, since a defined false value might make more difficult the debgging of real errors.

    error

Returns the last error string passed to the new() method:



   AnyClass->new->any_method or die Class::Error->error  # static
   $result = AnyClass->new->any_method or die $result->error
   $obj = AnyClass->new or die $obj->error



    errnum

Returns the last error number passed to the new() method:



   if ( Class::Error->errnum == 230 ) { .... }  # static
   if ( $obj->errnum == 230 ) { .... }



SUPPORT and FEEDBACK

If you need support or if you want just to send me some feedback or request, please use this link: http://perl.4pro.net/?Class::Error.

AUTHOR and COPYRIGHT

X 2004-2005 by Domizio Demichelis.

All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as perl itself.

POD ERRORS

Hey! <B>The above document had some coding errors, which are explained below:B>
Around line 221: Non-ASCII character seen before =encoding in ’X’. Assuming ISO8859-1
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 CLASS::ERROR (3) 2012-03-05

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.