| 1 | package CXC::Astro::Regions::DS9::Variant; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Generate DS9 Region classes | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use v5.20; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use experimental 'signatures', 'postderef'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Module::Runtime 'module_notional_filename'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Ref::Util qw( is_arrayref ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | use Package::Variant | ||||||||||||||||||||||||||||
| 16 | 3 | importing => [ 'Moo', 'MooX::StrictConstructor' ], | |||||||||||||||||||||||||||
| 17 | 3 | ▶ | subs => [qw( has extends around with )]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use constant PREFIX => __PACKAGE__ =~ s/[^:]+$//r; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | sub _croak { | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | require Carp; | ||||||||||||||||||||||||||
|
Subroutine
_croak: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 23 | 0 | goto \&Carp::croak; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | ▶ | sub make_variant_package_name ( $, $package, % ) { | |||||||||||||||||||||||||||
|
Subroutine
make_variant_package_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 42 | return PREFIX . ucfirst( $package ); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | ▶ | sub make_variant ( $, $, $region, %args ) { | |||||||||||||||||||||||||||
|
Subroutine
make_variant: called CC=15 SCAR=27.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 42 | ▶ | my $params = $args{params} // []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"params"} // []
MC/DC0%0/1
$args{"params"} // []
$args{"params"}
Truth table50%1/2
A
A= $args{"params"}
| |||||||||||||||||||||||||||||
| 35 | 42 | ▶ | my $props = $args{props} // []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"props"} // []
MC/DC0%0/1
$args{"props"} // []
$args{"props"}
Truth table50%1/2
A
A= $args{"props"}
| |||||||||||||||||||||||||||||
| 36 | 42 | ▶ | $region = $args{name} // $region; | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{"name"} // $region
MC/DC0%0/2
$args{"name"} // $region
$args{"name"}
$region
Truth table66%2/3
A // B
A= $args{"name"}B= $region
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 42 | ▶ | extends $args{extends}->@* if $args{extends} && $args{extends}->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args{"extends"} and @{$args{"extends"}}
MC/DC50%1/2
$args{"extends"} and @{$args{"extends"}}
$args{"extends"}
@{$args{"extends"}}
Truth table66%2/3
A and B
A= $args{"extends"}B= @{$args{"extends"}}
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # if a region has a text *parameter*, don't add a text *property* | ||||||||||||||||||||||||||||
| 41 | 42 | my $has_text_param; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 42 | my @private = qw( label format render ); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 42 | for my $arg ( $params->@* ) { | |||||||||||||||||||||||||||
| 46 | 138 | my %has = ( is => 'ro', required => 1, $arg->%* ); | |||||||||||||||||||||||||||
| 47 | 138 | my ( $name ) = delete @has{ 'name', @private }; | |||||||||||||||||||||||||||
| 48 | 138 | has $name => %has; | |||||||||||||||||||||||||||
| 49 | 138 | ▶ | $has_text_param = !!1 if $name eq 'text'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 42 | for my $arg ( $props->@* ) { | |||||||||||||||||||||||||||
| 53 | 742 | my %has = ( is => 'ro', required => 0, $arg->%* ); | |||||||||||||||||||||||||||
| 54 | 742 | my ( $name ) = delete @has{ 'name', @private }; | |||||||||||||||||||||||||||
| 55 | 742 | ▶ | next if $has_text_param && $name eq 'text'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$has_text_param and $name eq "text"
MC/DC100%2/2
$has_text_param and $name eq "text"
$has_text_param
$name eq "text"
Truth table100%3/3
A and B
A= $has_text_paramB= $name eq "text"
| |||||||||||||||||||||||||||||
| 56 | 740 | has $name => %has; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | ▶ | install render => sub ( $self ) { | |||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 60 | 57 | my @output; | |||||||||||||||||||||||||||
| 61 | 57 | ▶ | push @output, q{#} if $args{comment}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 57 | ▶ | push @output, ( $self->include ? q{} : q{-} ) . $region; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 57 | push @output, params( $self, $params ); | |||||||||||||||||||||||||||
| 64 | 57 | my @props = props( $self, $props, has_text_param => $has_text_param ); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 57 | ▶ | push @output, q{#}, @props if @props; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 57 | return join q{ }, @output; | |||||||||||||||||||||||||||
| 69 | 42 | }; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 42 | ▶ | around $args{around}->@* if $args{around} && $args{around}->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args{"around"} and @{$args{"around"}}
MC/DC50%1/2
$args{"around"} and @{$args{"around"}}
$args{"around"}
@{$args{"around"}}
Truth table66%2/3
A and B
A= $args{"around"}B= @{$args{"around"}}
| |||||||||||||||||||||||||||||
| 72 | 42 | ▶ | with $args{with}->@* if $args{with} && $args{with}->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args{"with"} and @{$args{"with"}}
MC/DC50%1/2
$args{"with"} and @{$args{"with"}}
$args{"with"}
@{$args{"with"}}
Truth table66%2/3
A and B
A= $args{"with"}B= @{$args{"with"}}
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | ▶ | sub params ( $self, $params ) { | |||||||||||||||||||||||||||
|
Subroutine
params: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | 57 | my @output; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 57 | for my $param ( $params->@* ) { | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # if the caller doesn't want this rendered, don't | ||||||||||||||||||||||||||||
| 82 | 158 | ▶ | next if !( $param->{render} // !!1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$param->{"render"} //
MC/DC100%1/1
$param->{"render"} //
$param->{"render"}
Truth table100%2/2
A
A= $param->{"render"}
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 156 | my $name = $param->{name}; | |||||||||||||||||||||||||||
| 85 | 156 | my @values = ( $self->$name ); | |||||||||||||||||||||||||||
| 86 | 156 | ▶ | next if !defined $values[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 145 | ▶ | if ( defined( my $format = $param->{format} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 1 | push @output, $format->( 'param', $name, \@values ); | |||||||||||||||||||||||||||
| 90 | 1 | next; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 144 | my @param_values; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 144 | ▶ | while ( @values ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 372 | my $value = shift @values; | |||||||||||||||||||||||||||
| 97 | 372 | ▶ | if ( is_arrayref( $value ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 111 | unshift @values, $value->@*; | |||||||||||||||||||||||||||
| 99 | 111 | next; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 261 | push @param_values, $value; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 144 | ▶ | if ( @param_values == 1 && defined( my $label = $param->{label} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@param_values == 1 and defined(my $label = $param->{"label"})
MC/DC100%2/2
@param_values == 1 and defined(my $label = $param->{"label"})
@param_values == 1
defined(my $label = $param->{"label"})
Truth table100%3/3
A and B
A= @param_values == 1B= defined(my $label = $param->{"label"})
| |||||||||||||||||||||||||||||
| 105 | 6 | push @output, $label . q{=} . $param_values[0]; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | else { | ||||||||||||||||||||||||||||
| 108 | 138 | push @output, @param_values; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 57 | return @output; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | ▶ | sub props ( $self, $props, %args ) { | |||||||||||||||||||||||||||
|
Subroutine
props: called CC=16 SCAR=27.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 57 | my @output; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 57 | for my $prop ( $props->@* ) { | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # if the caller doesn't want this rendered, don't | ||||||||||||||||||||||||||||
| 122 | 1044 | ▶ | next if !( $prop->{render} // !!1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$prop->{"render"} //
MC/DC0%0/1
$prop->{"render"} //
$prop->{"render"}
Truth table50%1/2
A
A= $prop->{"render"}
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1044 | my $name = $prop->{name}; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 1044 | ▶ | next if $name eq 'include'; # this results in a prefix to the | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | # start of the region spec | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 987 | ▶ | next if $name eq 'text' && $args{has_text_param}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$name eq "text" and $args{"has_text_param"}
MC/DC100%2/2
$name eq "text" and $args{"has_text_param"}
$name eq "text"
$args{"has_text_param"}
Truth table100%3/3
A and B
A= $name eq "text"B= $args{"has_text_param"}
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 986 | ▶ | my $label = exists $prop->{label} ? $prop->{label} : $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 986 | my @values = ( grep defined, $self->$name ); | |||||||||||||||||||||||||||
| 133 | 986 | ▶ | next unless @values; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 55 | ▶ | if ( defined( my $format = $prop->{format} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 16 | push @output, $format->( 'prop', $label, \@values ); | |||||||||||||||||||||||||||
| 137 | 16 | next; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 39 | my @prop_values; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 39 | ▶ | while ( @values ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 57 | my $value = shift @values; | |||||||||||||||||||||||||||
| 144 | 57 | ▶ | if ( is_arrayref( $value ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 9 | unshift @values, $value->@*; | |||||||||||||||||||||||||||
| 146 | 9 | next; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 48 | push @prop_values, $value; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 39 | ▶ | if ( @prop_values ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 39 | ▶ | if ( !defined $label ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 154 | 15 | push @output, @prop_values; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | elsif ( @prop_values == 1 ) { | ||||||||||||||||||||||||||||
| 157 | 23 | push @output, $label . q{=} . $prop_values[0]; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | else { | ||||||||||||||||||||||||||||
| 160 | 1 | ▶ | push @output, "$label=" if defined $label; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 1 | push @output, @prop_values; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 57 | return @output; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 3 | 1; | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # | ||||||||||||||||||||||||||||
| 172 | # This file is part of CXC-Astro-Regions | ||||||||||||||||||||||||||||
| 173 | # | ||||||||||||||||||||||||||||
| 174 | # This software is Copyright (c) 2023 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||
| 175 | # | ||||||||||||||||||||||||||||
| 176 | # This is free software, licensed under: | ||||||||||||||||||||||||||||
| 177 | # | ||||||||||||||||||||||||||||
| 178 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||
| 179 | # | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | __END__ | ||||||||||||||||||||||||||||