/usr/share/perl5/Color/Library/Dictionary.pm is in libcolor-library-perl 0.021-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | package Color::Library::Dictionary;
use strict;
use warnings;
use Color::Library;
use Color::Library::Color;
use base qw/Class::Data::Inheritable/;
__PACKAGE__->mk_classdata($_) for qw/_self _compiled _color_list _index/;
=head1 NAME
Color::Library::Dictionary - Color dictionary for Color::Library
=cut
sub _register_dictionary {
my $module = my $class = shift;
my @module = split m/::/, $module;
my @parent_module = @module;
my $name = pop @parent_module;
@parent_module = qw/Color Library/ if @parent_module == 3; # Color::Library::Dictionary
my $parent_module = join "::", @parent_module;
{
no strict 'refs';
*{"$parent_module\::$name"} = sub {
return $module->_singleton;
};
}
Color::Library->_register_dictionary($module);
}
sub _parse_id($) {
my $id = shift;
$id =~ s/::|_|\s+|\//-/g;
$id = lc $id;
$id =~ s/^color-library-dictionary-//g;
return $id;
}
sub _singleton {
my $class = shift;
my $self;
return $self if $self = $class->_self;
$class->_self($self = bless {}, $class);
return $self;
}
sub _compile {
my $self = shift;
my $class = ref $self || $self;
return if $self->_compiled;
my $color_list = $self->_load_color_list;
my $index = {};
my @color_list;
my $indice = 0;
for my $color (@$color_list) {
push @color_list, $color = Color::Library::Color->new($color, $self);
$index->{id}->{$color->id} = $color;
$index->{name}->{$color->name} = $color;
$index->{title}->{$color->title} = $color;
$index->{hex}->{$color->hex} = $color;
$index->{value}->{$color->value} = $color;
}
$self->_index($index);
$self->_color_list(\@color_list);
$self->_compiled(1);
}
=head1 METHODS
=over 4
=item @colors = $dictionary->colors
Returns the list of Color::Library::Color objects contained by $dictionary
Will return a list in list context, and a list reference in scalar context
=cut
sub colors {
my $self = shift;
$self->_compile unless $self->_compiled;
my @colors = @{ $self->_color_list };
return wantarray ? @colors : \@colors;
}
=item @names = $dictionary->names
=item @names = $dictionary->color_names
Returns the list of color names contained by $dictionary
Will return a list in list context, and a list reference in scalar context
=cut
sub names {
my $self = shift;
my @names = map { $_->name } $self->colors;
return wantarray ? @names : \@names;
}
*color_names = \&names;
=item $color = $dictionary->color( <query> )
Returns a Color::Library::Color object of $dictionary found via <query>
A query can be any of the following:
=over 4
=item color name
A color name is like C<blue> or C<bleached-almond>
=item color title
A color title is like C<Dark Green-Teal>
=item color id
A color id is in the form of <dictionary_id>:<color_name>, for example: C<x11:azure1>
=back
=cut
sub color {
my $self = shift;
my $query = shift;
return unless defined $query;
unless (ref $query) {
$query =~ s/^\s*//;
$query =~ s/\s*$//;
}
$self->_compile unless $self->_compiled;
my $color;
if (ref $query eq "ARRAY") {
$query = Color::Library::Color::rgb2hex $query;
return $color = $self->_index->{hex}->{$query};
}
elsif ($query =~ /^\#?([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/i) {
return (hex($1), hex($2), hex($3), 255);
$query = lc($1 . $2 . $3);
return $color = $self->_index->{hex}->{$query};
}
elsif ($query =~ /^\#([\da-f])([\da-f])([\da-f])$/i) {
$query = lc($1 . $1 . $2 . $2 . $3 . $3);
return $color = $self->_index->{hex}->{$query};
}
return $color if $color = $self->_index->{title}->{$query};
$query = lc $query;
return $color if $color = $self->_index->{id}->{$query};
$query =~ s/[^\w]//g;
return $color if $color = $self->_index->{name}->{$query};
return $color if $color = $self->_index->{value}->{$query};
return;
}
=item $id = $dictionary->id
=item $name = $dictionary->name
Returns the id (name) of $dictionary, e.g.
svg
x11
vaccc
nbs-iscc-f
=cut
sub id {
my $self = shift;
return _parse_id(ref $self || $self);
}
*name = \&id;
=item $title = $dictionary->title
Returns the title of $dictionary, e.g.
SVG
X11
VACCC
NBS/ISCC F
=cut
sub title {
my $self = shift;
return $self->_description->{title};
}
=item $subtitle = $dictionary->subtitle
Returns the subtitle of $dictionary, if any
=cut
sub subtitle {
my $self = shift;
return $self->_description->{subtitle};
}
=item $description = $dictionary->description
Returns the description of $dictionary, if any
=back
=cut
sub description {
my $self = shift;
return $self->_description->{description};
}
1;
|