1 2use strict; 3use warnings; 4use Module::Build; 5use File::Spec; 6 7# Automatically create Telescope/MPC.pm. 8my $class = Module::Build->subclass( 9 class => "Module::Build::CustomAstroTelescope", 10 code => join( "", <DATA> ), 11 ); 12 13my $file = File::Spec->catfile( "lib", "Astro", "Telescope.pm" ); 14 15# Now configure it further 16my $build = $class->new 17 ( 18 module_name => 'Astro::Telescope', 19 license => 'perl', 20 abstract_from => $file, 21 version_from => $file, 22 dist_author => [ 23 'Tim Jenness <tjenness@cpan.org>', 24 'Brad Cavanagh <bradc@cpan.org>', 25 ], 26 meta_merge => { 27 resources => { 28 repository => "git://github.com/timj/perl-Astro-Telescope.git", 29 homepage => "http://github.com/timj/perl-Astro-Telescope/tree/master", 30 }, 31 }, 32 configure_requires => { 33 "Module::Build" => 0.30, 34 }, 35 requires => { 36 'Astro::PAL' => 0.99, 37 }, 38 build_requires => { 39 'Test::More' => 0, 40 }, 41 ); 42 43$build->create_build_script; 44 45# This is the subclass code to handle dynamic generation of the git version 46# status when running Build 47# Always generate this file. The overhead is small and we want to make sure that 48# it is correct whenever the module is built. No reason to use something cleverer. 49__DATA__ 50 51use File::Spec; 52use warnings; 53use strict; 54 55sub ACTION_build { 56 57 my $self = shift; 58 59 print "Generating MPC lookup table support module Astro::Telescope::MPC...\n"; 60 61 # Locations of input and output files 62 my $mpc_data = File::Spec->catfile("tmpl", "MPC.dat"); 63 my $mpc_dir = File::Spec->catdir("lib", "Astro", "Telescope"); 64 my $mpc_pm = File::Spec->catfile($mpc_dir, "MPC.pm"); 65 66 # Create output directory 67 if ( !-d $mpc_dir) { 68 mkdir $mpc_dir 69 or die "Error creating MPC module. Unable to make directory $mpc_dir: $!"; 70 } 71 72 # Open the input and output handles 73 open(my $MPC_DATA_FH, $mpc_data) || 74 die "Unable to open MPC stub file $mpc_data : $!\n"; 75 open(my $MPC_PM_FH, ">", "$mpc_pm") || 76 die "Unable to open MPC stub file $mpc_pm : $!\n"; 77 78 # Write out the module code 79 print $MPC_PM_FH q| 80 81# This file has been generated automatically by the 82# Astro::Telescope build system. Do not edit directly. 83# Edit Build.PL or tmpl/MPC.dat instead. 84 85package Astro::Telescope::MPC; 86 87use strict; 88use warnings; 89use vars qw/ %obs_codes /; 90 91use constant DD2R => 0.017453292519943295769236907684886127134428718885417; 92 93sub parse_table { 94 my $self = shift; 95 return if %obs_codes; 96 97 for (<DATA>) { 98 my($code, $long, $par_S, $par_C, $mpcname) = unpack("A3A10A8A9A*", $_); 99 next unless $long =~ /\d/; # Space telescope 100 $obs_codes{$code} = { Long => ($long * DD2R), 101 Par_S => $par_S, 102 Par_C => $par_C, 103 Name => $mpcname, 104 }; 105 } 106 107} 108 1091; 110__DATA__ 111|; 112 113 while(<$MPC_DATA_FH>) { 114 print $MPC_PM_FH $_; 115 } 116 close $MPC_DATA_FH || die "Error closing data input file: $!"; 117 close $MPC_PM_FH || die "Error closing output module: $!"; 118 119 $self->SUPER::ACTION_build; 120} 121 122# Remove the file on clean 123sub ACTION_clean { 124 my $self = shift; 125 # Ignore errors 126 unlink File::Spec->catfile( "lib", "Astro", "Telescope", "MPC.pm" ); 127 $self->SUPER::ACTION_clean; 128} 129 130