Class::Error

Class::Error offers delayed checking of object failure.
Download

Class::Error Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Domizio Demichelis
  • Publisher web site:
  • http://search.cpan.org/~domizio/CGI-Application-Plus-1.21/lib/CGI/Application/CheckRM.pm

Class::Error Tags


Class::Error Description

Class::Error offers delayed checking of object failure. Class::Error offers delayed checking of object failure.SYNOPSIS package My::Package ; use Class::Error ; $undef_obj = Class::Error->new($error, $errnum) $undef_obj->any_method ; # won't 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 ; # won't 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 warningsYou 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 # staticFor 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 "Can't 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() }; Requirements: · Perl version >= 5.6.1


Class::Error Related Software