blib/lib/Astro/Hipparcos.pm

filter: Statementstmt 78.9% 45 / 57 Branchbran 41.6% 10 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 100% 3 / 3 totaltotal 67.3% 66 / 98 CC 14 SCAR 23.3
CC
14
Cov
65%
append_record
30.0
new
6.7
get_record
6.0
CRAP 10.3
↑ Summary HipRecord.h »
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
BranchTrueFalseTotal
unless defined $file 0 1 1
20 1 ▶ if (not -e $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 1 1
21 0 ▶ open my $fh, '>', $file or die "Could not open file '$file' for writing: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $file or die "Could not open file '${file}' for writing: $!" 0 0 0
22 0 close $fh;
23 }
24 1 ▶ open my $fh, '+<', $file or die "Could not open file '$file' for reading/writing: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "+<", $file or die "Could not open file '${file}' for reading/writing: $!" 1 0 1
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
BranchTrueFalseTotal
if (not $recno) { } 5 4 9
41 5 $line = <$fh>;
42 5 ▶ return if not defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 3 2 5
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
BranchTrueFalseTotal
if $line_end > $self->{"filesize"} 0 4 4
48 4 ▶ seek $fh, $line_start, 0
Branch: 1 branch
BranchTrueFalseTotal
seek $fh, $line_start, 0 or die qq[Could not seek to pos '${line_start}' of file '$self->{"filename"}': $!] 4 0 4
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
BranchTrueFalseTotal
unless defined $line 0 4 4
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
BranchTrueFalseTotal
unless ref $record and $record->isa("Astro::Hipparcos::Record") 0 0 0
Condition0%0/3
ref $record and $record->isa("Astro::Hipparcos::Record")
!ll&&!rl&&r
000
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
seek $fh, 0, 2 or die "Could not seek to end of file: $!" 0 0 0
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
BranchTrueFalseTotal
seek $fh, $orig_pos, 0 or die "Could not seek to previous position: $!" 0 0 0
70 0 return 1;
71 }
72  
73 1 1;
74 __END__
↑ Summary HipRecord.h »