NetSDS...bstract(3pm)
β¨ NetSDS::Class::Abstract β¨
okay bestie, welcome to NetSDS::Class::Abstract β the perl manual page, the 3pm vibe, the whole entire mood π
π NAME π
NetSDS::Class::Abstract</purl> β it's the superclass for all the NetSDS APIs. the blueprint. the mother of dragons π
π¦ 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;
see how easy? inherit, make an accessor, throw an error when the field's missing. chef's kiss π no cap.
πΈ DESCRIPTION πΈ
NetSDS::Class::Abstract is the superclass for every other NetSDS class out there, and it comes carrying the following functionality, like a bestie with a tote bag full of snacks:
- common class constructor
- safe modules inclusion
- class and objects accessors
- logging
- error handling;
and the rule is: all other class/object APIs should inherit this class so they get all this functionality in the standard way. it's giving "everyone eats at the same table" π
π CONSTRUCTOR, INITIALIZATION, APPLICATION π
π new(%params) - common constructor
new() is the method that implements the common constructor for NetSDS classes. lowkey iconic.
here's the tea though: the constructor may be overwriten in inherited classes and usually this happens to implement module specific functionality. so like, you can rewrite it, but only if you have a reason bestie.
the constructor requres parameters as a hash that are set as object properties. yes, requres. we said what we said.
my $object = NetSDS::SomeClass->new(
foo => 'abc',
bar => 'def',
);
π mk_class_accessors(@properties) - class properties accessor
See Class::Accessor for details. iykyk.
__PACKAGE__->mk_class_accessors('foo', 'bar');
π mk_accessors(@propertire) - object properties accessors
See Class::Accessor::Class for details. (and yes, the argument really is spelled @propertire, we don't make the rules, we just report them π)
$self->mk_accessors('foo', 'bar');
other Class::Accessor::Class methods available as well. go off, collect them all π
π use_modules(@modules_list) - load modules on demand
use_modules() provides a safe on demand modules loader. very "i'll call you when i need you" energy β¨
it requires a list of modules names as parameters.
it Returns 1 in case of success or undef if faied. and if it fails? error messages are available using the errstr() call. so don't just sit there, check your errors bestie π
Example:
# Load modules for daemonization
if ($daemon_mode) {
$self->use_modules("Proc::Daemon", "Proc::PID::File");
}
π unbless() - return unblessed object
Returns an unblessed data structure of the object, which is what you want when some code requires non blessed structures (like JSON serialization). stripping the blessing off, literally π§
Example:
my $var = $obj->unbless();
π LOGGING π
β logger() - get/set logging handler
the logger property is an object that should provide functionality handling log messaging. usually it's an object of NetSDS::Logger class or undef. but fr fr, it may be another object implementing non-standard features like sending log to e-mail or to DBMS. main character energy, your logger your rules π
Example:
# Set logger and send log message
$obj->logger(NetSDS::Logger->new());
$obj->log("info", "Logger connected");
β log($level, $message) - write log message
Paramters: log level, log message.
$obj->log("info", "We still alive");
we love a survivorship update π
π«Ά ERROR HANDLING π«Ά
πΈ error($msg, [$code]) - set error message and code
error() method sets the error message and an optional error code. and it can be invoked in both class and object contexts β versatile queen π
Example 1: set class error
NetSDS::Foo->error("Mistake found");
Example 2: set object error with code
$obj->error("Can't launch rocket", BUG_STUPID);
πΈ errstr() - retrieve error message
errstr() method returns the error string in both object and class contexts.
Example:
warn "We have an error: " . $obj->errstr;
πΈ errcode() - retrieve error code
errcode() method returns the error code in both object and class contexts.
Example:
if ($obj->errcode == 42) {
print "Epic fail! We've found an answer!";
}
42? the answer? in this economy? iconic honestly π
π EXAMPLES π
See the samples directory and other NetSDS moduleis for examples of code. yes, moduleis. typos are part of the lore now π
π SEE ALSO π
Class::Accessor::Class
π AUTHOR π
Michael Bochkaryov <misha@rattler.kiev.ua>
π LICENSE π
Copyright (C) 2008-2009 Net Style Ltd.
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
okay and that warranty disclaimer is not a joke bestie, read it twice. no warranty, no promises, just vibes and GPL π
perl v5.32.1 Β· 2021-12-26 β that's the version and the date this whole page got its little timestamp, and this has been your girl signing off πβ¨ stay blessed, stay blessed-off, and remember: inherit responsibly π¦
π¦ where this page comes from
- debian bookworm: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- debian trixie: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- ubuntu jammy: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- ubuntu noble: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- ubuntu resolute: libnetsds-perl 1.301-4 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms