METHODS

new(@args)

Create a new RGB colour. This method is invoked when you USE the plugin from within a template.

[% USE col = Colour.RGB('#ffccdd') %]

The colour can be specified as a short (3 digit) or long (6 digit) hexadecimal number, with or without the leading '#'. A list or reference to a list of decimal red, green and blue values can also be provided:

When called without any arguments it simply returns itself, a blessed reference to a list of red, green and blue components. This is effectively a no-op, but can be useful to ensure that you have a colour defined in a particular colour space.

For example, say we have two colours, one of which is defined in the RGB colour space, the other in HSV (Hue, Saturation, Value - see Template::Plugin::Colour::HSV).

[% red = Colour.RGB('#C00');
orange = Colour.HSV(30, 255, 255);
%]

If we iterate over these colours in a FOREACH loop then we can't be sure if the colour we're looking at is defined in the RGB or HSV colour space. By calling the 'rgb' method against it we can convert any HSV colours to RGB, and leave those that are already RGB as they are.

When called without an argument, it returns the greyscale value for the current RGB colour. Because our eyes do not perceive the different red, green and blue components with equal intensity (green is the dominant colour in defining the perception of brightness, whereas blue contributes very little), the value returned is one based on the following formula which is widely accepted to give the most accurate value:

(red * 0.222) + (green * 0.707) + (blue * 0.071)

hex($x)

Get or set the value using hexadecimal notation. When called with an argument, it sets the red, green and blue components according to the value. This can be specified in short (3 digit) or long (6 digit) form, with or without a leading '#'.

When called without any arguments, it returns the current value as a 6 digit hexadecimal string without the leading '#'.

[% col.hex %] # 336699

Any alphabetical characters ('a'-'f') are output in lower case.

[% col.hex('#AABBCC') %]
[% col.hex %] # aabbcc

Use the HEX() method if you want them output in upper case.

HEX($x)

Wrapper around the hex() method which returns the hex string converted to upper case.

[% col.hex('#aabbcc') %]
[% col.hex %] # AABBCC

html($h)

Wrapper around the hex() method which prefixes the returned value with a '#', suitable for using directly as an HTML or CSS colour.

[% col.hex('#aabbcc') %]
[% col.html %] # #aabbcc

HTML($h)

Same as the html() method, but returning the colour in upper case, as per HEX().

[% col.hex('#aabbcc') %]
[% col.html %] # #AABBCC

hsv($h,$s,$v)

Convert the RGB colour to one in the HSV (hue, saturation, value) colour space, by creating a new Template::Plugin::Colour::HSV object. If arguments are provided then these are passed to the HSV constructor for hue, saturation and value parameters. Otherwise they are computed from the current RGB colour.