Acme-AutoColor

 view release on metacpan or  search on metacpan

lib/Acme/AutoColor.pm  view on Meta::CPAN

package Acme::AutoColor;

use 5.006;
use strict;
use warnings;

use Graphics::ColorNames 0.32;

our $VERSION = '0.04';

our $Colors;

sub import {
  my $class = shift;
  # TODO: parse version numbers
  $Colors = Graphics::ColorNames->new(@_);
}

package main;

use Carp qw( croak );
use Graphics::ColorNames qw( hex2tuple );

our $AUTOLOAD;

sub AUTOLOAD {
  my $class = shift;
  $AUTOLOAD =~ /.*::(\w+)/;

  my $cname = $1;

  if($cname eq "OCTARINE") {
     # Discworlds eigth color. Can't display it yet,
     # but as far as we know, R, G and B are zero,
     # and O is 255
     if(wantarray) {
       return(0,0,0,255);
     } else {
       return "000000ff";
     }
  }

  my $value = $Acme::AutoColor::Colors->hex($1);
  if (defined $value) {
    return wantarray ? hex2tuple($value) : $value;
  } else {
    croak "Unknown method: $cname";
  }
}

1;
__END__


=head1 NAME

Acme::AutoColor - automatic color names

=head1 SYNOPSIS

  use Acme::AutoColor;

  $red   = RED();    # 'ff0000'
  @green = GREEN();  # (0, 255, 0)

=head1 DESCRIPTION

This module uses an AUTOLOAD function which assumes unrecognized methods
are color names.

Color names are case-insensitive, though style-wise one should
probably use all capitals.

It returns a hex string or a an array of RGB triplets depending on the
calling context.

Color schemes may be specified in the use line:

  use Acme::AutoColor qw( X HTML );

=head1 OCTARINE

Octarine is the discworlds eigth color. It can't actually displayed with a RGB color scheme,
but as far as we know, its R, G and B components are all zero and O is 0xff. But you can use it
anyway:



( run in 1.784 second using v1.01-cache-2.11-cpan-d06a3f9ecfd )