| 1 | package Astro::STSDAS::Table::HeaderPars; | ||||||||||||||||||||
| 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 | our $VERSION = '0.02'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 3 | ▶ | use Astro::STSDAS::Table::HeaderPar; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | # manages the header parameters | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | sub new | ||||||||||||||||||||
| 16 | 2 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||
| 17 | 2 | my $class = shift; | |||||||||||||||||||
| 18 | 2 | ▶ | $class = ref($class) || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 2 | my $self = { | |||||||||||||||||||
| 22 | vars => {}, | ||||||||||||||||||||
| 23 | idx => 0, | ||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 2 | bless $self, $class; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | sub npars | ||||||||||||||||||||
| 30 | 5 | ▶ | { | ||||||||||||||||||
|
Subroutine
npars: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 31 | 5 | scalar keys %{$_[0]->{vars}}; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | sub add | ||||||||||||||||||||
| 35 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 36 | 3 | my $self = shift; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 3 | my $name = uc shift; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | $self->_add( | ||||||||||||||||||||
| 41 | Astro::STSDAS::Table::HeaderPar->new( ++$self->{idx}, | ||||||||||||||||||||
| 42 | 3 | $name, @_ ) ); | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | sub _add | ||||||||||||||||||||
| 46 | 4 | ▶ | { | ||||||||||||||||||
|
Subroutine
_add: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 47 | 4 | my ( $self, $par ) = @_; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 4 | ▶ | if ( exists $self->{vars}{uc $par->name} ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | { | ||||||||||||||||||||
| 51 | 1 | $self->{idx}--; | |||||||||||||||||||
| 52 | 1 | croak( __PACKAGE__, "->add: duplicate parameter name `", | |||||||||||||||||||
| 53 | $par->name, "'\n" ); | ||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 3 | $self->{vars}{$par->name} = $par; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 3 | $par; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | sub pars | ||||||||||||||||||||
| 62 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
pars: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 63 | 1 | return sort { $a->idx <=> $b->idx } values %{$_[0]->{vars}}; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | sub byname | ||||||||||||||||||||
| 67 | 6 | ▶ | { | ||||||||||||||||||
|
Subroutine
byname: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 68 | 6 | my $name = uc $_[1]; | |||||||||||||||||||
| 69 | 6 | ▶ | return undef unless exists $_[0]->{vars}{$name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | 4 | $_[0]->{vars}{$name}; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | sub delbyname | ||||||||||||||||||||
| 75 | 4 | ▶ | { | ||||||||||||||||||
|
Subroutine
delbyname: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 76 | 4 | my $self = shift; | |||||||||||||||||||
| 77 | 4 | my $name = uc shift; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 4 | ▶ | return 0 unless exists $self->{vars}{$name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 3 | delete $self->{vars}{$name}; | |||||||||||||||||||
| 82 | 3 | 1; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | sub rename | ||||||||||||||||||||
| 86 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
rename: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 87 | 1 | my ( $self, $name, $newname ) = @_; | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 1 | my $hdrp = $self->byname($name); | |||||||||||||||||||
| 90 | 1 | ▶ | return undef unless defined $hdrp; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 1 | $self->delbyname( $name ); | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 1 | $hdrp->name($newname); | |||||||||||||||||||
| 95 | 1 | $self->_add( $hdrp ); | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | sub copy | ||||||||||||||||||||
| 100 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
copy: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 101 | 0 | my $self = shift; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 0 | my $new = $self->new; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | $new->_add( $_->copy ) foreach values %{$self->{vars}}; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 3 | 1; | |||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||