| 1 | package Astro::STSDAS::Table::Column; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | require 5.005_62; | |||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Astro::STSDAS::Table::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # Column attributes | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | # All tables: | ||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||
| 17 | # name - the column name | ||||||||||||||||||||||||||||
| 18 | # units - the units string | ||||||||||||||||||||||||||||
| 19 | # format - the format string | ||||||||||||||||||||||||||||
| 20 | # idx - the column number (unary based) | ||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||
| 22 | # Binary Tables: | ||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||
| 24 | # offset - the byte offset from the start of the row | ||||||||||||||||||||||||||||
| 25 | # (for row ordered tables) | ||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||
| 27 | # type - the data representation type (TY_REAL, | ||||||||||||||||||||||||||||
| 28 | # TY_DOUBLE, TY_INT, etc.) see the constants defined | ||||||||||||||||||||||||||||
| 29 | # above | ||||||||||||||||||||||||||||
| 30 | # | ||||||||||||||||||||||||||||
| 31 | # nelem - the number of elements in the cell. if the data type | ||||||||||||||||||||||||||||
| 32 | # is TY_STRING, this is the maximum number of | ||||||||||||||||||||||||||||
| 33 | # characters. if not a string, and if greater than | ||||||||||||||||||||||||||||
| 34 | # one, it indicates a vector. | ||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||
| 36 | # fmt - the pack() compatible format to parse this column | ||||||||||||||||||||||||||||
| 37 | # (taking into account vectors) | ||||||||||||||||||||||||||||
| 38 | # | ||||||||||||||||||||||||||||
| 39 | # size - # bytes in the data type | ||||||||||||||||||||||||||||
| 40 | # ifmt - pack() compatible format for this type (doesn't take | ||||||||||||||||||||||||||||
| 41 | # into account vectors) | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 4 | our @colkeys = qw { name units format idx offset type nelem }; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub new | ||||||||||||||||||||||||||||
| 46 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.4
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 9 | my $class = shift; | |||||||||||||||||||||||||||
| 48 | 9 | ▶ | $class = ref($class) || $class; | ||||||||||||||||||||||||||
|
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 9 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 9 | @{$self}{@colkeys} = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 9 | ▶ | $self->{nelem} = 1 unless defined $self->{nelem}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 9 | ▶ | if ( defined $self->{type} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||
| 58 | croak( __PACKAGE__, '->new: illegal column type' ) | ||||||||||||||||||||||||||||
| 59 | 9 | ▶ | unless exists $Types{$self->{type}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 9 | $self->{size} = $TypeSize{$self->{type}}; | |||||||||||||||||||||||||||
| 61 | 9 | $self->{fmt} = $self->{ifmt} = $TypeUPack{$self->{type}}; | |||||||||||||||||||||||||||
| 62 | 9 | ▶ | $self->{fmt} .= $self->{nelem} if $self->{nelem} > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 9 | $self->{indef} = $TypeIndef{$self->{type}}; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 9 | $self; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | sub _access_rw | ||||||||||||||||||||||||||||
| 70 | 12 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_access_rw: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | 12 | my $what = shift; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 22 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 74 | 22 | my $self = shift; | |||||||||||||||||||||||||||
| 75 | 22 | ▶ | $self->{$what} = $_[0] if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 22 | $self->{$what}; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 12 | } | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub _access_ro | ||||||||||||||||||||||||||||
| 81 | 24 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_access_ro: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | 24 | my $what = shift; | |||||||||||||||||||||||||||
| 83 | 29 | ▶ | sub { croak( __PACKAGE__, "->$what: attempt to write to RO attribute" ) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | if @_ > 1; | ||||||||||||||||||||||||||||
| 85 | 24 | $_[0]->{$what} | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 24 | } | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||
| 90 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 91 | *$_ = _access_rw( $_ ) | ||||||||||||||||||||||||||||
| 92 | 4 | foreach qw( name units format ); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | *$_ = _access_ro( $_ ) | ||||||||||||||||||||||||||||
| 95 | 4 | foreach qw ( idx offset type fmt size ifmt ); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | sub is_string | ||||||||||||||||||||||||||||
| 99 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
is_string: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 2 | ▶ | defined $_[0]->{type} ? ($_[0]->{type} == TY_STRING ? 1 : 0) : undef; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub is_indef | ||||||||||||||||||||||||||||
| 104 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
is_indef: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 2 | ▶ | $_[0]->{type} != TY_STRING && $_[0]->{indef} == $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | sub is_vector | ||||||||||||||||||||||||||||
| 109 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
is_vector: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $_[0]->{type} != TY_STRING && $_[0]->{nelem} > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | sub nelem | ||||||||||||||||||||||||||||
| 114 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
nelem: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 2 | ▶ | croak( __PACKAGE__, "->nelem: attempt to write to RO attribute" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | if @_ > 1; | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | defined $_[0]->{type} && $_[0]->{type} == TY_STRING ? | ||||||||||||||||||||||||||||
| 119 | 1 | ▶ | 1 : $_[0]->{nelem}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $_[0]{"type"} and $_[0]{"type"} == -1
MC/DC0%0/2
defined $_[0]{"type"} and $_[0]{"type"} == -1
defined $_[0]{"type"}
$_[0]{"type"} == -1
Truth table33%1/3
A and B
A= defined $_[0]{"type"}B= $_[0]{"type"} == -1
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub copy | ||||||||||||||||||||||||||||
| 123 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
copy: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 3 | $_[0]->new( @{$_[0]}{@colkeys} ); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 4 | 1; | |||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||