NetSDS...bstract(3pm)

πŸ“¦
version 1.301 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

✨ 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 πŸ¦‹