NAME

NetSDS::Class::Abstract - superclass for all NetSDS APIs

SYNOPSIS

package MyClass;
use base 'NetSDS::Class::Abstract';

__PACKAGE__->mk_accessors(qw/my_field/);

sub error_sub {
	my ($self) = @_;
	if (!$self->my_field) {
		return $self->error("No my_field defined");
	}
}

1;

DESCRIPTION

NetSDS::Class::Abstract is a superclass for all other NetSDS classes, containing the following functionality:

  • common class constructor

  • safe modules inclusion

  • class and objects accessors and cloning;

  • error handling;

All other class/object APIs should inherit this class to use it's functionality in standard way.

CONSTRUCTOR, INITIALIZATION, APPLICATION

new([...])

Common constructor for NetSDS classes.

my $object = NetSDS::SomeClass->new(%options);

Constructor may be overwriten in inherited classes and usually is. Parameters for constructor may be given as hash or hash reference.

mk_class_var(@variables)
Class->mk_class_var(@variables);

This creates accessor/mutator methods for each named class variable.

use_modules(ARRAY)

Invoke modules from list given in parameters.

Return TRUE in case of success or FALSE if failed.

unbless()

Return non object copy of object data structure.

$copy = $obj->unbless();
$same = $obj->unbless( 1 );
serialize() - returns serialized object

This method returns serialized copy of object.

deserialize($serialized) - returns deserialized object

Paramters: serialized object as string

Returns: object

my $obj = NetSDS::SomeClass->deserialize($str);
nstore($file_name) - store serialized object

Save serialized object to file

logger() - set logger handler

This method allows to set class logger (NetSDS::Logger object)

log($level, $message) - write log message

Paramters: log level, log message

$obj->log("info", "We still alive");
error_code($new_code) - set/get error code
if (error_occured()) {

	$self->error_code(1234); # secret error status
	return $self->error("Oops! We have a 1234 error!");

}

EXAMPLES

See samples directory and other NetSDS moduleis for examples of code.

SEE ALSO

Class::Accessor, Class::Accessor::Class, Clone, Class::ErrorHandler

AUTHOR

Michael Bochkaryov <misha@rattler.kiev.ua>

LICENSE

Copyright (C) 2008-2009 Michael Bochkaryov

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA