| 1 | package Astro::STSDAS::Table::Columns; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | require 5.005_62; | |||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | ▶ | use Astro::STSDAS::Table::Column; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 3 | our $VERSION = '0.01'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | sub new | ||||||||||||||||||||
| 14 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 15 | 3 | my $class = shift; | |||||||||||||||||||
| 16 | 3 | ▶ | $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
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 3 | my $self = { | |||||||||||||||||||
| 20 | cols => {}, | ||||||||||||||||||||
| 21 | idxs => {}, | ||||||||||||||||||||
| 22 | idxs_s => undef, # sorted indices | ||||||||||||||||||||
| 23 | }; | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 3 | bless $self, $class; | |||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | sub ncols | ||||||||||||||||||||
| 29 | 7 | ▶ | { | ||||||||||||||||||
|
Subroutine
ncols: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 30 | 7 | scalar keys %{$_[0]->{cols}}; | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | sub add | ||||||||||||||||||||
| 34 | 4 | ▶ | { | ||||||||||||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 35 | 4 | my $self = shift; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 4 | $self->_add( Astro::STSDAS::Table::Column->new( @_ ) ); | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | sub _add | ||||||||||||||||||||
| 41 | 7 | ▶ | { | ||||||||||||||||||
|
Subroutine
_add: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 42 | 7 | my ( $self, $col ) = @_; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | croak( __PACKAGE__, "->add: duplicate column index `", $col->idx, "'\n" ) | ||||||||||||||||||||
| 45 | 7 | ▶ | if exists $self->{idxs}{$col->idx}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | croak( __PACKAGE__, "->add: duplicate column name `", $col->name, "'\n" ) | ||||||||||||||||||||
| 48 | 6 | ▶ | if exists $self->{cols}{lc $col->name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 5 | $self->{cols}{lc $col->name} = $col; | |||||||||||||||||||
| 51 | 5 | $self->{idxs}{$col->idx} = $col; | |||||||||||||||||||
| 52 | 5 | $_[0]->{idxs_s} = undef; | |||||||||||||||||||
| 53 | 5 | $col; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | sub del | ||||||||||||||||||||
| 57 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
del: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 58 | 1 | my $self = shift; | |||||||||||||||||||
| 59 | 1 | my $col = shift; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | # first make sure its one of ours. | ||||||||||||||||||||
| 62 | 1 | ▶ | return 0 unless grep { $col == $_ } values %{$self->{cols}}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 1 | $self->delbyname( $col->name ); | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | sub delbyname | ||||||||||||||||||||
| 68 | 4 | ▶ | { | ||||||||||||||||||
|
Subroutine
delbyname: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 69 | 4 | my $self = shift; | |||||||||||||||||||
| 70 | 4 | my $name = lc shift; | |||||||||||||||||||
| 71 | 4 | ▶ | return 0 unless exists $self->{cols}{$name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 3 | delete $self->{idxs}{$self->{cols}{$name}->idx}; | |||||||||||||||||||
| 74 | 3 | delete $self->{cols}{$name}; | |||||||||||||||||||
| 75 | 3 | $_[0]->{idxs_s} = undef; | |||||||||||||||||||
| 76 | 3 | 1; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | sub byidx | ||||||||||||||||||||
| 80 | 5 | ▶ | { | ||||||||||||||||||
|
Subroutine
byidx: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 81 | 5 | ▶ | exists $_[0]->{idxs}{$_[1]} ? $_[0]->{idxs}{$_[1]} : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | sub byname | ||||||||||||||||||||
| 86 | 7 | ▶ | { | ||||||||||||||||||
|
Subroutine
byname: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 87 | 7 | my $name = lc $_[1]; | |||||||||||||||||||
| 88 | 7 | ▶ | return undef unless exists $_[0]->{cols}{$name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | 6 | $_[0]->{cols}{$name}; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | sub cols | ||||||||||||||||||||
| 93 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
cols: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 94 | 0 | ▶ | $_[0]->_mkidxs_s unless defined $_[0]->{idxs_s}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 0 | @{$_[0]->{idxs_s}}; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | sub _mkidxs_s | ||||||||||||||||||||
| 99 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_mkidxs_s: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 100 | 0 | $_[0]->{idxs_s} = [ sort { $a->idx <=> $b->idx} values %{$_[0]->{cols}} ]; | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | sub names | ||||||||||||||||||||
| 104 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
names: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 105 | 0 | map { $_->name } $_[0]->cols; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | sub rename | ||||||||||||||||||||
| 109 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
rename: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 110 | 1 | my ( $self, $name, $newname ) = @_; | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 1 | my $col = $self->byname($name); | |||||||||||||||||||
| 113 | 1 | ▶ | return undef unless defined $col; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 1 | $self->delbyname( $name ); | |||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 1 | $col->name($newname); | |||||||||||||||||||
| 118 | 1 | $self->_add( $col ); | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | sub _access | ||||||||||||||||||||
| 122 | 27 | ▶ | { | ||||||||||||||||||
|
Subroutine
_access: called CC=1 SCAR=3.5
| |||||||||||||||||||||
| 123 | 27 | my $what = shift; | |||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 0 | ▶ | sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||||||||||
| 128 | 0 | my $name = lc shift; | |||||||||||||||||||
| 129 | 0 | ▶ | return undef unless exists $self->{cols}{$name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 130 | 0 | $self->{cols}{$name}->$what(@_); | |||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | 27 | } | |||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | { | ||||||||||||||||||||
| 135 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 136 | *$_ = _access( $_ ) | ||||||||||||||||||||
| 137 | 3 | foreach qw( units format idx offset type nelem fmt is_string is_undef ); | |||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | sub copy | ||||||||||||||||||||
| 143 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
copy: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 144 | 1 | my $self = shift; | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 1 | my $new = $self->new; | |||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 1 | $new->_add( $_->copy ) foreach values %{$self->{cols}}; | |||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 1 | $new; | |||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | 3 | 1; | |||||||||||||||||||
| 155 | __END__ | ||||||||||||||||||||