line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Color::Library::Dictionary; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
62
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
45
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Color::Library; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
48
|
|
7
|
2
|
|
|
2
|
|
1157
|
use Color::Library::Color; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
17
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
119
|
use base qw/Class::Data::Inheritable/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
317592
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata($_) for qw/_self _compiled _color_list _index/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Color::Library::Dictionary - Color dictionary for Color::Library |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _register_dictionary { |
20
|
44
|
|
|
44
|
|
163
|
my $module = my $class = shift; |
21
|
44
|
|
|
|
|
263
|
my @module = split m/::/, $module; |
22
|
|
|
|
|
|
|
|
23
|
44
|
|
|
|
|
230
|
my @parent_module = @module; |
24
|
44
|
|
|
|
|
89
|
my $name = pop @parent_module; |
25
|
44
|
100
|
|
|
|
176
|
@parent_module = qw/Color Library/ if @parent_module == 3; # Color::Library::Dictionary |
26
|
44
|
|
|
|
|
132
|
my $parent_module = join "::", @parent_module; |
27
|
|
|
|
|
|
|
{ |
28
|
2
|
|
|
2
|
|
590
|
no strict 'refs'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2790
|
|
|
44
|
|
|
|
|
59
|
|
29
|
44
|
|
|
|
|
348
|
*{"$parent_module\::$name"} = sub { |
30
|
45
|
|
|
45
|
|
468
|
return $module->_singleton; |
31
|
44
|
|
|
|
|
210
|
}; |
32
|
|
|
|
|
|
|
} |
33
|
44
|
|
|
|
|
269
|
Color::Library->_register_dictionary($module); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _parse_id($) { |
37
|
90
|
|
|
90
|
|
137
|
my $id = shift; |
38
|
90
|
|
|
|
|
1025
|
$id =~ s/::|_|\s+|\//-/g; |
39
|
90
|
|
|
|
|
170
|
$id = lc $id; |
40
|
90
|
|
|
|
|
230
|
$id =~ s/^color-library-dictionary-//g; |
41
|
90
|
|
|
|
|
504
|
return $id; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _singleton { |
45
|
85
|
|
|
85
|
|
154
|
my $class = shift; |
46
|
85
|
|
|
|
|
130
|
my $self; |
47
|
85
|
100
|
|
|
|
2332
|
return $self if $self = $class->_self; |
48
|
21
|
|
|
|
|
300
|
$class->_self($self = bless {}, $class); |
49
|
21
|
|
|
|
|
852
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _compile { |
53
|
21
|
|
|
21
|
|
322
|
my $self = shift; |
54
|
21
|
|
33
|
|
|
116
|
my $class = ref $self || $self; |
55
|
|
|
|
|
|
|
|
56
|
21
|
50
|
|
|
|
79
|
return if $self->_compiled; |
57
|
|
|
|
|
|
|
|
58
|
21
|
|
|
|
|
255
|
my $color_list = $self->_load_color_list; |
59
|
|
|
|
|
|
|
|
60
|
21
|
|
|
|
|
1113
|
my $index = {}; |
61
|
21
|
|
|
|
|
50
|
my @color_list; |
62
|
21
|
|
|
|
|
41
|
my $indice = 0; |
63
|
21
|
|
|
|
|
76
|
for my $color (@$color_list) { |
64
|
12801
|
|
|
|
|
92494
|
push @color_list, $color = Color::Library::Color->new($color, $self); |
65
|
12801
|
|
|
|
|
50337
|
$index->{id}->{$color->id} = $color; |
66
|
12801
|
|
|
|
|
108966
|
$index->{name}->{$color->name} = $color; |
67
|
12801
|
|
|
|
|
84550
|
$index->{title}->{$color->title} = $color; |
68
|
12801
|
|
|
|
|
94079
|
$index->{hex}->{$color->hex} = $color; |
69
|
12801
|
|
|
|
|
82669
|
$index->{value}->{$color->value} = $color; |
70
|
|
|
|
|
|
|
} |
71
|
21
|
|
|
|
|
416
|
$self->_index($index); |
72
|
21
|
|
|
|
|
1287
|
$self->_color_list(\@color_list); |
73
|
21
|
|
|
|
|
677
|
$self->_compiled(1); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 METHODS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=over 4 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item @colors = $dictionary->colors |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Returns the list of Color::Library::Color objects contained by $dictionary |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Will return a list in list context, and a list reference in scalar context |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub colors { |
89
|
86
|
|
|
86
|
1
|
929
|
my $self = shift; |
90
|
86
|
100
|
|
|
|
434
|
$self->_compile unless $self->_compiled; |
91
|
86
|
|
|
|
|
2047
|
my @colors = @{ $self->_color_list }; |
|
86
|
|
|
|
|
255
|
|
92
|
86
|
50
|
|
|
|
14195
|
return wantarray ? @colors : \@colors; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item @names = $dictionary->names |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item @names = $dictionary->color_names |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Returns the list of color names contained by $dictionary |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Will return a list in list context, and a list reference in scalar context |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub names { |
106
|
43
|
|
|
43
|
1
|
102
|
my $self = shift; |
107
|
43
|
|
|
|
|
162
|
my @names = map { $_->name } $self->colors; |
|
25750
|
|
|
|
|
146203
|
|
108
|
43
|
50
|
|
|
|
14591
|
return wantarray ? @names : \@names; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
*color_names = \&names; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item $color = $dictionary->color( ) |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns a Color::Library::Color object of $dictionary found via |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
A query can be any of the following: |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over 4 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item color name |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
A color name is like C or C |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item color title |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
A color title is like C |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item color id |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
A color id is in the form of :, for example: C |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub color { |
137
|
20
|
|
|
20
|
1
|
32
|
my $self = shift; |
138
|
20
|
|
|
|
|
25
|
my $query = shift; |
139
|
|
|
|
|
|
|
|
140
|
20
|
50
|
|
|
|
41
|
return unless defined $query; |
141
|
|
|
|
|
|
|
|
142
|
20
|
50
|
|
|
|
35
|
unless (ref $query) { |
143
|
20
|
|
|
|
|
55
|
$query =~ s/^\s*//; |
144
|
20
|
|
|
|
|
78
|
$query =~ s/\s*$//; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
20
|
50
|
|
|
|
68
|
$self->_compile unless $self->_compiled; |
148
|
|
|
|
|
|
|
|
149
|
20
|
|
|
|
|
137
|
my $color; |
150
|
|
|
|
|
|
|
|
151
|
20
|
50
|
|
|
|
103
|
if (ref $query eq "ARRAY") { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
152
|
0
|
|
|
|
|
0
|
$query = Color::Library::Color::rgb2hex $query; |
153
|
0
|
|
|
|
|
0
|
return $color = $self->_index->{hex}->{$query}; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
elsif ($query =~ /^\#?([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/i) { |
156
|
0
|
|
|
|
|
0
|
return (hex($1), hex($2), hex($3), 255); |
157
|
0
|
|
|
|
|
0
|
$query = lc($1 . $2 . $3); |
158
|
0
|
|
|
|
|
0
|
return $color = $self->_index->{hex}->{$query}; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
elsif ($query =~ /^\#([\da-f])([\da-f])([\da-f])$/i) { |
161
|
0
|
|
|
|
|
0
|
$query = lc($1 . $1 . $2 . $2 . $3 . $3); |
162
|
0
|
|
|
|
|
0
|
return $color = $self->_index->{hex}->{$query}; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
20
|
100
|
|
|
|
70
|
return $color if $color = $self->_index->{title}->{$query}; |
166
|
|
|
|
|
|
|
|
167
|
15
|
|
|
|
|
292
|
$query = lc $query; |
168
|
|
|
|
|
|
|
|
169
|
15
|
50
|
|
|
|
35
|
return $color if $color = $self->_index->{id}->{$query}; |
170
|
|
|
|
|
|
|
|
171
|
15
|
|
|
|
|
119
|
$query =~ s/[^\w]//g; |
172
|
|
|
|
|
|
|
|
173
|
15
|
100
|
|
|
|
33
|
return $color if $color = $self->_index->{name}->{$query}; |
174
|
|
|
|
|
|
|
|
175
|
14
|
50
|
|
|
|
106
|
return $color if $color = $self->_index->{value}->{$query}; |
176
|
|
|
|
|
|
|
|
177
|
14
|
|
|
|
|
131
|
return; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item $id = $dictionary->id |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item $name = $dictionary->name |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Returns the id (name) of $dictionary, e.g. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
svg |
187
|
|
|
|
|
|
|
x11 |
188
|
|
|
|
|
|
|
vaccc |
189
|
|
|
|
|
|
|
nbs-iscc-f |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub id { |
194
|
50
|
|
|
50
|
1
|
109
|
my $self = shift; |
195
|
50
|
|
66
|
|
|
304
|
return _parse_id(ref $self || $self); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
*name = \&id; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item $title = $dictionary->title |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Returns the title of $dictionary, e.g. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
SVG |
204
|
|
|
|
|
|
|
X11 |
205
|
|
|
|
|
|
|
VACCC |
206
|
|
|
|
|
|
|
NBS/ISCC F |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub title { |
211
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
212
|
0
|
|
|
|
|
|
return $self->_description->{title}; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item $subtitle = $dictionary->subtitle |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Returns the subtitle of $dictionary, if any |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub subtitle { |
222
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
223
|
0
|
|
|
|
|
|
return $self->_description->{subtitle}; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item $description = $dictionary->description |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Returns the description of $dictionary, if any |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub description { |
233
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
234
|
0
|
|
|
|
|
|
return $self->_description->{description}; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
1; |