Astro-Constants
view release on metacpan or search on metacpan
script/add_constant.pl view on Meta::CPAN
#!/usr/bin/perl -w
#
# Adds a constant to PhysicalConstants.xml
# Boyd Duffee, July 2017 & April 2024
#
# validation is not fatal, it only warns of errors
use v5.10;
use autodie;
use FindBin qw($Bin);
use XML::LibXML;
my $file = $ARGV[0] || "$Bin/../data/PhysicalConstants.xml";
die "Can't file $file\n" unless -f $file;
my $schema_file = $file;
$schema_file =~ s/\.xml$/.xsd/;
my $bak = $file . '.bak';
die "Script won't overwrite backup file $bak Stopping.\n" if -f $bak;
my $xml = XML::LibXML->load_xml(location => $file, no_blanks => 1);
my ($name, $description, $value, $precision, $category_list, @categories,
$dimensions, $minValue, $maxValue, $source, );
my %category = ( fundamental => 1 , cosmology => 1, electromagnetic => 1,
planetary => 1, conversion => 1, nuclear => 1, mathematical => 1,
);
my $add_constant = 1;
while ($add_constant) {
get_constant_definition();
print 'Add another constant? [y/N] ';
my $ans = <STDIN>;
$add_constant = 0 unless $ans =~ /^y/i;
}
write_entries();
exit;
sub populate_fields {
get_name();
check_not_a_duplicate() or return;
get_description();
get_value();
get_precision();
get_dimensions();
get_source();
get_categories();
}
sub get_constant_definition {
do {
populate_fields();
} while ( edit_fields() );
append_to_list();
}
sub edit_fields {
print <<"EDIT";
I have the following values for your new PhysicalConstant
name [required]\t $name
description\t $description
value (in SI)\t $value
precision\t $precision
categories\t $category_list
Do you want to make any changes to this definition? [Y/n]
EDIT
my $ans = <STDIN>;
return $ans !~ /^n/i ? 1 : 0;
}
sub write_entries {
( run in 3.144 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )