|
NAMEChemistry::Elements - Perl extension for working with Chemical ElementsSYNOPSISuse Chemistry::Elements qw(get_name get_Z get_symbol); # the constructor can use different input $element = Chemistry::Elements->new( $atomic_number ); $element = Chemistry::Elements->new( $chemical_symbol ); $element = Chemistry::Elements->new( $element_name ); # you can make up your own attributes by specifying # a method (which is really AUTOLOAD) $element->molar_mass(22.989) #sets the attribute $MM = $element->molar_mass #retrieves the value DESCRIPTIONThere are two parts to the module: the object stuff and the exportable functions for use outside of the object stuff. The exportable functions are discussed in "Exportable functions".Chemistry::Elements provides an easy, object-oriented way to keep track of your chemical data. Using either the atomic number, chemical symbol, or element name you can construct an Element object. Once you have an element object, you can associate your data with the object by making up your own methods, which the AUTOLOAD function handles. Since each chemist is likely to want to use his or her own data, or data for some unforesee-able property, this module does not try to be a repository for chemical data. The Element object constructor tries to be as flexible as possible - pass it an atomic number, chemical symbol, or element name and it tries to create the object. # the constructor can use different input $element = Chemistry::Elements->new( $atomic_number ); $element = Chemistry::Elements->new( $chemical_symbol ); $element = Chemistry::Elements->new( $element_name ); Once you have the object, you can define your own methods simply by using them. Giving the method an argument (others will be ignored) creates an attribute with the method's name and the argument's value. # you can make up your own attributes by specifying # a method (which is really AUTOLOAD) $element->molar_mass(22.989) #sets the attribute $MM = $element->molar_mass #retrieves the value The atomic number, chemical symbol, and element name can be retrieved in the same way. $atomic_number = $element->Z; $name = $element->name; $symbol = $element->symbol; These methods can also be used to set values, although changing any of the three affects the other two. $element = Chemistry::Elements->new('Lead'); $atomic_number = $element->Z; # $atomic_number is 82 $element->Z(79); $name = $element->name; # $name is 'Gold' Instance methods
Exportable functionsThese functions can be exported. They are not exported by default. At the moment, only the functional interface supports multi-language names.
The package constructor automatically finds the largest defined atomic number (in case you add your own heavy elements). AUTOLOADing methodsYou can pseudo-define additional methods to associate data with objects. For instance, if you wanted to add a molar mass attribute, you simply pretend that there is a molar_mass method:$element->molar_mass($MM); #add molar mass datum in $MM to object Similarly, you can retrieve previously set values by not specifying an argument to your pretend method: $datum = $element->molar_mass(); #or without the parentheses $datum = $element->molar_mass; If a value has not been associated with the pretend method and the object, the pretend method returns nothing. I had thought about providing basic data for the elements, but thought that anyone using this module would probably have their own data. If there is an interest in canned data, perhaps I can provide mine :) Localization supportXXX: Fill this stuff in later. For now see the test suiteTO DOI would like make this module easily localizable so that one could specify other names or symbols for the elements (i.e. a different language or a different perspective on the heavy elements). If anyone should make changes to the data, i would like to get a copy so that i can include it in future releases :)SOURCE AVAILABILITYThe source for this module is in Github:https://github.com/briandfoy/chemistry-elements AUTHORbrian d foy, "<bdfoy@cpan.org>"COPYRIGHT AND LICENSECopyright © 2000-2021, brian d foy <bdfoy@cpan.org>. All rights reserved.This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.
Visit the GSP FreeBSD Man Page Interface. |