| 1 | package Astro::Hipparcos; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = '0.09'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use constant LINE_LENGTH => 451; # I wish they were using a modern file format. | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | require XSLoader; | |||||||||||||||||||||||||||
| 14 | 1 | XSLoader::load('Astro::Hipparcos', $VERSION); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=19.1
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 18 | 1 | my $file = shift; | |||||||||||||||||||||||||||
| 19 | 1 | ▶ | croak("Need catalog file") if not defined $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | if (not -e $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | open my $fh, '>', $file or die "Could not open file '$file' for writing: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 0 | close $fh; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 1 | ▶ | open my $fh, '+<', $file or die "Could not open file '$file' for reading/writing: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 1 | my $self = bless { | |||||||||||||||||||||||||||
| 26 | fh => $fh, | ||||||||||||||||||||||||||||
| 27 | filename => $file, | ||||||||||||||||||||||||||||
| 28 | filesize => (-s $file), | ||||||||||||||||||||||||||||
| 29 | abs_file => File::Spec->rel2abs($file), | ||||||||||||||||||||||||||||
| 30 | } => $class; | ||||||||||||||||||||||||||||
| 31 | 1 | return $self; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 9 | ▶ | sub get_record { | ||||||||||||||||||||||||||
|
Subroutine
get_record: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 36 | 9 | my $recno = shift; | |||||||||||||||||||||||||||
| 37 | 9 | my $line; | |||||||||||||||||||||||||||
| 38 | 9 | local $/ = "\012"; # database uses unix newlines | |||||||||||||||||||||||||||
| 39 | 9 | my $fh = $self->{fh}; | |||||||||||||||||||||||||||
| 40 | 9 | ▶ | if (not $recno) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 5 | $line = <$fh>; | |||||||||||||||||||||||||||
| 42 | 5 | ▶ | return if not defined $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||
| 45 | 4 | my $line_start = LINE_LENGTH*($recno-1); | |||||||||||||||||||||||||||
| 46 | 4 | my $line_end = $line_start+LINE_LENGTH; | |||||||||||||||||||||||||||
| 47 | 4 | ▶ | return() if $line_end > $self->{filesize}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 4 | ▶ | seek $fh, $line_start, 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | or die "Could not seek to pos '$line_start' of file '$self->{filename}': $!"; | ||||||||||||||||||||||||||||
| 50 | 4 | $line = <$fh>; | |||||||||||||||||||||||||||
| 51 | 4 | ▶ | return if not defined $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 6 | my $record = Astro::Hipparcos::Record->new(); | |||||||||||||||||||||||||||
| 54 | 6 | $record->ParseRecord($line); | |||||||||||||||||||||||||||
| 55 | 6 | return $record; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub append_record { | ||||||||||||||||||||||||||
|
Subroutine
append_record: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 60 | 0 | my $record = shift; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | croak("Need Astro::Hipparcos::Record as first argument to append_record") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $record and $record->isa("Astro::Hipparcos::Record")
MC/DC0%0/2
ref $record and $record->isa("Astro::Hipparcos::Record")
ref $record
$record->isa("Astro::Hipparcos::Record")
Truth table0%0/3
A and B
A= ref $recordB= $record->isa("Astro::Hipparcos::Record")
| |||||||||||||||||||||||||||||
| 62 | unless ref($record) and $record->isa("Astro::Hipparcos::Record"); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | my $fh = $self->{fh}; | |||||||||||||||||||||||||||
| 65 | 0 | my $orig_pos = tell($fh); | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | seek $fh, 0, 2 or die "Could not seek to end of file: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | print $fh $record->get_line(); | |||||||||||||||||||||||||||
| 68 | 0 | $self->{filesize} = (-s $self->{abs_file}); | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | seek $fh, $orig_pos, 0 or die "Could not seek to previous position: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | return 1; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | 1; | |||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||