NAME

CSS::DOM - Document Object Model for Cascading Style Sheets

VERSION

Version 0.02

This is an alpha version. The API is still subject to change. Many features have not been implemented yet (but patches would be welcome :-).

SYNOPSIS

use CSS::DOM;

$sheet = new CSS::DOM;
$sheet->read_string( $css_source );

# ...

DESCRIPTION

This module provides the CSS-specific interfaces described in the W3C DOM recommendation.

The CSS::DOM class itself implements the StyleSheet and CSSStyleSheet DOM interfaces, and inherits from CSS.

METHODS

Constructor

$style = new CSS::DOM;

Creates a new stylesheet object.

Attributes

type

Returns the string 'text/css'.

disabled

Allows one to specify whether the style sheet is used. (This attribute is not actually used yet by CSS::DOM.)

ownerNode

Returns the node that 'owns' this style sheet.

parentStyleSheet

This currently just returns an empty list.

href

Returns the style sheet's URI, if applicable.

title

Returns the value of the owner node's title attribute.

media

Returns the MediaList associated with the style sheet (or a plain list in list context). This defaults to an empty list. You can pass a comma-delimited string to the MediaList's mediaText method to initialise it.

(The medium information is not actually used [yet] by CSS::DOM, but you can put it there.)

ownerRule

This currently just returns an empty list (or undef in scalar context).

cssRules

In scalar context, this returns a CSS::DOM::RuleList object (simply a blessed array reference) of CSS::DOM::Rule objects. In list context it returns a list.

insertRule ( $css_code, $index )

Parses the rule contained in the $css_code, inserting it the style sheet's list of rules at the given $index.

deleteRule ( $index )

Deletes the rule at the given $index.

hasFeature ( $feature, $version )

You can call this either as an object or class method.

This is actually supposed to be a method of the 'DOMImplementation' object. (See, for instance, HTML::DOM::Interface's method of the same name, which delegates to this one.) This returns a boolean indicating whether a particular DOM module is implemented. Right now it returns true only for the 'CSS2' and 'StyleSheets' features (version '2.0').

Non-DOM Methods

set_ownerNode

This allows you to set the value of ownerNode. Passing an argument to ownerNode does nothing, because it is supposed to be read-only. But you have to be able to set it somehow, so that's why this method is here.

The style sheet will hold a weak reference to the object passed to this method.

set_href

Like set_ownerNode, but for href.

CLASSES AND DOM INTERFACES

Here are the inheritance hierarchy of CSS::DOM's various classes and the DOM interfaces those classes implement. For brevity's sake, a simple '::' at the beginning of a class name in the left column is used for 'CSS::DOM::'. Items in brackets do not exist yet. (See also CSS::DOM::Interface for a machine-readable list of standard methods.)

 Class Inheritance Hierarchy  Interfaces
 ---------------------------  ----------
 
 CSS
     CSS::DOM                 StyleSheet, CSSStyleSheet
 ::Array
     ::MediaList              MediaList
     ::StyleSheetList         StyleSheetList
     ::RuleList               CSSRuleList
 ::Rule                       CSSRule
     ::Rule::Style            CSSStyleRule
    [::Rule::Media            CSSMediaRule]
    [::Rule::FontFace         CSSFontFaceRule]
    [::Rule::Page             CSSPageRule]
    [::Rule::Import           CSSImportRule]
    [::Rule::Charset          CSSCharsetRule]
    [::Rule::Unknown          CSSUnknownRule]
 ::StyleDecl                  CSSStyleDeclaration, CSS2Properties
[::Value                      CSSValue]
    [::Value::Primitive       CSSPrimitiveValue]
    [::Value::List            CSSValueList]
[::RGBColor                   RGBColor]
[::Rect                       Rect]
[::Counter                    Counter]

CSS::DOM does not implement the following interfaces (see HTML::DOM for these):

LinkStyle
DocumentStyle
ViewCSS
DocumentCSS
DOMImplementationCSS
ElementCSSInlineStyle

IMPLEMENTATION NOTES

  • Attributes of objects are accessed via methods of the same name. When the method is invoked, the current value is returned. If an argument is supplied, the attribute is set (unless it is read-only) and its old value returned.

  • Where the DOM spec. says to use null, undef or an empty list is used.

  • Instead of UTF-16 strings, CSS::DOM uses Perl's Unicode strings.

  • Each method that the specification says returns an array-like object (e.g., a RuleList) will return such an object in scalar context, or a simple list in list context. You can use the object as an array ref in addition to calling its item and length methods.

PREREQUISITES

perl 5.8.0 or later

CSS.pm version 1 or later

Scalar::Util 1.08 or later

Exporter 5.57 or later

BUGS

To report bugs, please e-mail the author.

AUTHOR & COPYRIGHT

Copyright (C) 2007 Father Chrysostomos <sprout [at] cpan [dot] org>

This program is free software; you may redistribute it and/or modify it under the same terms as perl.

SEE ALSO

All the classes listed above under "CLASSES AND DOM INTERFACES".

CSS.pm and HTML::DOM

The DOM Level 2 Style specification at http://www.w3.org/TR/DOM-Level-2-Style

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 158:

Non-ASCII character seen before =encoding in 'I’ve'. Assuming UTF-8

Around line 351:

You forgot a '=back' before '=head1'