diff options
author | gregor herrmann <gregoa@debian.org> | 2021-10-30 17:14:56 +0200 |
---|---|---|
committer | gregor herrmann <gregoa@debian.org> | 2021-10-30 17:14:56 +0200 |
commit | c62f2d9a5f06a381ed29e5fa656340b6c9aec704 (patch) | |
tree | cc9c2691d4a52a8093a1ea1be9a0ae5df60eb805 |
Import libchemistry-elements-perl_1.075.orig.tar.gz
[dgit import orig libchemistry-elements-perl_1.075.orig.tar.gz]
42 files changed, 2935 insertions, 0 deletions
@@ -0,0 +1,74 @@ +Revision history for Perl module Chemistry::Elements + +1.075 2021-10-26T17:12:19Z + * Minor fix to Changes file because I had the first two dates in the + wrong order + * On the repo side, fixed up the GitHub actions to do more testing + and to report to Coveralls. It's all changed since last I looked. + +1.074 2021-01-15T08:26:43Z + * freshen distro, remove Travis CI, add Github Actions + +1.073 2018-05-22T13:57:23Z + * Change to Artistic License 2.0. + +1.072 2017-08-06T06:08:52Z + * Update the new heavy element symbols. + +1.071 2016-12-30T20:11:12Z + * Version adjustment to be greater than what's on CPAN + +1.065 2016-12-24T18:07:06Z + * Add the rest of the Japanese element names + +1.064 2016-12-24T17:24:18Z + * Ben Bullock adds Japanese element names and fixes some sloppy + typing while he's in there. + +1.063 2016-12-24T03:46:31Z + * New names for 113, 115, 117, and 118 + https://iupac.org/iupac-announces-the-names-of-the-elements-113-115-117-and-118/ + +1.062 2016-01-12T19:38:47Z + * Fix the GitHub reference + +1.061 2016-01-12T19:28:38Z + * Add the latest chemical elements. We're up to 118 now. + * http://periodic.lanl.gov/index.shtml + +1.06 - 2008-08-31 + * Bump to a release version. There are no changes since the + last development version. + +1.05_02 - 2008-08-29 + * Fix some element name typoes + * All of this is now in github + https://github.com/briandfoy/chemistry-elements.git + +1.05_01 - 2008-06-28 + * Adding multi-language support + * This is a test version for the new tests and the big move + +1.05 - 2007-11-09 + * cleanups for the move from CVS to SVN, and latest kwalitee + * no need to upgrade + +1.04 - 2007-07-30 + * Updated distro to use new subversion repo, and for kwalitee + +1.03 - 2007-01-09 + * updated copyright and license info + * no code changes, so no need to upgrade + +1.01 - 2005-05-24 + * Fixed up the distro to have tests and more documentation + * Added license info: this package is under the same terms as Perl itself + +0.97.1102 - 1997-11-02 + * gutsy enough to actually release it for testing and comments + * working on a German version to be released RSN (just need a free hour) + +0.97.1018 - 1997-10-19 + * original version; created by h2xs 1.18 + + diff --git a/INSTALL.SKIP b/INSTALL.SKIP new file mode 100644 index 0000000..99aae72 --- /dev/null +++ b/INSTALL.SKIP @@ -0,0 +1,6 @@ +README\.pod +README.* + +# things that might be in local directories after fooling +# around with them +\.DS_Store @@ -0,0 +1,177 @@ +The Chemistry::Elements module is licensed under the same terms as perl +itself, under the Artistic License 2.0. + + +Artistic License 2.0 +Copyright (c) 2000-2006, The Perl Foundation. +http://www.perlfoundation.org/artistic_license_2_0 + +Preamble + +This license establishes the terms under which a given free software +Package may be copied, modified, distributed, and/or redistributed. +The intent is that the Copyright Holder maintains some artistic +control over the development of that Package while still keeping the +Package available as open source and free software. + +You are always permitted to make arrangements wholly outside of this +license directly with the Copyright Holder of a given Package. If the +terms of this license do not permit the full use that you propose to +make of the Package, you should contact the Copyright Holder and seek +a different licensing arrangement. + +Definitions + +"Copyright Holder" means the individual(s) or organization(s) named in +the copyright notice for the entire Package. + +"Contributor" means any party that has contributed code or other +material to the Package, in accordance with the Copyright Holder's +procedures. + +"You" and "your" means any person who would like to copy, distribute, +or modify the Package. + +"Package" means the collection of files distributed by the Copyright +Holder, and derivatives of that collection and/or of those files. A +given Package may consist of either the Standard Version, or a +Modified Version. + +"Distribute" means providing a copy of the Package or making it +accessible to anyone else, or in the case of a company or +organization, to others outside of your company or organization. + +"Distributor Fee" means any fee that you charge for Distributing this +Package or providing support for this Package to another party. It +does not mean licensing fees. + +"Standard Version" refers to the Package if it has not been modified, +or has been modified only in ways explicitly requested by the +Copyright Holder. + +"Modified Version" means the Package, if it has been changed, and such +changes were not explicitly requested by the Copyright Holder. + +"Original License" means this Artistic License as Distributed with the +Standard Version of the Package, in its current version or as it may +be modified by The Perl Foundation in the future. + +"Source" form means the source code, documentation source, and +configuration files for the Package. + +"Compiled" form means the compiled bytecode, object code, binary, or +any other form resulting from mechanical transformation or translation +of the Source form. + +Permission for Use and Modification Without Distribution + +(1) You are permitted to use the Standard Version and create and use +Modified Versions for any purpose without restriction, provided that +you do not Distribute the Modified Version. + +Permissions for Redistribution of the Standard Version + +(2) You may Distribute verbatim copies of the Source form of the +Standard Version of this Package in any medium without restriction, +either gratis or for a Distributor Fee, provided that you duplicate +all of the original copyright notices and associated disclaimers. At +your discretion, such verbatim copies may or may not include a +Compiled form of the Package. + +(3) You may apply any bug fixes, portability changes, and other +modifications made available from the Copyright Holder. The resulting +Package will still be considered the Standard Version, and as such +will be subject to the Original License. + +Distribution of Modified Versions of the Package as Source + +(4) You may Distribute your Modified Version as Source (either gratis +or for a Distributor Fee, and with or without a Compiled form of the +Modified Version) provided that you clearly document how it differs +from the Standard Version, including, but not limited to, documenting +any non-standard features, executables, or modules, and provided that +you do at least ONE of the following: + + (a) make the Modified Version available to the Copyright Holder of the + Standard Version, under the Original License, so that the Copyright + Holder may include your modifications in the Standard Version. + + (b) ensure that installation of your Modified Version does not prevent + the user installing or running the Standard Version. In addition, the + Modified Version must bear a name that is different from the name of + the Standard Version. + + (c) allow anyone who receives a copy of the Modified Version to make + the Source form of the Modified Version available to others under + + (i) the Original License or + + (ii) a license that permits the licensee to freely copy, modify and + redistribute the Modified Version using the same licensing terms that + apply to the copy that the licensee received, and requires that the + Source form of the Modified Version, and of any works derived from it, + be made freely available in that license fees are prohibited but + Distributor Fees are allowed. + +Distribution of Compiled Forms of the Standard Version or Modified +Versions without the Source + +(5) You may Distribute Compiled forms of the Standard Version without +the Source, provided that you include complete instructions on how to +get the Source of the Standard Version. Such instructions must be +valid at the time of your distribution. If these instructions, at any +time while you are carrying out such distribution, become invalid, you +must provide new instructions on demand or cease further distribution. +If you provide valid instructions or cease distribution within thirty +days after you become aware that the instructions are invalid, then +you do not forfeit any of your rights under this license. + +(6) You may Distribute a Modified Version in Compiled form without the +Source, provided that you comply with Section 4 with respect to the +Source of the Modified Version. + +Aggregating or Linking the Package + +(7) You may aggregate the Package (either the Standard Version or +Modified Version) with other packages and Distribute the resulting +aggregation provided that you do not charge a licensing fee for the +Package. Distributor Fees are permitted, and licensing fees for other +components in the aggregation are permitted. The terms of this license +apply to the use and Distribution of the Standard or Modified Versions +as included in the aggregation. + +(8) You are permitted to link Modified and Standard Versions with +other works, to embed the Package in a larger work of your own, or to +build stand-alone binary or bytecode versions of applications that +include the Package, and Distribute the result without restriction, +provided the result does not expose a direct interface to the Package. + +Items That are Not Considered Part of a Modified Version + +(9) Works (including, but not limited to, modules and scripts) that +merely extend or make use of the Package, do not, by themselves, cause +the Package to be a Modified Version. In addition, such works are not +considered parts of the Package itself, and are not subject to the +terms of this license. + +General Provisions + +(10) Any use, modification, and distribution of the Standard or +Modified Versions is governed by this Artistic License. By using, +modifying or distributing the Package, you accept this license. Do not +use, modify, or distribute the Package, if you do not accept this +license. + +(11) If your Modified Version has been derived from a Modified Version +made by someone other than you, you are nevertheless required to +ensure that your Modified Version complies with the requirements of +this license. + +(12) This license does not grant you the right to use any trademark, +service mark, tradename, or logo of the Copyright Holder. + +(13) This license includes the non-exclusive, worldwide, +free-of-charge patent license to make, have made, use, offer to sell, +sell, import and otherwise transfer the Package with respect to any +patent claims licensable by the Copyright Holder that are necessarily +infringed by the Package. If you institute patent litigation diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..92b43be --- /dev/null +++ b/MANIFEST @@ -0,0 +1,42 @@ +Changes +examples/chart_test +examples/README +INSTALL.SKIP +languages/cz-el.txt +languages/de-el.txt +languages/es-el.txt +languages/fr-el.txt +languages/it-el.txt +languages/nl-el.txt +languages/sv-el.txt +lib/Chemistry/Elements.pm +LICENSE +Makefile.PL +MANIFEST +MANIFEST.SKIP +README.pod +t/_get_name_by_symbol.t +t/_get_name_by_Z.t +t/_get_symbol_by_name.t +t/_get_symbol_by_Z.t +t/_get_Z_by_name.t +t/_get_Z_by_symbol.t +t/_is_name.t +t/_is_symbol.t +t/_is_Z.t +t/autoload.t +t/can.t +t/compile.t +t/get_name.t +t/get_symbol.t +t/get_Z.t +t/name.t +t/new.t +t/pod.t +t/pod_coverage.t +t/symbol.t +t/test_manifest +t/Z.t +xt/changes.t +META.yml Module YAML meta-data (added by MakeMaker) +META.json Module JSON meta-data (added by MakeMaker) diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..6f6f01c --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,68 @@ + +#!start included /usr/local/perls/perl-5.20.0/lib/5.20.0/ExtUtils/MANIFEST.SKIP +# Avoid version control files. +\bRCS\b +\bCVS\b +\bSCCS\b +,v$ +\B\.svn\b +\B\.git\b +\B\.gitignore\b +\b_darcs\b +\B\.cvsignore$ + +# Avoid VMS specific MakeMaker generated files +\bDescrip.MMS$ +\bDESCRIP.MMS$ +\bdescrip.mms$ + +# Avoid Makemaker generated and utility files. +\bMANIFEST\.bak +\bMakefile$ +\bblib/ +\bMakeMaker-\d +\bpm_to_blib\.ts$ +\bpm_to_blib$ +\bblibdirs\.ts$ # 6.18 through 6.25 generated this + +# Avoid Module::Build generated and utility files. +\bBuild$ +\b_build/ +\bBuild.bat$ +\bBuild.COM$ +\bBUILD.COM$ +\bbuild.com$ + +# Avoid temp and backup files. +~$ +\.old$ +\#$ +\b\.# +\.bak$ +\.tmp$ +\.# +\.rej$ + +# Avoid OS-specific files/dirs +# Mac OSX metadata +\B\.DS_Store +# Mac OSX SMB mount metadata files +\B\._ + +# Avoid Devel::Cover and Devel::CoverX::Covered files. +\bcover_db\b +\bcovered\b + +# Avoid MYMETA files +^MYMETA\. +#!end included /usr/local/perls/perl-5.20.0/lib/5.20.0/ExtUtils/MANIFEST.SKIP + + +\.?appveyor.yml +\.releaserc +\.lwpcookies +\bMANIFEST\s\d +\bChanges\s\d +\.icloud$ +\A\.github\b + diff --git a/META.json b/META.json new file mode 100644 index 0000000..61e892f --- /dev/null +++ b/META.json @@ -0,0 +1,57 @@ +{ + "abstract" : "Perl extension for working with Chemical Elements", + "author" : [ + "brian d foy <bdfoy@cpan.org>" + ], + "dynamic_config" : 1, + "generated_by" : "ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010", + "license" : [ + "artistic_2" + ], + "meta-spec" : { + "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", + "version" : 2 + }, + "name" : "Chemistry-Elements", + "no_index" : { + "directory" : [ + "t", + "inc" + ] + }, + "prereqs" : { + "build" : { + "requires" : {} + }, + "configure" : { + "requires" : { + "ExtUtils::MakeMaker" : "6.64", + "File::Spec::Functions" : "0" + } + }, + "runtime" : { + "requires" : { + "perl" : "5.010" + } + }, + "test" : { + "requires" : { + "Test::More" : "1" + } + } + }, + "release_status" : "stable", + "resources" : { + "bugtracker" : { + "web" : "https://github.com/briandfoy/chemistry-elements/issues" + }, + "homepage" : "https://github.com/briandfoy/chemistry-elements", + "repository" : { + "type" : "git", + "url" : "https://github.com/briandfoy/chemistry-elements.git", + "web" : "https://github.com/briandfoy/chemistry-elements" + } + }, + "version" : "1.075", + "x_serialization_backend" : "JSON::PP version 4.04" +} diff --git a/META.yml b/META.yml new file mode 100644 index 0000000..6625249 --- /dev/null +++ b/META.yml @@ -0,0 +1,28 @@ +--- +abstract: 'Perl extension for working with Chemical Elements' +author: + - 'brian d foy <bdfoy@cpan.org>' +build_requires: + Test::More: '1' +configure_requires: + ExtUtils::MakeMaker: '6.64' + File::Spec::Functions: '0' +dynamic_config: 1 +generated_by: 'ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010' +license: artistic_2 +meta-spec: + url: http://module-build.sourceforge.net/META-spec-v1.4.html + version: '1.4' +name: Chemistry-Elements +no_index: + directory: + - t + - inc +requires: + perl: '5.010' +resources: + bugtracker: https://github.com/briandfoy/chemistry-elements/issues + homepage: https://github.com/briandfoy/chemistry-elements + repository: https://github.com/briandfoy/chemistry-elements.git +version: '1.075' +x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..c8d5736 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,111 @@ +package Chemistry::Elements; +use strict; +use warnings; + +=encoding utf8 + +=head1 The build file for Chemistry::Elements + +This build file is a modulino; it works as both a build script and +a module. + +To build the distribution, run this file normally: + + % perl Makefile.PL + +But, it's more interesting than that. You can load it with C<require> +and call C<arguments> to get the data structure it passes to +C<WriteMakefile>: + + my $package = require '/path/to/Makefile.PL'; + my $arguments = $package->arguments; + +Note that C<require>-ing a file makes an entry in C<%INC> for exactly +that name. If you try to C<require> another file with the same name, +even from a different path, C<require> thinks it has already loaded +the file. As such, I recommend you always require the full path to the +file. + +The return value of the C<require> is a package name (in this case, +the name of the main module. Use that to call the C<arguments> method. + +Even if this distribution needs a higher version of Perl, this bit +only needs v5.8. You can play with the data structure with a primitive +Perl. + +=cut + +use File::Spec::Functions qw(catfile); + +my $module = __PACKAGE__; +( my $dist = $module ) =~ s/::/-/g; + +my $github = 'https://github.com/briandfoy/chemistry-elements'; +my $main_file = catfile( 'lib', split /::/, "$module.pm" ); + +my %WriteMakefile = ( + 'MIN_PERL_VERSION' => '5.010', + + 'NAME' => $module, + 'VERSION_FROM' => $main_file, + 'ABSTRACT_FROM' => $main_file, + 'LICENSE' => 'artistic_2', + 'AUTHOR' => 'brian d foy <bdfoy@cpan.org>', + + 'CONFIGURE_REQUIRES' => { + 'ExtUtils::MakeMaker' => '6.64', + 'File::Spec::Functions' => '0', + }, + + 'BUILD_REQUIRES' => { + }, + + 'TEST_REQUIRES' => { + 'Test::More' => '1', + }, + + 'PREREQ_PM' => { + }, + + 'META_MERGE' => { + 'meta-spec' => { version => 2 }, + resources => { + repository => { + type => 'git', + url => "$github.git", + web => $github, + }, + bugtracker => { + web => "$github/issues", + }, + homepage => $github, + }, + }, + + clean => { FILES => "$dist-*" }, + ); + +sub arguments { \%WriteMakefile } + +do_it() unless caller; +sub do_it { + require File::Spec; + my $MM ='ExtUtils::MakeMaker'; + my $MM_version = + eval{ "$MM " . $WriteMakefile{'CONFIGURE_REQUIRES'}{'ExtUtils::MakeMaker'} } + || + "$MM 6.64"; + eval "use $MM_version; 1" or die "Could not load $MM_version: $@"; + eval "use Test::Manifest 1.21" + if -e File::Spec->catfile( qw(t test_manifest) ); + + my $arguments = arguments(); + my $minimum_perl = $arguments->{MIN_PERL_VERSION} || '5.008'; + eval "require $minimum_perl;" or die $@; + + WriteMakefile( %$arguments ); + } + + +no warnings; +__PACKAGE__; diff --git a/README.pod b/README.pod new file mode 100644 index 0000000..ff025d9 --- /dev/null +++ b/README.pod @@ -0,0 +1,119 @@ +=pod + +=encoding utf8 + +=for HTML <a href="https://www.github.com/briandfoy/chemistry-elements/actions?query=workflow%3Amacos"><img src="https://www.github.com/briandfoy/chemistry-elements/workflows/macos/badge.svg"></a> + +=for HTML <a href="https://www.github.com/briandfoy/chemistry-elements/actions?query=workflow%3Aubuntu"><img src="https://www.github.com/briandfoy/chemistry-elements/workflows/ubuntu/badge.svg"></a> + +=for HTML <a href="https://www.github.com/briandfoy/chemistry-elements/actions?query=workflow%3Awindows"><img src="https://www.github.com/briandfoy/chemistry-elements/workflows/windows/badge.svg"></a> + +=for HTML <a href="https://ci.appveyor.com/project/briandfoy/chemistry-elements"><img src="https://ci.appveyor.com/api/projects/status/cct1bt7w2peyqcr8/branch/master?svg=true"></a> + +=for HTML <a href='https://coveralls.io/github/briandfoy/chemistry-elements?branch=master'><img src='https://coveralls.io/repos/github/briandfoy/chemistry-elements/badge.svg?branch=master' alt='Coverage Status' /></a> + +=for HTML <a href="https://github.com/briandfoy/chemistry-elements/blob/master/LICENSE"><img src="https://img.shields.io/cpan/l/Chemistry::Elements.svg" /></a> + +=for HTML <a href="https://metacpan.org/pod/Chemistry::Elements"><img src="https://img.shields.io/cpan/v/Chemistry::Elements.svg" /></A> + +=head1 The Chemistry::Elements module + +This is the I<README> for the L<Chemistry::Elements> Perl module. +You're probably looking at this because you don't know where else to +find what you're looking for. Read this once and you might never have +to read one again for any Perl module. + +=head2 Documentation + +To read about L<Chemistry::Elements>, look at the embedded documentation +in the module itself. Inside the distribution, you can format it +with L<perldoc|https://perldoc.perl.orgperldoc.html>: + + % perldoc lib/Chemistry/Elements.pm + +If you have already installed the module, you can specify the module +name instead of the file location: + + % perldoc Chemistry::Elements + +You can read the documentation and inspect the meta data on +L<MetaCPAN|https://metacpan.org/pod/Chemistry::Elements>. + +The standard module documentation has example uses in the SYNOPSIS +section, but you can also look in the I<examples/> directory (if it's +there), or look at the test files in I<t/>. + +=head2 Installation + +You can install this module with a CPAN client, which will resolve +and install the dependencies: + + % cpan Chemistry::Elements + % cpanm Chemistry::Elements + +You can also install directly from the distribution directory, which +will also install the dependencies: + + % cpan . + % cpanm . + +You could install just this module manually: + + % perl Makefile.PL + % make + % make test + % make install + +You probably don't want to do that unless you're fiddling with the +module and only want to run the tests without installing anything. + +=head2 Source location + +The meta data, such as the source repository and bug tracker, is in +I<Makefile.PL> or the I<META.*> files it creates. You can find that on +those CPAN web interfaces, but you can also look at files directly in +the source repository: + +=over 4 + +=item * L<https://github.com/briandfoy/chemistry-elements> + +=back + +If you find a problem, file a ticket in the L<issue +tracker|https://github.com/briandfoy/chemistry-elements/issues>: + +=over 4 + +=item * L<https://github.com/briandfoy/chemistry-elements/issues> + +=back + +=head2 Getting help + +Although I'm happy to hear from module users in private email, +that's the best way for me to forget to do something. + +Besides the issue trackers, you can find help at +L<Perlmonks|http://www.perlmonks.org> or +L<Stackoverflow|http://www.stackoverflow.com>, both of which have many +competent Perlers who can answer your question, almost in real time. +They might not know the particulars of this module, but they can help +you diagnose your problem. + +You might like to read L<brian's Guide to Solving Any Perl +Problem|https://briandfoy.github.io/brians-guide-to-solving-any-perl-problem/>. + +=head2 Copyright and License + +You should have received a I<LICENSE> file, but the license is also noted +in the module files. About the only thing you can't do is pretend that +you wrote code that you didn't. + +=head2 Good luck! + +Enjoy, + +brian d foy, bdfoy@cpan.org + +=cut diff --git a/examples/README b/examples/README new file mode 100644 index 0000000..6674cee --- /dev/null +++ b/examples/README @@ -0,0 +1 @@ +See the tests in the t/ directory for examples until I add some more.
\ No newline at end of file diff --git a/examples/chart_test b/examples/chart_test new file mode 100644 index 0000000..21d8abf --- /dev/null +++ b/examples/chart_test @@ -0,0 +1,36 @@ +#!/usr/bin/perl -w +use strict; + +#This script demostrates the use of the object oriented interface +#that the Chemistry::Elements module provides. At the prompt you +#can enter a Z, name, or chemical symbol to create an Elements +#object. Once you have an object you can define your own methods +#through which you associate data with the object. + +use Chemistry::Elements qw(); + +print "> "; + +#you can specify a Z, name, or symbol. +#case does not matter since the module should figure it out +while( <STDIN> ) + { + chomp $_; + + my $obj = new Chemistry::Elements $_; + + print "no object could be created\n> " unless ref $obj; + next unless ref $obj; + + #accessor methods for the Element object + my $Z = $obj->Z; + my $name = $obj->name; + my $symbol = $obj->symbol; + + #this is just to demonstrate defining your own method + $obj->pretend_method($obj->Z / 3.2); + my $MM = $obj->pretend_method; + + print "$Z,$name,$symbol,$MM\n> "; + + } diff --git a/languages/cz-el.txt b/languages/cz-el.txt new file mode 100644 index 0000000..610f466 --- /dev/null +++ b/languages/cz-el.txt @@ -0,0 +1,119 @@ +Chech CZ +1 Vodik H
+2 Helium He
+3 Lithium Li
+4 Beryllium Be
+5 Bor B
+6 Uhlik C
+7 Dusik N
+8 Kyslik O
+9 Fluor F
+10 Neon Ne
+11 Sodik Na
+12 Horcik Mg
+13 Hlinik Al
+14 Kremik Si
+15 Fosfor P
+16 Sira S
+17 Chlor Cl
+18 Argon Ar
+19 Draslik K
+20 Vapnik Ca
+21 Skandium Sc
+22 Titan Ti
+23 Vanad V
+24 Chrom Cr
+25 Mangan Mn
+26 Zelezo Fe
+27 Kobalt Co
+28 Nikl Ni
+29 Med Cu
+30 Zinek Zn
+31 Gallium Ga
+32 Germanium Ge
+33 Arsen As
+34 Selen Se
+35 Brom Br
+36 Krypton Kr
+37 Rubidium Rb
+38 Stroncium Sr
+39 Yttrium Y
+40 Zirkonium Zr
+41 Niob Nb
+42 Molybden Mo
+43 Technecium Tc
+44 Ruthenium Ru
+45 Rhodium Rh
+46 Palladium Pd
+47 Stribro Ag
+48 Kadmium Cd
+49 Indium In
+50 Cin Sn
+51 Antimon Sb
+52 Tellur Te
+53 Jod I
+54 Xenon Xe
+55 Cesium Cs
+56 Baryum Ba
+57 Lanthan La
+58 Cer Ce
+59 Praseodym Pr
+60 Neodym Nd
+61 Promethium Pm
+62 Samarium Sm
+63 Europium Eu
+64 Gadolinium Gd
+65 Terbium Tb
+66 Dysprosium Dy
+67 Holmium Ho
+68 Erbium Er
+69 Thulium Tm
+70 Ytterbium Yb
+71 Lutecium Lu
+72 Hafnium Hf
+73 Tantal Ta
+74 Wolfram W
+75 Rhenium Re
+76 Osmium Os
+77 Iridium Ir
+78 Platina Pt
+79 Zlato Au
+80 Rtut Hg
+81 Thallium Tl
+82 Olovo Pb
+83 Bismut Bi
+84 Polonium Po
+85 Astat At
+86 Radon Rn
+87 Francium Fr
+88 Radium Ra
+89 Aktinium Ac
+90 Thorium Th
+91 Protaktinium Pa
+92 Uran U
+93 Neptunium Np
+94 Plutonium Pu
+95 Americium Am
+96 Curium Cm
+97 Berkelium Bk
+98 Kalifornium Cf
+99 Einsteinium Es
+100 Fermium Fm
+101 Mendelevium Md
+102 Nobelium No
+103 Lawrencium Lr
+104 Rutherfordium Rf
+105 Dubnium Db
+106 Seaborgium Sg
+107 Bohrium Bh
+108 Hassium Hs
+109 Meitnerium Mt
+110 Darmstadtium Ds
+111 Roentgenium Rg
+112 Ununbium Uub
+113 Ununtrium Uut
+114 Ununquadium Uuq
+115 Ununpentium Uup
+116 Ununhexium Uuh
+117 Ununseptium Uus
+118 Ununoctium Uuo
\ No newline at end of file diff --git a/languages/de-el.txt b/languages/de-el.txt new file mode 100644 index 0000000..313a86d --- /dev/null +++ b/languages/de-el.txt @@ -0,0 +1,119 @@ +German DE +1 Wasserstoff H
+2 Helium He
+3 Lithium Li
+4 Beryllium Be
+5 Bor B
+6 Kohlenstoff C
+7 Stickstoff N
+8 Sauerstoff O
+9 Fluor F
+10 Neon Ne
+11 Natrium Na
+12 Magnesium Mg
+13 Aluminum Al
+14 Silizium Si
+15 Phosphor P
+16 Schwefel S
+17 Chlor Cl
+18 Argon Ar
+19 Kalium K
+20 Kalzium Ca
+21 Scandium Sc
+22 Titan Ti
+23 Vanadium V
+24 Chrom Cr
+25 Mangan Mn
+26 Eisen Fe
+27 Kobalt Co
+28 Nickel Ni
+29 Kupfer Cu
+30 Zink Zn
+31 Gallium Ga
+32 Germanium Ge
+33 Arsen As
+34 Selen Se
+35 Brom Br
+36 Krypton Kr
+37 Rubidium Rb
+38 Strontium Sr
+39 Yttrium Y
+40 Zirkonium Zr
+41 Nobium Nb
+42 Molybdan Mo
+43 Technetium Tc
+44 Ruthenium Ru
+45 Rhodium Rh
+46 Palladium Pd
+47 Silber Ag
+48 Kadmium Cd
+49 Indium In
+50 Zinn Sn
+51 Antimon Sb
+52 Tellur Te
+53 Jod I
+54 Xenon Xe
+55 Casium Cs
+56 Barium Ba
+57 Lanthan La
+58 Cer Ce
+59 Praseodym Pr
+60 Neodym Nd
+61 Promethium Pm
+62 Samarium Sm
+63 Europium Eu
+64 Gadolinium Gd
+65 Terbium Tb
+66 Dysprosium Dy
+67 Holmium Ho
+68 Erbium Er
+69 Thulium Tm
+70 Ytterbium Yb
+71 Lutetium Lu
+72 Hafnium Hf
+73 Tantal Ta
+74 Wolfram W
+75 Rhenium Re
+76 Osmium Os
+77 Iridium Ir
+78 Platin Pt
+79 Gold Au
+80 Quecksilber Hg
+81 Thallium Tl
+82 Blei Pb
+83 Wismut Bi
+84 Polonium Po
+85 Astat At
+86 Radon Rn
+87 Franzium Fr
+88 Radium Ra
+89 Aktinium Ac
+90 Thorium Th
+91 Protactinium Pa
+92 Uran U
+93 Neptunium Np
+94 Plutonium Pu
+95 Amerikium Am
+96 Curium Cm
+97 Berkelium Bk
+98 Kalifornium Cf
+99 Einsteinium Es
+100 Fermium Fm
+101 Mendelevium Md
+102 Nobelium No
+103 Lawrencium Lr
+104 Rutherfordium Rf
+105 Dubnium Db
+106 Seaborgium Sg
+107 Bohrium Bh
+108 Hassium Hs
+109 Meitnerium Mt
+110 Darmstadtium Ds
+111 Rontgenium Rg
+112 Ununbium Uub
+113 Ununtrium Uut
+114 Ununquadium Uuq
+115 Ununpentium Uup
+116 Ununhexium Uuh
+117 Ununseptium Uus
+118 Ununoctium Uuo
\ No newline at end of file diff --git a/languages/es-el.txt b/languages/es-el.txt new file mode 100644 index 0000000..5310a11 --- /dev/null +++ b/languages/es-el.txt @@ -0,0 +1,119 @@ +Spanish ES +1 Hidrogeno H
+2 Helio He
+3 Litio Li
+4 Berilio Be
+5 Boro B
+6 Carbono C
+7 Nitrogeno N
+8 Oxigeno O
+9 Fluor F
+10 Neon Ne
+11 Sodio Na
+12 Magnesio Mg
+13 Aluminio Al
+14 Silicio Si
+15 Fosforo P
+16 Azufre S
+17 Cloro Cl
+18 Argon Ar
+19 Potasio K
+20 Calcio Ca
+21 Escandio Sc
+22 Titanio Ti
+23 Vanadio V
+24 Cromo Cr
+25 Manganeso Mn
+26 Hierro Fe
+27 Cobalto Co
+28 Niquel Ni
+29 Cobre Cu
+30 Zinc Zn
+31 Galio Ga
+32 Germanio Ge
+33 Arsenico As
+34 Selenio Se
+35 Bromo Br
+36 Kripton Kr
+37 Rubidio Rb
+38 Estroncio Sr
+39 Itrio Y
+40 Circonio Zr
+41 Niobio Nb
+42 Molibdeno Mo
+43 Tecnecio Tc
+44 Rutenio Ru
+45 Rodio Rh
+46 Paladio Pd
+47 Plata Ag
+48 Cadmio Cd
+49 Indio In
+50 Estano Sn
+51 Antimonio Sb
+52 Telurio Te
+53 Yodo I
+54 Xenon Xe
+55 Cesio Cs
+56 Bario Ba
+57 Lantano La
+58 Cerio Ce
+59 Praseodimio Pr
+60 Neodimio Nd
+61 Prometio Pm
+62 Samario Sm
+63 Europio Eu
+64 Gadolinio Gd
+65 Terbio Tb
+66 Disprosio Dy
+67 Holmio Ho
+68 Erbio Er
+69 Tulio Tm
+70 Iterbio Yb
+71 Lutecio Lu
+72 Hafnio Hf
+73 Tantalio Ta
+74 Wolframio W
+75 Renio Re
+76 Osmio Os
+77 Iridio Ir
+78 Platino Pt
+79 Oro Au
+80 Mercurio Hg
+81 Talio Tl
+82 Plomo Pb
+83 Bismuto Bi
+84 Polonio Po
+85 Astato At
+86 Radon Rn
+87 Francio Fr
+88 Radio Ra
+89 Actinio Ac
+90 Torio Th
+91 Protactinio Pa
+92 Uranio U
+93 Neptunio Np
+94 Plutonio Pu
+95 Americio Am
+96 Curio Cm
+97 Berkelio Bk
+98 Californio Cf
+99 Einsteinio Es
+100 Fermio Fm
+101 Mendelevio Md
+102 Nobelio No
+103 Lawrencio Lr
+104 Rutherfordio Rf
+105 Dubnio Db
+106 Seaborgio Sg
+107 Bohrio Bh
+108 Hassio Hs
+109 Meitnerio Mt
+110 Darmstadtio Ds
+111 Roentgenio Rg
+112 Ununbio Uub
+113 Ununtrio Uut
+114 Ununquadio Uug
+115 Ununpentio Uup
+116 Ununhexio Uuh
+117 Ununseptio Uus
+118 Ununoctio Uuo
\ No newline at end of file diff --git a/languages/fr-el.txt b/languages/fr-el.txt new file mode 100644 index 0000000..0d45454 --- /dev/null +++ b/languages/fr-el.txt @@ -0,0 +1,119 @@ +French FR +1 Hydrogene H
+2 Helium He
+3 Lithium Li
+4 Beryllium Be
+5 Bore B
+6 Carbone C
+7 Azote N
+8 Oxygene O
+9 Fluor F
+10 Neon Ne
+11 Sodium Na
+12 Magnesium Mg
+13 Aluminium Al
+14 Silicium Si
+15 Phosphore P
+16 Soufre S
+17 Chlore Cl
+18 Argon Ar
+19 Potassium K
+20 Calcium Ca
+21 Scandium Sc
+22 Titane Ti
+23 Vanadium V
+24 Chrome Cr
+25 Manganese Mn
+26 Fer Fe
+27 Cobalt Co
+28 Nickel Ni
+29 Cuivre Cu
+30 Zinc Zn
+31 Gallium Ga
+32 Germanium Ge
+33 Arsenic As
+34 Selenium Se
+35 Brome Br
+36 Krypton Kr
+37 Rubidium Rb
+38 Strontium Sr
+39 Yttrium Y
+40 Zirconium Zr
+41 Niobium Nb
+42 Molybdene Mo
+43 Technetium Tc
+44 Ruthenium Ru
+45 Rhodium Rh
+46 Palladium Pd
+47 Argent Ag
+48 Cadmium Cd
+49 Indium In
+50 Etain Sn
+51 Antimoine Sb
+52 Tellure Te
+53 Iode I
+54 Xenon Xe
+55 Cesium Cs
+56 Baryum Ba
+57 Lanthane La
+58 Cerium Ce
+59 Praseodyme Pr
+60 Neodyme Nd
+61 Promethium Pm
+62 Samarium Sm
+63 Europium Eu
+64 Gadolinium Gd
+65 Terbium Tb
+66 Dysprosium Dy
+67 Holmium Ho
+68 Erbium Er
+69 Thulium Tm
+70 Ytterbium Yb
+71 Lutecium Lu
+72 Hafnium Hf
+73 Tantale Ta
+74 Tungstene W
+75 Rhenium Re
+76 Osmium Os
+77 Iridium Ir
+78 Platine Pt
+79 Or Au
+80 Mercure Hg
+81 Thallium Tl
+82 Plomb Pb
+83 Bismuth Bi
+84 Polonium Po
+85 Astate At
+86 Radon Rn
+87 Francium Fr
+88 Radium Ra
+89 Actinium Ac
+90 Thorium Th
+91 Protactinium Pa
+92 Uranium U
+93 Neptunium Np
+94 Plutonium Pu
+95 Americium Am
+96 Curium Cm
+97 Berkelium Bk
+98 Californium Cf
+99 Einsteinium Es
+100 Fermium Fm
+101 Mendelevium Md
+102 Nobelium No
+103 Lawrencium Lr
+104 Rutherfordium Rf
+105 Dubnium Db
+106 Seaborgium Sg
+107 Bohrium Bh
+108 Hassium Hs
+109 Meitnerium Mt
+110 Darmstadtium Ds
+111 Roentgenium Rg
+112 Ununbium Uub
+113 Ununtrium Uut
+114 Ununquadium Uuq
+115 Ununpentium Uup
+116 Ununhexium Uuh
+117 Ununseptium Uus
+118 Ununoctium Uuo
\ No newline at end of file diff --git a/languages/it-el.txt b/languages/it-el.txt new file mode 100644 index 0000000..784c3ee --- /dev/null +++ b/languages/it-el.txt @@ -0,0 +1,119 @@ +Italian IT +1 Idrogeno H
+2 Elio He
+3 Litio Li
+4 Berillio Be
+5 Boro B
+6 Carbonio C
+7 Azoto N
+8 Ossigeno O
+9 Fluoro F
+10 Neon Ne
+11 Sodio Na
+12 Magnesio Mg
+13 Alluminio Al
+14 Silicio Si
+15 Fosforo P
+16 Zolfo S
+17 Cloro Cl
+18 Argon Ar
+19 Potassio K
+20 Calcio Ca
+21 Scandio Sc
+22 Titanio Ti
+23 Vanadio V
+24 Cromo Cr
+25 Manganese Mn
+26 Ferro Fe
+27 Cobalto Co
+28 Nichel Ni
+29 Rame Cu
+30 Zinco Zn
+31 Gallio Ga
+32 Germanio Ge
+33 Arsenico As
+34 Selenio Se
+35 Bromo Br
+36 Kripton Kr
+37 Rubidio Rb
+38 Stronzio Sr
+39 Ittrio Y
+40 Zirconio Zr
+41 Niobio Nb
+42 Molibdeno Mo
+43 Tecnezio Tc
+44 Rutenio Ru
+45 Rodio Rh
+46 Palladio Pd
+47 Argento Ag
+48 Cadmio Cd
+49 Indio In
+50 Stagno Sn
+51 Antimonio Sb
+52 Tellurio Te
+53 Iodio I
+54 Xeno Xe
+55 Cesio Cs
+56 Bario Ba
+57 Lantanio La
+58 Cerio Ce
+59 Praseodimio Pr
+60 Neodimio Nd
+61 Promezio Pm
+62 Samario Sm
+63 Europio Eu
+64 Gadolinio Gd
+65 Terbio Tb
+66 Disprosio Dy
+67 Olmio Ho
+68 Erbio Er
+69 Tulio Tm
+70 Itterbio Yb
+71 Lutezio Lu
+72 Afnio Hf
+73 Tantalio Ta
+74 Tungsteno W
+75 Renio Re
+76 Osmio Os
+77 Iridio Ir
+78 Platino Pt
+79 Oro Au
+80 Mercurio Hg
+81 Tallio Tl
+82 Piombo Pb
+83 Bismuto Bi
+84 Polonio Po
+85 Astato At
+86 Radon Rn
+87 Francio Fr
+88 Radio Ra
+89 Attinio Ac
+90 Torio Th
+91 Protoattinio Pa
+92 Uranio U
+93 Nettunio Np
+94 Plutonio Pu
+95 Americio Am
+96 Curio Cm
+97 Berkelio Bk
+98 Californio Cf
+99 Einsteinio Es
+100 Fermio Fm
+101 Mendelevio Md
+102 Nobelio No
+103 Laurenzio Lr
+104 Rutherfordio Rf
+105 Dubnio Db
+106 Seaborgio Sg
+107 Bohrio Bh
+108 Hassio Hs
+109 Meitnerio Mt
+110 Darmstadtio Ds
+111 Roentgenio Rg
+112 Ununbio Uub
+113 Ununtrio Uut
+114 Ununquadio Uuq
+115 Ununpentio Uup
+116 Ununhexio Uuh
+117 Ununseptio Uus
+118 Ununoctio Uuo
\ No newline at end of file diff --git a/languages/nl-el.txt b/languages/nl-el.txt new file mode 100644 index 0000000..afda144 --- /dev/null +++ b/languages/nl-el.txt @@ -0,0 +1,119 @@ +Dutch NL +1 Waterstof H
+2 Helium He
+3 Lithium Li
+4 Berillium Be
+5 Boor B
+6 Koolstof C
+7 Stikstof N
+8 Zuurstof O
+9 Fluor F
+10 Neon Ne
+11 Natrium Na
+12 Magnesium Mg
+13 Aluminium Al
+14 Silicium Si
+15 Fosfor P
+16 Zwavel S
+17 Chloor Cl
+18 Argon Ar
+19 Kalium K
+20 Calcium Ca
+21 Scandium Sc
+22 Titanium Ti
+23 Vanadium V
+24 Chroom Cr
+25 Mangaan Mn
+26 IJzer Fe
+27 Kobalt Co
+28 Nikkel Ni
+29 Koper Cu
+30 Zink Zn
+31 Gallium Ga
+32 Germanium Ge
+33 Arsenicum As
+34 Seleen Se
+35 Broom Br
+36 Krypton Kr
+37 Rubidium Rb
+38 Strontium Sr
+39 Yttrium Y
+40 Zirkonium Zr
+41 Niobium Nb
+42 Molybdeen Mo
+43 Technetium Tc
+44 Ruthenium Ru
+45 Rhodium Rh
+46 Palladium Pd
+47 Zilver Ag
+48 Cadmium Cd
+49 Indium In
+50 Tin Sn
+51 Antimonium Sb
+52 Telluur Te
+53 Jodium I
+54 Xenon Xe
+55 Cesium Cs
+56 Barium Ba
+57 Lanthanium La
+58 Cerium Ce
+59 Praseodymium Pr
+60 Neodymium Nd
+61 Promethium Pm
+62 Samarium Sm
+63 Europium Eu
+64 Gadolinium Gd
+65 Terbium Tb
+66 Dysprosium Dy
+67 Holmium Ho
+68 Erbium Er
+69 Thulium Tm
+70 Ytterbium Yb
+71 Lutetium Lu
+72 Hafnium Hf
+73 Tantalium Ta
+74 Wolfraam W
+75 Renium Re
+76 Osmium Os
+77 Iridium Ir
+78 Platina Pt
+79 Goud Au
+80 Kwik Hg
+81 Thallium Tl
+82 Lood Pb
+83 Bismut Bi
+84 Polonium Po
+85 Astatium At
+86 Radon Rn
+87 Francium Fr
+88 Radium Ra
+89 Actinium Ac
+90 Thorium Th
+91 Protactinium Pa
+92 Uranium U
+93 Neptunium Np
+94 Plutonium Pu
+95 Americium Am
+96 Curium Cm
+97 Berkelium Bk
+98 Californium Cf
+99 Einsteinium Es
+100 Fermium Fm
+101 Mendelevium Md
+102 Nobelium No
+103 Lawrencium Lr
+104 Rutherfordium Rf
+105 Dubnium Db
+106 Seaborgium Sg
+107 Bohrium Bh
+108 Hassium Hs
+109 Meitnerium Mt
+110 Darmstadtium Ds
+111 Roentgenium Rg
+112 Ununbium Uub
+113 Ununtrium Uut
+114 Ununquadium Uug
+115 Ununpentium Uup
+116 Ununhexium Uuh
+117 Ununseptium Uus
+118 Ununoctium Uuo
diff --git a/languages/sv-el.txt b/languages/sv-el.txt new file mode 100644 index 0000000..f578a1a --- /dev/null +++ b/languages/sv-el.txt @@ -0,0 +1,119 @@ +XXX SV +1 Vate H
+2 Helium He
+3 Litium Li
+4 Beryllium Be
+5 Bor B
+6 Kol C
+7 Kvave N
+8 Syre O
+9 Fluor F
+10 Neon Ne
+11 Natrium Na
+12 Magnesium Mg
+13 Aluminium Al
+14 Kisel Si
+15 Fosfor P
+16 Svavel S
+17 Klor Cl
+18 Argon Ar
+19 Kalium K
+20 Kalcium Ca
+21 Skandium Sc
+22 Titan Ti
+23 Vanadin V
+24 Krom Cr
+25 Mangan Mn
+26 Jarn Fe
+27 Kobolt Co
+28 Nickel Ni
+29 Koppar Cu
+30 Zink Zn
+31 Gallium Ga
+32 Germanium Ge
+33 Arsenik As
+34 Selen Se
+35 Brom Br
+36 Krypton Kr
+37 Rubidium Rb
+38 Strontium Sr
+39 Yttrium Y
+40 Zirkonium Zr
+41 Niob Nb
+42 Molybden Mo
+43 Teknetium Tc
+44 Rutenium Ru
+45 Rodium Rh
+46 Palladium Pd
+47 Silver Ag
+48 Kadmium Cd
+49 Indium In
+50 Tenn Sn
+51 Antimon Sb
+52 Tellur Te
+53 Jod I
+54 Xenon Xe
+55 Cesium Cs
+56 Barium Ba
+57 Lantan La
+58 Cerium Ce
+59 Praseodym Pr
+60 Neodym Nd
+61 Prometium Pm
+62 Samarium Sm
+63 Europium Eu
+64 Gadolinium Gd
+65 Terbium Tb
+66 Dysprosium Dy
+67 Holmium Ho
+68 Erbium Er
+69 Tulium Tm
+70 Ytterbium Yb
+71 Lutetium Lu
+72 Hafnium Hf
+73 Tantal Ta
+74 Volfram W
+75 Rhenium Re
+76 Osmium Os
+77 Iridium Ir
+78 Platina Pt
+79 Guld Au
+80 Kvicksilver Hg
+81 Tallium Tl
+82 Bly Pb
+83 Vismut Bi
+84 Polonium Po
+85 Astat At
+86 Radon Rn
+87 Francium Fr
+88 Radium Ra
+89 Aktinium Ac
+90 Torium Th
+91 Protaktinium Pa
+92 Uran U
+93 Neptunium Np
+94 Plutonium Pu
+95 Americium Am
+96 Curium Cm
+97 Berkelium Bk
+98 Californium Cf
+99 Einsteinium Es
+100 Fermium Fm
+101 Mendelevium Md
+102 Nobelium No
+103 Lawrencium Lr
+104 Rutherfordium Rf
+105 Dubnium Db
+106 Seaborgium Sg
+107 Bohrium Bh
+108 Hassium Hs
+109 Meitnerium Mt
+110 Darmstadtium Ds
+111 Rontgenium Rg
+112 Ununbium Uub
+113 Ununtrium Uut
+114 Ununquadium Uug
+115 Ununpentium Uup
+116 Ununhexium Uuh
+117 Ununseptium Uus
+118 Ununoctium Uuo
diff --git a/lib/Chemistry/Elements.pm b/lib/Chemistry/Elements.pm new file mode 100644 index 0000000..f9a94d1 --- /dev/null +++ b/lib/Chemistry/Elements.pm @@ -0,0 +1,721 @@ +use v5.10; + +package Chemistry::Elements; + +use strict; +use warnings; +use utf8; +no warnings; + +use Carp qw(croak carp); +use Scalar::Util qw(blessed); + +use vars qw( @ISA $AUTOLOAD + $debug %names %elements $maximum_Z + %names_to_Z $Default_language %Languages + ); + +use Exporter qw(import); + +our @EXPORT_OK = qw(get_Z get_symbol get_name); +our @EXPORT = qw(); +our $VERSION = '1.075'; + +use subs qw( + _get_name_by_Z + _get_symbol_by_Z + _get_name_by_symbol + _get_Z_by_symbol + _get_symbol_by_name + _get_Z_by_name + _is_Z + _is_name + _is_symbol + _format_name + _format_symbol + ); + +BEGIN { +my @class_methods = qw(can isa); +my @object_methods = qw(new Z name symbol can); +my %class_methods = map { $_, 1 } @class_methods; +my %object_methods = map { $_, 1 } @object_methods; + +sub can { + my $thingy = shift; + my @methods = @_; + + my $method_hash = blessed $thingy ? \%object_methods : \%class_methods ; + + foreach my $method ( @methods ) { + return unless exists $method_hash->{ $method }; + } + + return 1; + } + +sub _add_object_method { # everyone gets it + $object_methods{ $_[1] } = 1; + } +} + +$debug = 0; + +%Languages = ( + 'Pig Latin' => 0, + 'English' => 1, + 'Japanese' => 2, + ); + +$Default_language = $Languages{'English'}; + +# http://www.ptable.com/?lang=ja +%names = ( + 1 => [ qw( Ydrogenhai Hydrogen 水素) ], + 2 => [ qw( Eliumhai Helium ヘリウム) ], + 3 => [ qw( Ithiumlai Lithium リチウム) ], + 4 => [ qw( Erylliumbai Beryllium ベリリウム) ], + 5 => [ qw( Oronbai Boron ホウ素) ], + 6 => [ qw( Arboncai Carbon 炭素) ], + 7 => [ qw( Itrogennai Nitrogen 窒素) ], + 8 => [ qw( Xygenoai Oxygen 酸素) ], + 9 => [ qw( Luorinefai Fluorine フッ素) ], + 10 => [ qw( Eonnai Neon ネオン) ], + 11 => [ qw( Odiumsai Sodium ナトリウム) ], + 12 => [ qw( Agnesiummai Magnesium マグネシウム) ], + 13 => [ qw( Luminiumaai Aluminium アルミニウム) ], + 14 => [ qw( Iliconsai Silicon ケイ素) ], + 15 => [ qw( Hosphoruspai Phosphorus リン) ], + 16 => [ qw( Ulfursai Sulfur 硫黄) ], + 17 => [ qw( Hlorinecai Chlorine 塩素) ], + 18 => [ qw( Rgonaai Argon アルゴン) ], + 19 => [ qw( Otassiumpai Potassium カリウム) ], + 20 => [ qw( Alciumcai Calcium カルシウム) ], + 21 => [ qw( Candiumsai Scandium スカンジウム) ], + 22 => [ qw( Itaniumtai Titanium チタン) ], + 23 => [ qw( Anadiumvai Vanadium バナジウム) ], + 24 => [ qw( Hromiumcai Chromium クロム) ], + 25 => [ qw( Anganesemai Manganese マンガン) ], + 26 => [ qw( Roniai Iron 鉄) ], + 27 => [ qw( Obaltcai Cobalt コバルト) ], + 28 => [ qw( Ickelnai Nickel ニッケル) ], + 29 => [ qw( Oppercai Copper 銅) ], + 30 => [ qw( Inczai Zinc 亜鉛) ], + 31 => [ qw( Alliumgai Gallium ガリウム) ], + 32 => [ qw( Ermaniumgai Germanium ゲルマニウム) ], + 33 => [ qw( Rsenicaai Arsenic ヒ素) ], + 34 => [ qw( Eleniumsai Selenium セレン) ], + 35 => [ qw( Rominebai Bromine 臭素) ], + 36 => [ qw( Ryptonkai Krypton クリプトン) ], + 37 => [ qw( Ubidiumrai Rubidium ルビジウム) ], + 38 => [ qw( Trontiumsai Strontium ストロンチウム) ], + 39 => [ qw( Ttriumyai Yttrium イットリウム) ], + 40 => [ qw( Irconiumzai Zirconium ジルコニウム) ], + 41 => [ qw( Iobiumnai Niobium ニオブ) ], + 42 => [ qw( Olybdenummai Molybdenum モリブデン) ], + 43 => [ qw( Echnetiumtai Technetium テクネチウム) ], + 44 => [ qw( Utheniumrai Ruthenium ルテニウム) ], + 45 => [ qw( Hodiumrai Rhodium ロジウム) ], + 46 => [ qw( Alladiumpai Palladium パラジウム) ], + 47 => [ qw( Ilversai Silver 銀) ], + 48 => [ qw( Admiumcai Cadmium カドミウム) ], + 49 => [ qw( Ndiumiai Indium インジウム) ], + 50 => [ qw( Intai Tin スズ) ], + 51 => [ qw( Ntimonyaai Antimony アンチモン) ], + 52 => [ qw( Elluriumtai Tellurium テルル) ], + 53 => [ qw( Odineiai Iodine ヨウ素) ], + 54 => [ qw( Enonxai Xenon キセノン) ], + 55 => [ qw( Esiumcai Cesium セシウム) ], + 56 => [ qw( Ariumbai Barium バリウム) ], + 57 => [ qw( Anthanumlai Lanthanum ランタン) ], + 58 => [ qw( Eriumcai Cerium セリウム) ], + 59 => [ qw( Raesodymiumpai Praseodymium プラセオジム) ], + 60 => [ qw( Eodymiumnai Neodymium ネオジム) ], + 61 => [ qw( Romethiumpai Promethium プロメチウム) ], + 62 => [ qw( Amariumsai Samarium サマリウム) ], + 63 => [ qw( Uropiumeai Europium ユウロピウム) ], + 64 => [ qw( Adoliniumgai Gadolinium ガドリニウム) ], + 65 => [ qw( Erbiumtai Terbium テルビウム) ], + 66 => [ qw( Ysprosiumdai Dysprosium ジスプロシウム) ], + 67 => [ qw( Olmiumhai Holmium ホルミウム) ], + 68 => [ qw( Rbiumeai Erbium エルビウム) ], + 69 => [ qw( Huliumtai Thulium ツリウム) ], + 70 => [ qw( Tterbiumyai Ytterbium イッテルビウム) ], + 71 => [ qw( Utetiumlai Lutetium ルテチウム) ], + 72 => [ qw( Afniumhai Hafnium ハフニウム) ], + 73 => [ qw( Antalumtai Tantalum タンタル) ], + 74 => [ qw( Ungstentai Tungsten タングステン) ], + 75 => [ qw( Heniumrai Rhenium レニウム) ], + 76 => [ qw( Smiumoai Osmium オスミウム) ], + 77 => [ qw( Ridiumiai Iridium イリジウム) ], + 78 => [ qw( Latinumpai Platinum 白金) ], + 79 => [ qw( Oldgai Gold 金) ], + 80 => [ qw( Ercurymai Mercury 水銀) ], + 81 => [ qw( Halliumtai Thallium タリウム) ], + 82 => [ qw( Eadlai Lead 鉛) ], + 83 => [ qw( Ismuthbai Bismuth ビスマス) ], + 84 => [ qw( Oloniumpai Polonium ポロニウム) ], + 85 => [ qw( Statineaai Astatine アスタチン) ], + 86 => [ qw( Adonrai Radon ラドン) ], + 87 => [ qw( Ranciumfai Francium フランシウム) ], + 88 => [ qw( Adiumrai Radium ラジウム) ], + 89 => [ qw( Ctiniumaai Actinium アクチニウム) ], + 90 => [ qw( Horiumtai Thorium トリウム) ], + 91 => [ qw( Rotactiniumpai Protactinium プロトアクチニウム) ], + 92 => [ qw( Raniumuai Uranium ウラン) ], + 93 => [ qw( Eptuniumnai Neptunium ネプツニウム) ], + 94 => [ qw( Lutoniumpai Plutonium プルトニウム) ], + 95 => [ qw( Mericiumaai Americium アメリシウム) ], + 96 => [ qw( Uriumcai Curium キュリウム) ], + 97 => [ qw( Erkeliumbai Berkelium バークリウム) ], + 98 => [ qw( Aliforniumcai Californium カリホルニウム) ], + 99 => [ qw( Insteiniumeai Einsteinium アインスタイニウム) ], +100 => [ qw( Ermiumfai Fermium フェルミウム) ], +101 => [ qw( Endeleviummai Mendelevium メンデレビウム) ], +102 => [ qw( Obeliumnai Nobelium ノーベリウム) ], +103 => [ qw( Awerenciumlai Lawrencium ローレンシウム) ], +104 => [ qw( Utherfordiumrai Rutherfordium ラザホージウム) ], +105 => [ qw( Ubniumdai Dubnium ドブニウム) ], +106 => [ qw( Eaborgiumsai Seaborgium シーボーギウム) ], +107 => [ qw( Ohriumbai Bohrium ボーリウム) ], +108 => [ qw( Assiumhai Hassium ハッシウム) ], +109 => [ qw( Eitneriummai Meitnerium マイトネリウム) ], +110 => [ qw( Armstadtiumdai Darmstadtium ダームスタチウム) ], +111 => [ qw( Oentgeniumrai Roentgenium レントゲニウム) ], +112 => [ qw( Operniciumcai Copernicium コペルニシウム) ], +113 => [ qw( Ihoniumnai Nihonium ニホニウム) ], +114 => [ qw( Leroviumfai Flerovium フレロビウム) ], +115 => [ qw( Oscoviummai Moscovium モスコビウム) ], +116 => [ qw( Ivermoriumlai Livermorium リバモリウム) ], +117 => [ qw( Ennessinetai Tennessine テネシン) ], +118 => [ qw( Ganessonoai Oganesson オガネソン) ], +); + +{ +# There might be duplicates keys here, but it should never come out +# with the wrong Z +our %names_to_Z = (); +foreach my $Z ( keys %names ) { + my @names = map { lc } @{ $names{$Z} }; +# print STDERR "Got names [@names] for $Z\n"; + @names_to_Z{@names} = ($Z) x @names; + } + +#print STDERR Dumper( \%names_to_symbol ); use Data::Dumper; +} + +{ +my @a = sort {$a <=> $b } keys %names; +$maximum_Z = pop @a; +} + +my %elements = map { state $n = 0; $n++; $_ => $n, $n => $_ } qw( +H He +Li Be B C N O F Ne +Na Mg Al Si P S Cl Ar +K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge As Se Br Kr +Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe +Cs Ba La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn +Fr Ra Ac Th Pa U Np Pu Am Cm Bk Cf Es Fm Md No Lr Rf Ha Sg Bh Hs Mt Ds Rg Cn Nh Fl Mc Lv Ts Og +); + +sub new { + my( $class, $data, $language ) = @_; + + my $self = {}; + bless $self, $class; + + if( _is_Z $data ) { $self->Z($data) } + elsif( _is_symbol $data ) { $self->symbol($data) } + elsif( _is_name $data ) { $self->name($data) } + else { return } + + return $self; + } + +sub Z { + my $self = shift; + + return $self->{'Z'} unless @_; + my $data = shift; + + unless( _is_Z $data ) { + $self->error('$data is not a valid proton number'); + return; + } + + $self->{'Z'} = $data; + $self->{'name'} = _get_name_by_Z $data; + $self->{'symbol'} = _get_symbol_by_Z $data; + + return $data; + } + +sub name { + my $self = shift; + + return $self->{'name'} unless @_; + my $data = shift; + + unless( _is_name $data ) { + $self->error('$data is not a valid element name'); + return; + } + + $self->{'name'} = _format_name $data; + $self->{'Z'} = _get_Z_by_name $data; + $self->{'symbol'} = _get_symbol_by_Z($self->Z); + + return $data; + } + +sub symbol { + my $self = shift; + + return $self->{'symbol'} unless @_; + my $data = shift; + + unless( _is_symbol $data ) { + $self->error('$data is not a valid element symbol'); + return; + } + + $self->{'symbol'} = _format_symbol $data; + $self->{'Z'} = _get_Z_by_symbol $data; + $self->{'name'} = _get_name_by_Z $self->Z; + + return $data; + } + +sub get_symbol { + my $thingy = shift; + + #since we were asked for a name, we'll suppose that we were passed + #either a chemical symbol or a Z. + return _get_symbol_by_Z($thingy) if _is_Z $thingy; + return _get_symbol_by_name($thingy) if _is_name $thingy; + + #maybe it's already a symbol... + return _format_symbol $thingy if _is_symbol $thingy; + + #we were passed something wierd. pretend we don't know anything. + return; + } + +sub _get_symbol_by_name { + my $name = lc shift; + + return unless _is_name $name; + + my $Z = $names_to_Z{$name}; + + $elements{$Z}; + } + +sub _get_symbol_by_Z { + return unless _is_Z $_[0]; + + return $elements{$_[0]}; + } + +sub get_name { + my $thingy = shift; + my $language = defined $_[0] ? $_[0] : $Default_language; + + #since we were asked for a name, we'll suppose that we were passed + #either a chemical symbol or a Z. + return _get_name_by_symbol( $thingy, $language ) if _is_symbol $thingy; + return _get_name_by_Z( $thingy, $language ) if _is_Z $thingy; + + #maybe it's already a name, might have to translate it + if( _is_name $thingy ) + { + my $Z = _get_Z_by_name( $thingy ); + return _get_name_by_Z( $Z, $language ); + } + + #we were passed something wierd. pretend we don't know anything. + return; + } + + +sub _get_name_by_symbol { + my $symbol = shift; + + return unless _is_symbol $symbol; + + my $language = defined $_[0] ? $_[0] : $Default_language; + + my $Z = _get_Z_by_symbol($symbol); + + return _get_name_by_Z( $Z, $language ); + } + +sub _get_name_by_Z { + my $Z = shift; + my $language = defined $_[0] ? $_[0] : $Default_language; + + return unless _is_Z $Z; + + #not much we can do if they don't pass a proper number + # XXX: check for language? + return $names{$Z}[$language]; + } + +sub get_Z { + my $thingy = shift; + + croak "Can't call get_Z on object. Use Z instead" if ref $thingy; + + #since we were asked for a name, we'll suppose that we were passed + #either a chemical symbol or a Z. + return _get_Z_by_symbol( $thingy ) if _is_symbol( $thingy ); + return _get_Z_by_name( $thingy ) if _is_name( $thingy ); + + #maybe it's already a Z + return $thingy if _is_Z( $thingy ); + + return; + } + +# gets the proton number for the name, no matter which language it +# is in +sub _get_Z_by_name { + my $name = lc shift; + + $names_to_Z{$name}; # language agnostic + } + +sub _get_Z_by_symbol { + my $symbol = _format_symbol( shift ); + + return $elements{$symbol} if exists $elements{$symbol}; + + return; + } + +######################################################################## +######################################################################## +# +# the _is_* functions do some minimal data checking to help other +# functions guess what sort of input they received + +######################################################################## +sub _is_name { exists $names_to_Z{ lc shift } ? 1 : 0 } + +######################################################################## +sub _is_symbol { + my $symbol = _format_symbol( $_[0] ); + + exists $elements{$symbol} ? 1 : (); + } + +######################################################################## +sub _is_Z { $_[0] =~ /^[123456789]\d*\z/ && exists $elements{$_[0]} } + +######################################################################## +# _format_symbol +# +# input: a string that is supoosedly a chemical symbol +# output: the string with the first character in uppercase and the +# rest lowercase +# +# there is no data checking involved. this function doens't know +# and doesn't care if the data are valid. it just does its thing. +sub _format_symbol { $_[0] =~ m/^[a-z]/i && ucfirst lc $_[0] } + +######################################################################## +# _format_name +# +# input: a string that is supoosedly a chemical element's name +# output: the string with the first character in uppercase and the +# rest lowercase +# +# there is no data checking involved. this function doens't know +# and doesn't care if the data are valid. it just does its thing. +# +# this looks like _format_symbol, but it logically isn't. someday +# it might do something different than _format_symbol +sub _format_name { + my $data = shift; + + $data =~ s/^(.)(.*)/uc($1).lc($2)/e; + + return $data; + } + +######################################################################## +sub AUTOLOAD { + my $self = shift; + my $data = shift; + + return unless ref $self; + + my $method_name = $AUTOLOAD; + + $method_name =~ s/.*:://; + + if( $data ) + { # only add new method if they add data + $self->{$method_name} = $data; + $self->_add_object_method( $method_name ); + } + elsif( defined $self->{$method_name} ) { return $self->{$method_name} } + else { return } + + } + +1; + +__END__ + +=encoding utf8 + +=head1 NAME + +Chemistry::Elements - Perl extension for working with Chemical Elements + +=head1 SYNOPSIS + + use 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 + +=head1 DESCRIPTION + +There 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 L</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' + +=head2 Instance methods + +=over 4 + +=item new( Z | SYMBOL | NAME ) + +Create a new instance from either the atomic number, symbol, or +element name. + +=item can( METHOD [, METHOD ... ] ) + +Returns true if the package or object can respond to METHOD. This +distinguishes between class and instance methods. + +=item Z + +Return the atomic number of the element. + +=item name + +Return the name of the element. + +=item symbol + +Return the symbol of the element. + +=back + +=head2 Exportable functions + +These functions can be exported. They are not exported by default. At the +moment, only the functional interface supports multi-language names. + +=over 4 + +=item get_symbol( NAME|Z ) + +This function attempts to return the symbol of the chemical element given +either the chemical symbol, element name, or atmoic number. The +function does its best to interpret inconsistent input data (e.g. +chemcial symbols of mixed and single case). + + use Chemistry::Elements qw(get_symbol); + + $name = get_symbol('Fe'); #$name is 'Fe' + $name = get_symbol('fe'); #$name is 'Fe' + $name = get_symbol(26); #$name is 'Fe' + $name = get_symbol('Iron'); #$name is 'Fe' + $name = get_symbol('iron'); #$name is 'Fe' + +If no symbol can be found, nothing is returned. + +Since this function will return the symbol if it is given a symbol, +you can use it to test whether a string is a chemical symbol +(although you have to play some tricks with case since get_symbol +will try its best despite the case of the input data). + + if( lc($string) eq lc( get_symbol($string) ) ) + { + #stuff + } + +You can modify the symbols (e.g. you work for UCal ;) ) by changing +the data at the end of this module. + +=item get_name( SYMBOL|NAME|Z [, LANGUAGE] ) + +This function attempts to return the name the chemical element given +either the chemical symbol, element name, or atomic number. The +function does its best to interpret inconsistent input data (e.g. +chemical symbols of mixed and single case). + + $name = get_name('Fe'); #$name is 'Iron' + $name = get_name('fe'); #$name is 'Iron' + $name = get_name(26); #$name is 'Iron' + $name = get_name('Iron'); #$name is 'Iron' + $name = get_name('iron'); #$name is 'Iron' + +If no Z can be found, nothing is returned. + +Since this function will return the name if it is given a name, +you can use it to test whether a string is a chemical element name +(although you have to play some tricks with case since get_name +will try its best despite the case of the input data). + + if( lc($string) eq lc( get_name($string) ) ) + { + #stuff + } + +You can modify the names (e.g. for different languages) by changing +the data at the end of this module. + +=item get_Z( SYMBOL|NAME|Z ) + +This function attempts to return the atomic number of the chemical +element given either the chemical symbol, element name, or atomic +number. The function does its best to interpret inconsistent input data +(e.g. chemcial symbols of mixed and single case). + + $name = get_Z('Fe'); #$name is 26 + $name = get_Z('fe'); #$name is 26 + $name = get_Z(26); #$name is 26 + $name = get_Z('Iron'); #$name is 26 + $name = get_Z('iron'); #$name is 26 + +If no Z can be found, nothing is returned. + +Since this function will return the Z if it is given a Z, +you can use it to test whether a string is an atomic number. +You might want to use the string comparison in case the +$string is not a number (in which case the comparison +will be false save for the case when $string is undefined). + + if( $string eq get_Z($string) ) { + #stuff + } + +=back + +The package constructor automatically finds the largest defined +atomic number (in case you add your own heavy elements). + +=head2 AUTOLOADing methods + +You 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 :) + +=head2 Localization support + +XXX: Fill this stuff in later. For now see the test suite + +=head1 TO DO + +I 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 :) + +=head1 SOURCE AVAILABILITY + +The source for this module is in Github: + + https://github.com/briandfoy/chemistry-elements + +=head1 AUTHOR + +brian d foy, C<< <bdfoy@cpan.org> >> + +=head1 COPYRIGHT AND LICENSE + +Copyright © 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. + +=cut @@ -0,0 +1,34 @@ +#!/usr/bin/perl + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; + +use_ok( $class ); +ok( defined &{"${class}::can"}, "$class defines its own can" ); + +my $element = $class->new( 'U' ); +isa_ok( $element, $class ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# try something that should return true +ok( $element->can('Z'), 'Object can call the Z method' ); + +is( $element->Z, 92, "Got right Z for U" ); +is( $element->symbol, 'U', "Got right symbol for U" ); +is( $element->name, 'Uranium', "Got right name for U (Default)" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Change the Z +is( $element->Z(94), 94, "Got right Z for Pu after U decay" ); +is( $element->symbol, 'Pu', "Got right symbol for Pu" ); +is( $element->name, 'Plutonium', "Got right name for Pu (Default)" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Change the Z to nonsense +ok( ! $element->Z('Pa'), "Could not change Z to symbol" ); +ok( ! $element->Z('Technetium'), "Could not change Z to symbol" ); +ok( ! $element->Z(''), "Could not change Z to empty string" ); +ok( ! $element->Z(undef), "Could not change Z to undef" ); +ok( ! $element->Z(0), "Could not change Z to 0" ); +ok( ! $element->Z(200), "Could not change Z to 200" ); diff --git a/t/_get_Z_by_name.t b/t/_get_Z_by_name.t new file mode 100644 index 0000000..8f5f6de --- /dev/null +++ b/t/_get_Z_by_name.t @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +package Chemistry::Elements; + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; +my $sub = '_get_Z_by_name'; + +use_ok( $class ); +ok( defined &{"${class}::$sub"}, "$sub defined" ); + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Stuff that should work +foreach my $name ( qw( Hydrogen Ydrogenhai ) ) + { + my $Z = _get_Z_by_name( $name ); + is( $Z, 1, "Z for $name is right" ); + } + +foreach my $name ( qw( Oldgai Gold ) ) + { + my $Z = _get_Z_by_name( $name ); + is( $Z, 79, "Z for $name is right" ); + } + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Stuff that shouldn't work +foreach my $name ( qw( Foo Bar Bax ), undef, 0, '', ) + { + no warnings 'uninitialized'; + my $Z = _get_Z_by_name( $name ); + is( "$Z", "", "Z for $name is undefined" ); + } + diff --git a/t/_get_Z_by_symbol.t b/t/_get_Z_by_symbol.t new file mode 100644 index 0000000..5fccbff --- /dev/null +++ b/t/_get_Z_by_symbol.t @@ -0,0 +1,23 @@ +#!/usr/bin/perl + +package Chemistry::Elements; + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; +my $sub = '_get_Z_by_symbol'; + +use_ok( $class ); +ok( defined &{"${class}::$sub"}, "$sub defined" ); + +is( _get_Z_by_symbol('Po'), 84, "Got right Z for Po" ); +is( _get_Z_by_symbol('Pb'), 82, "Got right Z for Pb" ); +is( _get_Z_by_symbol('Ne'), 10, "Got right Z for Ne" ); +is( _get_Z_by_symbol('La'), 57, "Got right Z for La" ); +is( _get_Z_by_symbol('H'), 1, "Got right Z for H" ); + + +ok( ! _get_Z_by_symbol( '' ), "empty string isn't a symbol" ); +ok( ! _get_Z_by_symbol( undef ), "undef isn't a symbol" ); +ok( ! _get_Z_by_symbol( 'Foo' ), "Foo isn't a symbol" ); +ok( ! _get_Z_by_symbol( '86' ), "86 isn't a symbol" ); diff --git a/t/_get_name_by_Z.t b/t/_get_name_by_Z.t new file mode 100644 index 0000000..99dd4d1 --- /dev/null +++ b/t/_get_name_by_Z.t @@ -0,0 +1,42 @@ +#!/usr/bin/perl + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; + +use_ok( $class ); +ok( defined &{"${class}::_get_name_by_Z"}, "_get_name_by_Z defined" ); + +package Chemistry::Elements; + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Default language, as English +is( _get_name_by_Z(1), 'Hydrogen', 'Works of H in default language' ); +is( _get_name_by_Z(6), 'Carbon', 'Works of C in default language' ); + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Default language, as Pig Latin +{ +local $Default_language; +$Default_language = $Languages{'Pig Latin'}; + +is( _get_name_by_Z(1), 'Ydrogenhai', 'Works of H in changed default language' ); +is( _get_name_by_Z(90), 'Horiumtai', 'Works of Th in changed default language' ); +} + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Specify language, as English +is( _get_name_by_Z( 1, $Languages{'English'} ), 'Hydrogen', 'Works of H in specified language (English)' ); +is( _get_name_by_Z( 6, $Languages{'English'} ), 'Carbon', 'Works of C in specified language (English)' ); + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Specify language, as Pig Latin +is( _get_name_by_Z( 1, $Languages{'Pig Latin'} ), 'Ydrogenhai', 'Works of H in specified language (Pig Latin)' ); +is( _get_name_by_Z( 82, $Languages{'Pig Latin'} ), 'Eadlai', 'Works of H in specified language (Pig Latin)' ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Stuff that shouldn't work +is( _get_name_by_Z(undef), undef, 'Fails for undef' ); +is( _get_name_by_Z('Foo'), undef, 'Fails for Foo' ); diff --git a/t/_get_name_by_symbol.t b/t/_get_name_by_symbol.t new file mode 100644 index 0000000..4ed2e40 --- /dev/null +++ b/t/_get_name_by_symbol.t @@ -0,0 +1,37 @@ +#!/usr/bin/perl + +package Chemistry::Elements; + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; +my $sub = '_get_name_by_symbol'; + +use_ok( $class ); +ok( defined &{"${class}::$sub"}, "$sub defined" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Stuff that should work, default language +is( _get_name_by_symbol( 'F' ), 'Fluorine', "Get right name for F (Default)" ); +is( _get_name_by_symbol( 'Ar' ), 'Argon', "Get right name for Ar (Default)" ); +is( _get_name_by_symbol( 'Xe' ), 'Xenon', "Get right name for Xe (Default)" ); + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Stuff that should work, English +is( _get_name_by_symbol( 'F', $Languages{'English'} ), 'Fluorine', "Get right name for F (English)" ); +is( _get_name_by_symbol( 'Ar', $Languages{'English'} ), 'Argon', "Get right name for Ar (English)" ); +is( _get_name_by_symbol( 'Xe', $Languages{'English'} ), 'Xenon', "Get right name for Xe (English)" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Stuff that should work, Pig Latin +is( _get_name_by_symbol( 'F', $Languages{'Pig Latin'} ), 'Luorinefai', "Get right name for F (Pig Latin)" ); +is( _get_name_by_symbol( 'Ar', $Languages{'Pig Latin'} ), 'Rgonaai', "Get right name for Ar (Pig Latin)" ); +is( _get_name_by_symbol( 'Xe', $Languages{'Pig Latin'} ), 'Enonxai', "Get right name for Xe (Pig Latin)" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Stuff that shouldn't work +ok( ! defined _get_name_by_symbol( '' ), "No symbol from empty string" ); +ok( ! defined _get_name_by_symbol( undef ), "No name from undef" ); +ok( ! defined _get_name_by_symbol( ), "No name from no args" ); +ok( ! defined _get_name_by_symbol( 0 ), "No name from 0" ); diff --git a/t/_get_symbol_by_Z.t b/t/_get_symbol_by_Z.t new file mode 100644 index 0000000..e716ed9 --- /dev/null +++ b/t/_get_symbol_by_Z.t @@ -0,0 +1,24 @@ +#!/usr/bin/perl + +package Chemistry::Elements; + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; +my $sub = '_get_symbol_by_Z'; + +use_ok( $class ); +ok( defined &{"${class}::$sub"}, "$sub defined" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Stuff that should work, default language +is( _get_symbol_by_Z( 46 ), 'Pd', "Get right symbol for 46" ); +is( _get_symbol_by_Z( 32 ), 'Ge', "Get right symbol for 32" ); +is( _get_symbol_by_Z( 61 ), 'Pm', "Get right symbol for 61" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Stuff that shouldn't work +ok( ! defined _get_symbol_by_Z( '' ), "No symbol from empty string" ); +ok( ! defined _get_symbol_by_Z( undef ), "No symbol from undef" ); +ok( ! defined _get_symbol_by_Z( ), "No symbol from no args" ); +ok( ! defined _get_symbol_by_Z( 0 ), "No symbol from 0" ); diff --git a/t/_get_symbol_by_name.t b/t/_get_symbol_by_name.t new file mode 100644 index 0000000..6ca9984 --- /dev/null +++ b/t/_get_symbol_by_name.t @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +package Chemistry::Elements; + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; +my $sub = '_get_symbol_by_name'; + +use_ok( $class ); +ok( defined &{"${class}::$sub"}, "$sub defined" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Stuff that should work +is( _get_symbol_by_name( 'Calcium' ), 'Ca', "Get right name for F (English)" ); +is( _get_symbol_by_name( 'Magnesium' ), 'Mg', "Get right name for Ar (English)" ); +is( _get_symbol_by_name( 'Chlorine' ), 'Cl', "Get right name for Xe (English)" ); + +is( _get_symbol_by_name( 'Alciumcai' ), 'Ca', "Get right name for F (Pig Latin)" ); +is( _get_symbol_by_name( 'Agnesiummai' ), 'Mg', "Get right name for Ar (Pig Latin)" ); +is( _get_symbol_by_name( 'Hlorinecai' ), 'Cl', "Get right name for Xe (Pig Latin)" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Stuff that shouldn't work +ok( ! defined _get_symbol_by_name( '' ), "No symbol from empty string" ); +ok( ! defined _get_symbol_by_name( undef ), "No name from undef" ); +ok( ! defined _get_symbol_by_name( ), "No name from no args" ); +ok( ! defined _get_symbol_by_name( 0 ), "No name from 0" ); diff --git a/t/_is_Z.t b/t/_is_Z.t new file mode 100644 index 0000000..3a4c752 --- /dev/null +++ b/t/_is_Z.t @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +package Chemistry::Elements; +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; +my $sub = '_is_Z'; + +use_ok( $class ); +ok( defined &{"${class}::$sub"}, "$sub defined" ); + + + +ok( _is_Z( $_ ), "$_ is a Z" ) for 1 .. 106; + +ok( ! _is_Z( $_ + 0.1 ), "$_.1 is not a Z" ) for 10 .. 20; + +ok( ! _is_Z( '' ), "empty string isn't a Z" ); +ok( ! _is_Z( undef ), "undef isn't a Z" ); +ok( ! _is_Z( 'Foo' ), "Foo isn't a Z" ); +ok( ! _is_Z( 'Po' ), "Po isn't a Z" ); +ok( ! _is_Z( 0 ), "0 isn't a Z" ); diff --git a/t/_is_name.t b/t/_is_name.t new file mode 100644 index 0000000..def77b9 --- /dev/null +++ b/t/_is_name.t @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +package Chemistry::Elements; + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; +my $sub = '_is_name'; + +use_ok( $class ); +ok( defined &{"${class}::$sub"}, "$sub defined" ); + + +ok( _is_name( 'Oxygen' ), "Oxygen is a name" ); +ok( _is_name( 'Xygenoai' ), "Xygenoai is a name" ); + +ok( ! _is_name( '' ), "empty string isn't a name" ); +ok( ! _is_name( undef ), "undef isn't a name" ); +ok( ! _is_name( 'Foo' ), "Foo isn't a name" ); +ok( ! _is_name( 'Po' ), "Po isn't a name" ); diff --git a/t/_is_symbol.t b/t/_is_symbol.t new file mode 100644 index 0000000..0b1da05 --- /dev/null +++ b/t/_is_symbol.t @@ -0,0 +1,21 @@ +#!/usr/bin/perl + +package Chemistry::Elements; + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; +my $sub = '_is_symbol'; + +use_ok( $class ); +ok( defined &{"${class}::$sub"}, "$sub defined" ); + + +ok( _is_symbol( 'Po' ), "Po is a symbol" ); +ok( _is_symbol( 'Sg' ), "Sg is a symbol" ); +ok( _is_symbol( 'Ha' ), "Ha is a symbol" ); + +ok( ! _is_symbol( '' ), "empty string isn't a symbol" ); +ok( ! _is_symbol( undef ), "undef isn't a symbol" ); +ok( ! _is_symbol( 'Foo' ), "Foo isn't a symbol" ); +ok( ! _is_symbol( '86' ), "Po isn't a symbol" ); diff --git a/t/autoload.t b/t/autoload.t new file mode 100644 index 0000000..d767dfd --- /dev/null +++ b/t/autoload.t @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; +my $sub = 'get_symbol'; + +use_ok( $class, $sub ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Object interface with something that works +{ +my $element = $class->new( 'Erbium' ); +isa_ok( $element, $class ); + +is( $element->Z, 68 ); +is( $element->name, 'Erbium' ); +is( $element->symbol, 'Er' ); + +ok( $element->molar_mass( 167.26 ), 'Set molar mass for Er' ); + +ok( $element->can( 'molar_mass' ), "Now I can call molar_mass" ); + +is( $element->molar_mass, 167.26, 'Got back same value for molar mass' ); +} + @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; + +use_ok( $class ); +ok( defined &{"${class}::can"}, "$class defines its own can" ); + +my $object = $class->new( 'U' ); +isa_ok( $object, $class ); + +# try something that should return true +ok( $object->can('Z'), 'Object can call the Z method' ); + +# try something that is a defined sub but should return false +ok( ! $object->can('get_Z'), 'Object can call the Z method' ); + +# try something that is not a defined sub (and should return false) +ok( ! $object->can('not_there'), 'Object can call the Z method' ); + +# try it as a class method, which should fail +ok( ! defined $class->can('Z'), "Can't call Z as a class method" ); +ok( ! defined $class->can('name'), "Can't call Z as a class method" ); + +# try is as a class method, when it should work +ok( $class->can('isa'), "Can call isa as a class method" ); +ok( $class->can('can'), "Can call can as a class method" ); diff --git a/t/compile.t b/t/compile.t new file mode 100644 index 0000000..6124a06 --- /dev/null +++ b/t/compile.t @@ -0,0 +1,11 @@ +BEGIN { + @classes = qw( Chemistry::Elements ); + } + +use Test::More tests => scalar @classes; + +foreach my $class ( @classes ) + { + print "bail out! $class did not compile" unless use_ok( $class ); + } + diff --git a/t/get_Z.t b/t/get_Z.t new file mode 100644 index 0000000..081ac60 --- /dev/null +++ b/t/get_Z.t @@ -0,0 +1,46 @@ +#!/usr/bin/perl + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; + +use_ok( $class, qw( get_Z ) ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Object interface shouldn't work +{ +my $element = $class->new( 'Erbium' ); +isa_ok( $element, $class ); + +ok( ! $element->can( 'get_Z' ), 'can() says get_Z is not there (good)' ); + +eval { $element->get_Z }; +ok( defined $@, "Calling get_Z as object method fails (good)" ); +} + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Functional interface, stuff that works +{ +ok( defined &get_Z, "get_Z is in the current namespace" ); + +is( get_Z( 'Erbium' ), 68, 'Got the right Z for Erbium' ); +is( get_Z( 72 ), 72, 'Got the right Z for 72' ); +is( get_Z( 'Po' ), 84, 'Got the right Z for Po' ); + +} + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Functional interface, stuff that shouldn't work +{ + +is( get_Z( -1 ), undef, 'Got undef for -1' ); +is( get_Z( 0 ), undef, 'Got undef for 0' ); +is( get_Z( ), undef, 'Got undef for no args' ); +is( get_Z( undef ), undef, 'Got undef for undef' ); +is( get_Z( '' ), undef, 'Got undef for empty string' ); +is( get_Z( 'Unh' ), undef, 'Got undef for Unh' ); +is( get_Z( 'Foo' ), undef, 'Got undef for Foo' ); +is( get_Z( 82.1 ), undef, 'Got undef for 82.0' ); + + +}
\ No newline at end of file diff --git a/t/get_name.t b/t/get_name.t new file mode 100644 index 0000000..612654f --- /dev/null +++ b/t/get_name.t @@ -0,0 +1,38 @@ +#!/usr/bin/perl + +package Chemistry::Elements; + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; + +use_ok( $class, qw(get_name) ); +ok( defined &get_name, "get_name is defined" ); + +is( get_name( 'H' ), 'Hydrogen' ); +is( get_name( 'Hydrogen' ), 'Hydrogen' ); +is( get_name( '1' ), 'Hydrogen' ); + +is( get_name( 'Si', $Languages{'English'} ), 'Silicon' ); +is( get_name( 'Silicon', $Languages{'English'} ), 'Silicon' ); +is( get_name( '14', $Languages{'English'} ), 'Silicon' ); + +is( get_name( 'He', $Languages{'Pig Latin'} ), 'Eliumhai' ); +is( get_name( 'Helium', $Languages{'Pig Latin'} ), 'Eliumhai' ); +is( get_name( '2', $Languages{'Pig Latin'} ), 'Eliumhai' ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Functional interface, stuff that shouldn't work +{ + +is( get_name( -1 ), undef, 'Got undef for -1' ); +is( get_name( 0 ), undef, 'Got undef for 0' ); +is( get_name( ), undef, 'Got undef for no args' ); +is( get_name( undef ), undef, 'Got undef for undef' ); +is( get_name( '' ), undef, 'Got undef for empty string' ); +is( get_name( 'Unh' ), undef, 'Got undef for Unh' ); +is( get_name( 'Foo' ), undef, 'Got undef for Foo' ); +is( get_name( 82.1 ), undef, 'Got undef for 82.0' ); + + +}
\ No newline at end of file diff --git a/t/get_symbol.t b/t/get_symbol.t new file mode 100644 index 0000000..bcbae08 --- /dev/null +++ b/t/get_symbol.t @@ -0,0 +1,47 @@ +#!/usr/bin/perl + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; +my $sub = 'get_symbol'; + +use_ok( $class, $sub ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Object interface +{ +my $element = $class->new( 'Erbium' ); +isa_ok( $element, $class ); + +ok( ! $element->can( $sub ), "can() says $sub is not there (good)" ); + +eval { $element->get_Z }; +ok( defined $@, "Calling $sub as object method fails (good)" ); +} + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Functional interface +{ +ok( defined &get_symbol, "$sub is in the current namespace" ); + +is( get_symbol( 'Plutonium' ), 'Pu', 'Got the right symbol for Plutonium (English)' ); +is( get_symbol( 'Lutoniumpai' ), 'Pu', 'Got the right symbol for Lutoniumpai (Pig Latin)' ); +is( get_symbol( 18 ), 'Ar', 'Got the right symbol for 18' ); +is( get_symbol( 'Rh' ), 'Rh', 'Got the right symbol for Rh' ); +} + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Functional interface, stuff that shouldn't work +{ + +is( get_symbol( -1 ), undef, 'Got undef for -1' ); +is( get_symbol( 0 ), undef, 'Got undef for 0' ); +is( get_symbol( ), undef, 'Got undef for no args' ); +is( get_symbol( undef ), undef, 'Got undef for undef' ); +is( get_symbol( '' ), undef, 'Got undef for empty string' ); +is( get_symbol( 'Unh' ), undef, 'Got undef for Unh' ); +is( get_symbol( 'Foo' ), undef, 'Got undef for Foo' ); +is( get_symbol( 82.1 ), undef, 'Got undef for 82.0' ); + + +}
\ No newline at end of file diff --git a/t/name.t b/t/name.t new file mode 100644 index 0000000..d021030 --- /dev/null +++ b/t/name.t @@ -0,0 +1,38 @@ +#!/usr/bin/perl + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; + +use_ok( $class ); +ok( defined &{"${class}::can"}, "$class defines its own can" ); + +my $element = $class->new( 'U' ); +isa_ok( $element, $class ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# try something that should return true +ok( $element->can('name'), 'Object can call the name method' ); + +is( $element->Z, 92, "Got right Z for U" ); +is( $element->symbol, 'U', "Got right symbol for U" ); +is( $element->name, 'Uranium', "Got right name for U (Default)" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Change the name to something that will work +is( $element->name('Plutonium'), 'Plutonium', "Got right name for Pu after U decay" ); +is( $element->symbol, 'Pu', "Got right symbol for Pu" ); +is( $element->Z, 94, "Got right Z for Pu (Default)" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Change the name to something that won't work +ok( ! $element->name(''), "Can't change name to empty string" ); +ok( ! $element->name(undef), "Can't change name to undef" ); +ok( ! $element->name(0), "Can't change name to 0" ); +ok( ! $element->name(-1), "Can't change name to -1" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# This should still be the same element +is( $element->name, 'Plutonium', "Got right name for Pu after U decay" ); +is( $element->symbol, 'Pu', "Got right symbol for Pu" ); +is( $element->Z, 94, "Got right Z for Pu (Default)" ); @@ -0,0 +1,69 @@ +#!/usr/bin/perl + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; +my $sub = 'get_symbol'; + +use_ok( $class, $sub ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Object interface with something that works +{ +my $element = $class->new( 'Erbium' ); +isa_ok( $element, $class ); + +is( $element->Z, 68 ); +is( $element->name, 'Erbium' ); +is( $element->symbol, 'Er' ); +} + +{ +my $element = $class->new( 'Er' ); +isa_ok( $element, $class ); + +is( $element->Z, 68 ); +is( $element->name, 'Erbium' ); +is( $element->symbol, 'Er' ); +} + +{ +my $element = $class->new( 68 ); +isa_ok( $element, $class ); + +is( $element->Z, 68 ); +is( $element->name, 'Erbium' ); +is( $element->symbol, 'Er' ); +} + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Object interface with something that doesn't work +{ +my $element = $class->new( 'Administrativium' ); +ok( ! defined $element, "Can't make a fake element" ); +} + +{ +my $element = $class->new( ); +ok( ! defined $element, "Can't make a fake element" ); +} + +{ +my $element = $class->new( undef ); +ok( ! defined $element, "Can't make a fake element" ); +} + +{ +my $element = $class->new( '' ); +ok( ! defined $element, "Can't make a fake element" ); +} + +{ +my $element = $class->new( 0 ); +ok( ! defined $element, "Can't make a fake element" ); +} + +{ +my $element = $class->new( -1 ); +ok( ! defined $element, "Can't make a fake element" ); +} @@ -0,0 +1,4 @@ +use Test::More; +eval "use Test::Pod 1.00"; +plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; +all_pod_files_ok(); diff --git a/t/pod_coverage.t b/t/pod_coverage.t new file mode 100644 index 0000000..2ceb94e --- /dev/null +++ b/t/pod_coverage.t @@ -0,0 +1,4 @@ +use Test::More tests => 1; +eval "use Test::Pod::Coverage"; + +pass; diff --git a/t/symbol.t b/t/symbol.t new file mode 100644 index 0000000..0b77416 --- /dev/null +++ b/t/symbol.t @@ -0,0 +1,38 @@ +#!/usr/bin/perl + +use Test::More 'no_plan'; + +my $class = 'Chemistry::Elements'; + +use_ok( $class ); +ok( defined &{"${class}::can"}, "$class defines its own can" ); + +my $element = $class->new( 'U' ); +isa_ok( $element, $class ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# try something that should return true +ok( $element->can('symbol'), 'Object can call the symbol method' ); + +is( $element->Z, 92, "Got right Z for U" ); +is( $element->symbol, 'U', "Got right symbol for U" ); +is( $element->name, 'Uranium', "Got right name for U (Default)" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Change the name to something that will work +is( $element->symbol('Pu'), 'Pu', "Got right name for Pu after U decay" ); +is( $element->name, 'Plutonium', "Got right name for Pu" ); +is( $element->Z, 94, "Got right Z for Pu (Default)" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Change the name to something that won't work +ok( ! $element->symbol(''), "Can't change name to empty string" ); +ok( ! $element->symbol(undef), "Can't change name to undef" ); +ok( ! $element->symbol(0), "Can't change name to 0" ); +ok( ! $element->symbol(-1), "Can't change name to -1" ); + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# This should still be the same element +is( $element->name, 'Plutonium', "Got right name for Pu after U decay" ); +is( $element->symbol, 'Pu', "Got right symbol for Pu" ); +is( $element->Z, 94, "Got right name for Pu (Default)" ); diff --git a/t/test_manifest b/t/test_manifest new file mode 100644 index 0000000..ab063e8 --- /dev/null +++ b/t/test_manifest @@ -0,0 +1,22 @@ +compile.t +pod.t +pod_coverage.t +can.t +_is_Z.t +_is_symbol.t +_get_Z_by_symbol.t +_is_name.t +_get_Z_by_name.t +_get_Z_by_symbol.t +_get_name_by_Z.t +_get_name_by_symbol.t +_get_symbol_by_Z.t +_get_symbol_by_name.t +get_Z.t +get_name.t +get_symbol.t +new.t +Z.t +name.t +symbol.t +autoload.t diff --git a/xt/changes.t b/xt/changes.t new file mode 100644 index 0000000..a9831b3 --- /dev/null +++ b/xt/changes.t @@ -0,0 +1,4 @@ +use Test::More; +eval 'use Test::CPAN::Changes'; +plan skip_all => 'Test::CPAN::Changes required for this test' if $@; +changes_ok(); |