Color/HSL.pm

filter: Statementstmt 92.6% 38 / 41 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 89.2% 58 / 65 SCAR 18.1
CC
6
Cov
86%
equal_to
7.3
BEGIN
1.0
BEGIN
1.0
CRAP 6.1
« Color/CMYK.pm ↑ Summary Color/YIQ.pm »
1 package Graphics::Color::HSL;
2 5 $Graphics::Color::HSL::VERSION = '0.30';
3 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use MooseX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 extends qw(Graphics::Color);
7  
8 # ABSTRACT: HSL color space
9  
10 5 with 'Graphics::Color::Equal';
11  
12 5 ▶use Graphics::Color::Types qw(Number360OrLess NumberOneOrLess);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 5 has 'hue' => (
16 is => 'rw',
17 isa => Number360OrLess,
18 default => 1,
19 alias => 'h'
20 );
21  
22  
23 5 has 'saturation' => (
24 is => 'rw',
25 isa => NumberOneOrLess,
26 default => 1,
27 alias => 's'
28 );
29  
30  
31 5 has 'lightness' => (
32 is => 'rw',
33 isa => NumberOneOrLess,
34 default => 1,
35 alias => 'l'
36 );
37  
38  
39 5 has 'alpha' => (
40 is => 'rw',
41 isa => NumberOneOrLess,
42 default => 1,
43 alias => 'a'
44 );
45  
46  
47 5 has 'name' => ( is => 'rw', isa => 'Str' );
48  
49  
50 sub as_string {
51 1 ▶ my ($self) = @_;
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
52  
53 1 return sprintf('%d,%0.2f,%0.2f,%0.2f',
54 $self->hue, $self->saturation, $self->lightness, $self->alpha
55 );
56 }
57  
58  
59 sub as_percent_string {
60 1 ▶ my ($self) = @_;
Subroutine as_percent_string: called CC=1 SCAR=0.0
Pod documented
61  
62 1 return sprintf("%d, %d%%, %d%%, %0.2f",
63 $self->hue, $self->saturation * 100, $self->lightness * 100,
64 $self->alpha
65 );
66 }
67  
68  
69 sub as_array {
70 1 ▶ my ($self) = @_;
Subroutine as_array: called CC=1 SCAR=0.0
Pod documented
71  
72 1 return ($self->hue, $self->saturation, $self->lightness);
73 }
74  
75  
76 sub as_array_with_alpha {
77 1 ▶ my ($self) = @_;
Subroutine as_array_with_alpha: called CC=1 SCAR=0.0
Pod documented
78  
79 1 return ($self->hue, $self->saturation, $self->lightness, $self->alpha);
80 }
81  
82  
83 sub equal_to {
84 2 ▶ my ($self, $other) = @_;
Subroutine equal_to: called CC=6 SCAR=19.9
Pod documented
85  
86 2 ▶ return 0 unless defined($other);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $other 0 2 2
87  
88 2 ▶ unless($self->hue == $other->hue) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->hue == $other->hue) 0 2 2
89 0 return 0;
90 }
91 2 ▶ unless($self->saturation == $other->saturation) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->saturation == $other->saturation) 1 1 2
92 1 return 0;
93 }
94 1 ▶ unless($self->lightness == $other->lightness) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->lightness == $other->lightness) 0 1 1
95 0 return 0;
96 }
97 1 ▶ unless($self->alpha == $other->alpha) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->alpha == $other->alpha) 0 1 1
98 0 return 0;
99 }
100  
101 1 return 1;
102 }
103  
104 5 __PACKAGE__->meta->make_immutable;
105  
106 5 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 5 1;
108  
109 __END__
110  
111 =pod
112  
113 =head1 NAME
114  
115 Graphics::Color::HSL - HSL color space
116  
117 =head1 VERSION
118  
119 version 0.30
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) 2014 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
« Color/CMYK.pm ↑ Summary Color/YIQ.pm »