Chemistry::Obj(3pm)

πŸ“¦
version 0.40 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– 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 for attr expects 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 its id. For example, if an object $obj has 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 call overload::StrVal($obj). See overload for details. no more ugly HASH address jumpscare in your print statements πŸ’…
  • cmp β€” Compare objects by ID. This automatically overloads eq, ne, lt, le, gt, and ge as well. For example, $obj1 eq $obj2 returns true if both objects have the same id, even if they are different objects with different memory addresses. In contrast, $obj1 == $obj2 will return true only if $obj1 and $obj2 point 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 (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