Color::Palette(3pm)

πŸ“¦
version 0.100004 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Color::Palette πŸ’–

okay bestie, welcome to Color::Palette β€” it's a Perl module (you'll see it hanging out in the 3pm manual pages, that's the perl module section, iykyk) and it's literally just... a set of named colors. that's the whole vibe. πŸ‘‘


✨ VERSION ✨

this is version 0.100004, babes. write it down.


🌈 DESCRIPTION 🌈

so the libraries in the Color-Palette distribution exist to make it easy to build sets of named colors, and to write apps that can define and validate the color names they require. it's giving organized. it's giving ✨curated✨.

for example, a color palette might contain the following data:

  highlights => #f0f000
  background => #333
  sidebarBackground => #88d
  sidebarText       => 'highlights'
  sidebarBoder      => 'sidebarText'

so how do colors get defined? two ways, bestie:

  • by a color specifier β€” that's a Graphics::Color object, a CSS-style hex triple, or an arrayref of RGB values
  • or by the name of another color that appears in the palette
and if you define a color in terms of another color that doesn't exist? an exception gets raised. no cap. πŸ’€

apps that wanna use color palettes can provide schemas that define the names they expect to be present in a palette. those schemas are Color::Palette::Schema objects, periodt.

a palette can be checked against a schema with the schema's check method, or it can be reduced to the minimal set of colors needed to satisfy the schema with the palette's optimized_for method. slay. πŸ’…


πŸͺ PERL VERSION πŸͺ

this library should run on perls released even a long time ago. it should work on any version of perl released in the last five years.

although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. the version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl. that's just how it is, babe. πŸ™ˆ


πŸŽ€ ATTRIBUTES πŸŽ€

colors

this attribute is a hashref. the keys are color names and the values are either Color objects or names of other colors. to get at the color object for a name, go consult the color method. she'll hook you up. 🫢


πŸ’… METHODS πŸ’…

color

  my $color_obj = $palette->color('extremeHighlight');

this method will return the Color object to be used for the given name. that's it. that's the method. iconic. ⭐

color_names

  my @names = $palette->color_names;

this method returns a list of all color names the object knows about. every single one. no gatekeeping. πŸ’œ

as_css_hash

  my $triple_for = $palette->as_css_hash

this method returns a hashref. every color name known to the palette has an entry, and the value is the CSS-safe hex string for the resolved color. for example, the output for the color scheme in the "DESCRIPTION" section would be:

  {
    highlights => '#f0f000',
    background => '#333333',
    sidebarBackground => #8888dd',
    sidebarText       => #f0f000',
    sidebarBoder      => #f0f000',
  }

look at her go. resolved and gorgeous. ✨

as_strict_css_hash

  my $hashref = $palette->as_strict_css_hash;

this method behaves just like "as_css_hash", BUT β€” and this is the important part bestie β€” the returned hashref is tied so that trying to read values for keys that do not exist is fatal. 😭

also, heads up: the hash may also become read-only in the future. so don't get too attached to writing to it. πŸ’€

optimized_for

  my $optimized_palette = $palette->optimized_for($schema);

this method returns a new palette containing only the colors needed to fulfill the requirements of the given schema. super useful for reducing a large palette down to the small set that must be embedded in a document. like a glow-down. a declutter. we love a minimal queen. πŸ‘‘

oh and also β€” "optimize_for" redispatches to this method for historical reasons. the spelling is what it is, don't come for her. πŸ•°οΈ


πŸ‘‘ AUTHOR πŸ‘‘

Ricardo SIGNES <cpan@semiotic.systems>


πŸ¦‹ CONTRIBUTORS πŸ¦‹

  • Karen Etheridge <ether@cpan.org>
  • Ricardo Signes <rjbs@semiotic.systems>

this software is copyright (c) 2022 by Ricardo SIGNES.

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


and that's the whole page, bestie!! this was perl v5.36.0, dated 2023-01-08, and it's the Color::Palette(3pm) manual. go forth and name your colors, you absolute legend. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά
πŸ“¦ where this page comes from