blib/lib/CXC/Gnuplot/V1/ColorSpec.pm

filter: Statementstmt 75.0% 6 / 8 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 81.8% 9 / 11 CC 1 SCAR 0.9
CC
1
Cov
75%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/CXC/Gnuplot/V1/Color.pm ↑ Summary blib/lib/CXC/Gnuplot/V1/CoordOffset2D.pm »
1 package CXC::Gnuplot::V1::ColorSpec;
2  
3 1 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use experimental 'declared_refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Object::Pad 0.821;
Subroutine BEGIN: called CC=1 SCAR=2.6
6  
7 our $VERSION = 'v0.29.3';
8  
9 class CXC::Gnuplot::V1::ColorSpec : isa(CXC::Gnuplot::V1::Base)
10 does( CXC::Gnuplot::V1::Role::Clone );
11  
12 no namespace::clean;
13  
14 use Ref::Util 'is_ref', 'is_plain_hashref';
15  
16 use namespace::clean;
17  
18 use CXC::Gnuplot::V1::Types -lexical, 'is_PositiveOrZeroInt', 'is_RGBColor', 'Palette';
19  
20 use CXC::Gnuplot::V1::Util
21 -lexical => 'pvalidate',
22 'gnuplot_color', 'to_hash_r', 'quote';
23  
24 my sub croak {
25 require Carp;
26 goto \&Carp::croak;
27 }
28  
29 #<<< no tidy
30 field $rgbcolor :param :reader = undef;
31 field $palette :param :reader = undef;
32 field $_color;
33 #>>>
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48 ADJUST {
49  
50 defined $rgbcolor
51 and defined $palette
52 and croak( 'specify only one of "rgbcolor" or "palette"' );
53  
54 pvalidate( palette => Palette, \$palette );
55  
56 # take this time to convert $rgbcolor while it's being validated.
57 if ( defined $rgbcolor ) {
58  
59 if ( length $rgbcolor ) {
60  
61 ## no critic( ControlStructures::ProhibitCascadingIfElse )
62 if ( $_color = gnuplot_color( $rgbcolor ) ) {
63 $_color = [ rgbcolor => quote( $_color->name ) ];
64 }
65 elsif ( is_RGBColor( $rgbcolor ) ) {
66 $_color = [ rgbcolor => quote( $rgbcolor ) ];
67 }
68 elsif ( is_PositiveOrZeroInt( $rgbcolor ) || $rgbcolor eq 'variable' ) {
69 $_color = [ rgbcolor => $rgbcolor ];
70 }
71 elsif ( $rgbcolor eq 'bgnd' ) {
72 $_color = $rgbcolor;
73 }
74 }
75  
76 defined $_color
77 or croak( "unrecognized color: $rgbcolor" );
78 }
79 }
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94 method BUILDARGS : common (@args ) {
95 return ( rgbcolor => $args[0] ) if @args == 1 && !is_ref( $args[0] );
96 return $class->SUPER::BUILDARGS( @args );
97 }
98  
99  
100  
101  
102  
103  
104  
105  
106 method to_hash ( %args ) {
107 return to_hash_r( {
108 ( defined $rgbcolor ? ( rgbcolor => $rgbcolor ) : () ), #
109 ( defined $palette ? ( palette => $palette ) : () ),
110 } );
111 }
112  
113  
114  
115  
116  
117 method opts {
118  
119 my @opts;
120  
121 # palette will only ever have one key.
122 defined $palette
123 and push @opts, [ palette => is_plain_hashref( $palette ) ? [ $palette->%* ] : $palette ];
124  
125 defined $_color
126 and push @opts, $_color;
127  
128 return @opts;
129 }
130  
131 1;
132  
133 #
134 # This file is part of CXC-Gnuplot
135 #
136 # This software is Copyright (c) 2024 by Smithsonian Astrophysical Observatory.
137 #
138 # This is free software, licensed under:
139 #
140 # The GNU General Public License, Version 3, June 2007
141 #
142  
143 __END__
« blib/lib/CXC/Gnuplot/V1/Color.pm ↑ Summary blib/lib/CXC/Gnuplot/V1/CoordOffset2D.pm »