.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Chemistry::Obj 3pm" .TH Chemistry::Obj 3pm "2022-07-14" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Chemistry::Obj \- Abstract chemistry object .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& package MyObj; \& use base "Chemistry::Obj"; \& Chemistry::Obj::accessor(\*(Aqcolor\*(Aq, \*(Aqflavor\*(Aq); \& \& package main; \& my $obj = MyObj\->new(name => \*(Aqbob\*(Aq, color => \*(Aqred\*(Aq); \& $obj\->attr(size => 42); \& $obj\->color(\*(Aqblue\*(Aq); \& my $color = $obj\->color; \& my $size = $obj\->attr(\*(Aqsize\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module implements some generic methods that are used by Chemistry::Mol, Chemistry::Atom, Chemistry::Bond, Chemistry::File, etc. .SS "Common Attributes" .IX Subsection "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 \f(CW\*(C`$obj\->id\*(C'\fR; to set the id, call \f(CW\*(C`$obj\->id(\*(Aqnew_id\*(Aq)\*(C'\fR. .IP "id" 4 .IX Item "id" Objects should have a unique \s-1ID.\s0 The user has the responsibility for uniqueness if he assigns ids; otherwise a unique \s-1ID\s0 is assigned sequentially. .IP "name" 4 .IX Item "name" An arbitrary name for an object. The name doesn't need to be unique. .IP "type" 4 .IX Item "type" The interpretation of this attribute is not specified here, but it's typically used for bond orders and atom types. .IP "attr" 4 .IX Item "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: .Sp .Vb 4 \& $color = $obj\->attr(\*(Aqcolor\*(Aq); \& $obj\->attr(color => \*(Aqred\*(Aq); \& $obj\->attr(color => \*(Aqred\*(Aq, flavor => \*(Aqcherry\*(Aq); \& $obj\->attr({color => \*(Aqred\*(Aq, flavor => \*(Aqcherry\*(Aq}); .Ve .SH "OTHER METHODS" .IX Header "OTHER METHODS" .ie n .IP "$obj\->del_attr($attr_name)" 4 .el .IP "\f(CW$obj\fR\->del_attr($attr_name)" 4 .IX Item "$obj->del_attr($attr_name)" Delete an attribute. .ie n .IP "$class\->new(name => value, name => value...)" 4 .el .IP "\f(CW$class\fR\->new(name => value, name => value...)" 4 .IX Item "$class->new(name => value, name => value...)" Generic object constructor. It will automatically call each \*(L"name\*(R" method with the parameter \*(L"value\*(R". For example, .Sp .Vb 1 \& $bob = Chemistry::Obj\->new(name => \*(Aqbob\*(Aq, attr => {size => 42}); .Ve .Sp is equivalent to .Sp .Vb 3 \& $bob = Chemistry::Obj\->new; \& $bob\->name(\*(Aqbob\*(Aq); \& $bob\->attr({size => 42}); .Ve .SH "OPERATOR OVERLOADING" .IX Header "OPERATOR OVERLOADING" Chemistry::Obj overloads a couple of operators for convenience. .ie n .IP """""" 4 .el .IP "``''" 4 The stringification operator. Stringify an object as its id. For example, If an object \f(CW$obj\fR has the id 'a1', print \*(L"$obj\*(R" will print 'a1' instead of something like 'Chemistry::Obj=HASH(0x810bbdc)'. If you really want to get the latter, you can call \f(CW\*(C`overload::StrVal($obj)\*(C'\fR. See overload for details. .IP "cmp" 4 .IX Item "cmp" Compare objects by \s-1ID.\s0 This automatically overloads \f(CW\*(C`eq\*(C'\fR, \f(CW\*(C`ne\*(C'\fR, \f(CW\*(C`lt\*(C'\fR, \f(CW\*(C`le\*(C'\fR, \&\f(CW\*(C`gt\*(C'\fR, and \f(CW\*(C`ge\*(C'\fR as well. For example, \f(CW\*(C`$obj1 eq $obj2\*(C'\fR returns true if both objects have the same id, even if they are different objects with different memory addresses. In contrast, \f(CW\*(C`$obj1 == $obj2\*(C'\fR will return true only if \&\f(CW$obj1\fR and \f(CW$obj2\fR point to the same object, with the same memory address. .SH "SOURCE CODE REPOSITORY" .IX Header "SOURCE CODE REPOSITORY" .SH "SEE ALSO" .IX Header "SEE ALSO" Chemistry::Atom, Chemistry::Bond, Chemistry::Mol .SH "AUTHOR" .IX Header "AUTHOR" Ivan Tubert-Brohman .SH "COPYRIGHT" .IX Header "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.