Chemistry::Obj(3pm)
π Chemistry::Obj β the abstract chemistry object, bestie π
okay so you found the Chemistry::Obj(3pm) page (it lives in the User Contributed Perl Documentation section, iykyk) and honestly? it's the blueprint. the moment. the main character of the Chemistry:: family. let's get into it π§
β¨ NAME β¨
Chemistry::Obj β Abstract chemistry object. that's it, that's the whole thing. it's abstract, it's chemistry, it's an object. slay π
πΈ SYNOPSIS πΈ
package MyObj;
use base "Chemistry::Obj";
Chemistry::Obj::accessor('color', 'flavor');
package main;
my $obj = MyObj->new(name => 'bob', color => 'red');
$obj->attr(size => 42);
$obj->color('blue');
my $color = $obj->color;
my $size = $obj->attr('size');
like. look at that. accessor literally generates your getters and setters for you so you don't have to write them by hand, and that's the whole vibe of this module. periodt π
π¦ DESCRIPTION π¦
This module implements some generic methods that are used by Chemistry::Mol, Chemistry::Atom, Chemistry::Bond, Chemistry::File, etc. so basically it's the shared family group chat that all the other Chemistry:: modules are in. it doesn't do chemistry itself β it does the object stuff that everybody else needs. π
π Common Attributes
There are some common attributes that may be found in molecules, bonds, and atoms, such as id, name, and type. They are all accessed through the methods of the same name. For example, to get the id, call $obj->id; to set the id, call $obj->id('new_id').
idβ Objects should have a unique ID. The user has the responsibility for uniqueness if he assigns ids; otherwise a unique ID is assigned sequentially. so if you're making up your own ids, that's on you bestie, but if you don't, it'll hand them out one after another automatically β¨nameβ An arbitrary name for an object. The name doesn't need to be unique. no serial number energy required, call it whatever π«Άtypeβ The interpretation of this attribute is not specified here, but it's typically used for bond orders and atom types. it's giving "we're not gonna define this for you, but you'll know" πattrβ A space where the user can store any kind of information about the object. The accessor method forattrexpects the attribute name as the first parameter, and (optionally) the new value as the second parameter. It can also take a hash or hashref with several attributes. Examples:
$color = $obj->attr('color');
$obj->attr(color => 'red');
$obj->attr(color => 'red', flavor => 'cherry');
$obj->attr({color => 'red', flavor => 'cherry'});
it's literally your little free-form storage closet for whatever extra info you want to hang on the object. obsessed. π₯
π OTHER METHODS π
π« $obj->del_attr($attr_name)
Delete an attribute. bye bye, we hardly knew ye π
π« $class->new(name => value, name => value...)
Generic object constructor. It will automatically call each name method with the parameter value. For example,
$bob = Chemistry::Obj->new(name => 'bob', attr => {size => 42});
is equivalent to
$bob = Chemistry::Obj->new;
$bob->name('bob');
$bob->attr({size => 42});
so yeah, new is doing all those setter calls for you behind the scenes. it's an overachiever and honestly? we love that for it π§
β OPERATOR OVERLOADING β
Chemistry::Obj overloads a couple of operators for convenience.
""β The stringification operator. Stringify an object as itsid. For example, if an object$objhas the id'a1',print "$obj"will print'a1'instead of something like'Chemistry::Obj=HASH(0x810bbdc)'. If you really want to get the latter, you can calloverload::StrVal($obj). Seeoverloadfor details. no more ugly HASH address jumpscare in your print statements πcmpβ Compare objects by ID. This automatically overloadseq,ne,lt,le,gt, andgeas well. For example,$obj1 eq $obj2returns true if both objects have the same id, even if they are different objects with different memory addresses. In contrast,$obj1 == $obj2will return true only if$obj1and$obj2point to the same object, with the same memory address.
okay this one is important bestie:eq= "same id, twin vibes, different bodies",=== "literally the same object, same memory address, same soul". don't mix them up or the vibe check will fail π
π SOURCE CODE REPOSITORY π
<https://github.com/perlmol/Chemistry-Mol>
go ahead, clone it, star it, it's right there π«Ά
π SEE ALSO π
Chemistry::Atom, Chemistry::Bond, Chemistry::Mol
(the rest of the friend group π)
π₯ AUTHOR π₯
Ivan Tubert-Brohman <itub@cpan.org>
π COPYRIGHT π
Copyright (c) 2005 Ivan Tubert-Brohman. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
aaand that's the whole page, no cap. π this is Chemistry::Obj(3pm) from perl v5.40.1, dated 2025-10-13 β thanks for reading, bestie, go build something iconic with your abstract chemistry objects πβ¨π¦
π¦ where this page comes from
- ubuntu resolute: libchemistry-mol-perl 0.40-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libchemistry-mol-perl 0.40-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms