File: CMYK.pm

package info (click to toggle)
libgraphics-color-perl 0.31-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 212 kB
  • sloc: perl: 661; makefile: 2
file content (194 lines) | stat: -rw-r--r-- 3,081 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package Graphics::Color::CMYK;
$Graphics::Color::CMYK::VERSION = '0.31';
use Moose;
use MooseX::Aliases;

extends qw(Graphics::Color);

# ABSTRACT: CMYK color model

use Graphics::Color::Types qw(Number360OrLess NumberOneOrLess);
use Graphics::Color::RGB;


has 'cyan' => (
    is => 'rw',
    isa => NumberOneOrLess,
    default => 1,
    alias => 'c'
);


has 'magenta' => (
    is => 'rw',
    isa => NumberOneOrLess,
    default => 1,
    alias => 'm'
);


has 'yellow' => (
    is => 'rw',
    isa => NumberOneOrLess,
    default => 1,
    alias => 'y'
);


has 'key' => (
    is => 'rw',
    isa => NumberOneOrLess,
    default => 1,
    alias => 'k'
);


has 'name' => ( is => 'rw', isa => 'Str' );


sub as_string {
    my ($self) = @_;

    return sprintf('%0.2f,%0.2f,%0.2f,%0.2f',
        $self->cyan, $self->magenta, $self->yellow, $self->key
    );
}


sub as_percent_string {
    my ($self) = @_;

    return sprintf("%d%%, %d%%, %d%%, %d%%",
        $self->cyan * 100, $self->magenta * 100, $self->yellow * 100,
        $self->key * 100
    );
}


sub as_array {
    my ($self) = @_;

    return ($self->cyan, $self->magenta, $self->yellow, $self->key);
}


sub equal_to {
    my ($self, $other) = @_;

    return 0 unless defined($other);

    unless($self->cyan == $other->cyan) {
        return 0;
    }
    unless($self->magenta == $other->magenta) {
        return 0;
    }
    unless($self->yellow == $other->yellow) {
        return 0;
    }
    unless($self->key == $other->key) {
        return 0;
    }

    return 1;
}

__PACKAGE__->meta->make_immutable;

no Moose;
1;

__END__

=pod

=head1 NAME

Graphics::Color::CMYK - CMYK color model

=head1 VERSION

version 0.31

=head1 SYNOPSIS

    use Graphics::Color::CMYK;

    my $color = Graphics::Color::CMYK->new({
        cyan    => 120,
        magenta => .5,
        yellow  => .25,
        key     => .5
    });

=head1 DESCRIPTION

Graphics::Color::CMYK represents a Color in CMYK color model.  Cyan stands for
B<Cyan> B<Magenta> B<Yellow> B<Key> (or black).

=head1 ATTRIBUTES

=head2 cyan

=head2 c

Set/Get the cyan component of this Color.

=head2 magenta

=head2 m

Set/Get the magenta component of this Color.

=head2 yellow

=head2 y

Set/Get the yellow component of this Color.

=head2 key

=head2 k

Set/Get the key (black) component of this Color.

=head2 name

Get the name of this color.  Only valid if the color was created by name.

=head1 METHODS

=head2 as_string

Get a string version of this Color in the form of:

CYAN,MAGENTA,YELLOW,KEY

=head2 as_percent_string

Return a percent formatted value for this color.

=head2 as_array

Get the CMYK values as an array

=head2 equal_to

Compares this color to the provided one.  Returns 1 if true, else 0;

=head2 not_equal_to

The opposite of C<equal_to>.

=head1 AUTHOR

Cory G Watson <gphat@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Cold Hard Code, LLC.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut