---
name: "CSS::DOM::Value::Primitive"
section: "3pm"
platform: "linux"
package: "libcss-dom-perl"
version: "0.17-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/CSS::DOM::Value::Primitive"
---

# CSS::DOM::Value::Primitive(3pm)

CSSPrimitiveValue class for CSS::DOM

## NAME

CSS::DOM::Value::Primitive - CSSPrimitiveValue class for CSS::DOM

## VERSION

Version 0.17

## SYNOPSIS

```
  # ...
```

## DESCRIPTION

This module implements objects that represent CSS primitive property  values (as opposed to lists). It implements the DOM CSSPrimitiveValue, Rect, and RGBColor interfaces.

## METHODS

If you need the constructor, it's below the object methods. Normally you would get an object via CSS::DOM::Style's `"getPropertyCSSValue"` method.

### CSSValue Interface

- cssText

  Returns a string representation of the attribute. Pass an argument to set  it.

- cssValueType

  Returns `"CSS::DOM::Value::CSS_PRIMITIVE_VALUE"`.

### CSSPrimitiveValue Interface

- primitiveType

  Returns one of the "CONSTANTS" listed below.

- getFloatValue

  Returns a number if the value is numeric.

The rest have still to be implemented.

### Rect Interface

The four methods `"top"`, `"right"`, `"bottom"` and `"left"` each return another value object representing the individual value.

### RGBColor Interface

The four methods `"red"`, `"green"`, `"blue"` and `"alpha"` each return another value object representing the individual value.

### Constructor

You probably don't need to call this, but here it is anyway:

```
  $val = new CSS::DOM::Value::Primitive:: %args;
```

The hash-style arguments are as follows. Only `"type"` and `"value"` are required.

- type

  One of the constants listed below under "CONSTANTS"

- value

  The data stored inside the value object. The format expected depends on the type. See below.

- css

  CSS code used for serialisation. This will make reading `"cssText"` faster at least until the value is modified.

- owner

  The style object that owns this value; if this is omitted, then the value is read-only. The value object holds a weak reference to the owner.

- property

  The name of the CSS property to which this value belongs. `"cssText"` uses this to determine how to parse text passed to it. This does not apply to the sub-values of colours, counters and rects, but it *does* apply to individual elements of a list value.

- index

  The index of this value within a list value (only applies to elements of a list, of course).

- format

  This is used by sub-values of colours and rects. It determines how assignment to `"cssText"` is handled. This uses the same syntax as the formats in CSS::DOM::PropertyParser.

Here are the formats for the `"value"` argument, which depend on the type:

- CSS\_UNKNOWN

  A string of CSS code.

- CSS\_NUMBER, CSS\_PERCENTAGE

  A simple scalar containing a number.

- Standard Dimensions

  Also a simple scalar containing a number.

  This applies to `"CSS_EMS"`, `"CSS_EXS"`, `"CSS_PX"`, `"CSS_CM"`, `"CSS_MM"`, `"CSS_IN"`, `"CSS_PT"`, `"CSS_PC"`, `"CSS_DEG"`, `"CSS_RAD"`, `"CSS_GRAD"`, `"CSS_MS"`, `"CSS_S"`, `"CSS_HZ"` and `"CSS_KHZ"`.

- CSS\_DIMENSION

  An array ref: `"[$number, $unit_text]"`

- CSS\_STRING

  A simple scalar containing a string (not a CSS string literal; i.e., no quotes or escapes).

- CSS\_URI

  The URL (not a CSS literal)

- CSS\_IDENT

  A string (no escapes)

- CSS\_ATTR

  A string containing the name of the attribute.

- CSS\_COUNTER

  An array ref: `"[$name, $separator, $style]"`

  `$separator` and `$style` may each be `"undef"`. If `$separator` is `"undef"`, the object represents a `"counter(...)"`. Otherwise it represents `"counters(...)"`.

- CSS\_RECT

  An array ref: `"[$top, $right, $bottom, $left]"`

  The four elements are either CSSValue objects or array refs of arguments to be passed to the constructor. E.g.:

  ```
   [
       [type => CSS_PX, value => 20],
       [type => CSS_PERCENTAGE, value => 50],
       [type => CSS_PERCENTAGE, value => 50],
       [type => CSS_PX, value => 50],
   ]
  ```

  When these array refs are converted to objects, the `"format"` argument is supplied automatically, so you do not need to include it here.

- CSS\_RGBCOLOR

  A string beginning with '#', with no escapes (such as '#fff' or '#c0ffee'), a colour name (like red) or an array ref with three to four elements:

  ```
   [$r, $g, $b]
   [$r, $g, $b, $alpha]
  ```

  The elements are either CSSValue objects or array refs of argument lists, as with `"CSS_RECT"`.

## CONSTANTS

The following constants can be imported with  `"use CSS::DOM::Value::Primitive ':all'"`. They represent the type of primitive value.

- CSS\_UNKNOWN

  - CSS\_NUMBER

  - CSS\_PERCENTAGE

  - CSS\_EMS

  - CSS\_EXS

  - CSS\_PX

  - CSS\_CM

  - CSS\_MM

  - CSS\_IN

  - CSS\_PT

  - CSS\_PC

  - CSS\_DEG

  - CSS\_RAD

  - CSS\_GRAD

  - CSS\_MS

  - CSS\_S

  - CSS\_HZ

  - CSS\_KHZ

  - CSS\_DIMENSION

  - CSS\_STRING

  - CSS\_URI

  - CSS\_IDENT

  - CSS\_ATTR

  - CSS\_COUNTER

  - CSS\_RECT

  - CSS\_RGBCOLOR

  ## SEE ALSO

CSS::DOM

CSS::DOM::Value

CSS::DOM::Value::List

CSS::DOM::Style
