line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graphics::Color::HSL; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
31086
|
$Graphics::Color::HSL::VERSION = '0.29'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
733
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use MooseX::Aliases; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends qw(Graphics::Color); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: HSL color space |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Graphics::Color::Equal'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Graphics::Color::Types qw(Number360OrLess NumberOneOrLess); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'hue' => ( |
18
|
|
|
|
|
|
|
is => 'rw', |
19
|
|
|
|
|
|
|
isa => Number360OrLess, |
20
|
|
|
|
|
|
|
default => 1, |
21
|
|
|
|
|
|
|
alias => 'h' |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 'saturation' => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
isa => NumberOneOrLess, |
28
|
|
|
|
|
|
|
default => 1, |
29
|
|
|
|
|
|
|
alias => 's' |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'lightness' => ( |
34
|
|
|
|
|
|
|
is => 'rw', |
35
|
|
|
|
|
|
|
isa => NumberOneOrLess, |
36
|
|
|
|
|
|
|
default => 1, |
37
|
|
|
|
|
|
|
alias => 'l' |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has 'alpha' => ( |
42
|
|
|
|
|
|
|
is => 'rw', |
43
|
|
|
|
|
|
|
isa => NumberOneOrLess, |
44
|
|
|
|
|
|
|
default => 1, |
45
|
|
|
|
|
|
|
alias => 'a' |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has 'name' => ( is => 'rw', isa => 'Str' ); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub as_string { |
53
|
|
|
|
|
|
|
my ($self) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return sprintf('%d,%0.2f,%0.2f,%0.2f', |
56
|
|
|
|
|
|
|
$self->hue, $self->saturation, $self->lightness, $self->alpha |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub as_percent_string { |
62
|
|
|
|
|
|
|
my ($self) = @_; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return sprintf("%d, %d%%, %d%%, %0.2f", |
65
|
|
|
|
|
|
|
$self->hue, $self->saturation * 100, $self->lightness * 100, |
66
|
|
|
|
|
|
|
$self->alpha |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub as_array { |
72
|
|
|
|
|
|
|
my ($self) = @_; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
return ($self->hue, $self->saturation, $self->lightness); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub as_array_with_alpha { |
79
|
|
|
|
|
|
|
my ($self) = @_; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
return ($self->hue, $self->saturation, $self->lightness, $self->alpha); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub equal_to { |
86
|
|
|
|
|
|
|
my ($self, $other) = @_; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return 0 unless defined($other); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
unless($self->hue == $other->hue) { |
91
|
|
|
|
|
|
|
return 0; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
unless($self->saturation == $other->saturation) { |
94
|
|
|
|
|
|
|
return 0; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
unless($self->lightness == $other->lightness) { |
97
|
|
|
|
|
|
|
return 0; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
unless($self->alpha == $other->alpha) { |
100
|
|
|
|
|
|
|
return 0; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return 1; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
no Moose; |
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
__END__ |
111
|
|
|
|
|
|
|
=pod |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 NAME |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Graphics::Color::HSL - HSL color space |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 VERSION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
version 0.29 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SYNOPSIS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
use Graphics::Color::HSL; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $color = Graphics::Color::HSL->new({ |
126
|
|
|
|
|
|
|
hue => 120, |
127
|
|
|
|
|
|
|
saturation => .5, |
128
|
|
|
|
|
|
|
lightness => .25, |
129
|
|
|
|
|
|
|
}); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 DESCRIPTION |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Graphics::Color::HSL represents a Color in an RGB color space. HSL stands for |
134
|
|
|
|
|
|
|
B<Hue> B<Saturation> and B<Lightness>. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 hue |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 h |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Set/Get the hue component of this Color. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 saturation |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 s |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Set/Get the saturation component of this Color. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 lightness |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 l |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Set/Get the lightness component of this Color. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 alpha |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Set/Get the alpha component of this Color. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 name |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Get the name of this color. Only valid if the color was created by name. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 METHODS |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 as_string |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Get a string version of this Color in the form of: |
169
|
|
|
|
|
|
|
HUE,SATURATION,LIGHTNESS,ALPHA |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 as_percent_string |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Return a percent formatted value for this color. This format is suitable for |
174
|
|
|
|
|
|
|
CSS HSL values. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 as_array |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Get the HSL values as an array |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 as_array_with_alpha |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Get the HSLA values as an array |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 equal_to |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Compares this color to the provided one. Returns 1 if true, else 0; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 not_equal_to |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
The opposite of equal_to. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 AUTHOR |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Cory G Watson <gphat@cpan.org> |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Cold Hard Code, LLC. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
201
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
204
|
|
|
|
|
|
|
|