SYNOPSIS

  use WebService::Validator::CSS::W3C;

  my $css = "p { color: not-a-color }";
  my $val = WebService::Validator::CSS::W3C->new;
  my $ok = $val->validate(string => $css);

  if ($ok and !$val->is_valid) {
      print "Errors:\n";
      printf "  * %s\n", $_->{message}
        foreach $val->errors
  }

DESCRIPTION

This module is an interface to the W3C \s-1CSS\s0 Validation online service http://jigsaw.w3.org/css-validator/ <http://jigsaw.w3.org/css-validator/>, based on its \s-1SOAP\s0 1.2 support. It helps to find errors in Cascading Style Sheets.

The following methods are available: Creates a new WebService::Validator::CSS::W3C object. A custom LWP::UserAgent object can be supplied which is then used for \s-1HTTP\s0 communication with the \s-1CSS\s0 Validator. $url is the \s-1URL\s0 of the \s-1CSS\s0 Validator, \*(C`http://jigsaw.w3.org/css-validator/validator\*(C' by default. Validate a style sheet, takes %params as defined below. Either \*(C`string\*(C' or \*(C`uri\*(C' must be supplied. Returns a true value if the validation succeeded (regardless of whether the style sheet contains errors).

A style sheet as a string. It is currently unlikely that validation will work if the string is not a legal \s-1UTF-8\s0 string. If a string is specified, the \*(C`uri\*(C' parameter will be ignored. Note that \*(C`GET\*(C' will be used to pass the string to the Validator, it might not work with overly long strings. The location of a style sheet or a \s-1HTML/XHTML/SVG\s0 document containing or referencing style sheets. The medium for which the style sheet should apply, one of \*(C`aural\*(C', \*(C`braille\*(C', \*(C`embossed\*(C', \*(C`handheld\*(C', \*(C`print\*(C', \*(C`screen\*(C', \*(C`tty\*(C', \*(C`tv\*(C', and \*(C`presentation\*(C'. A special value \*(C`all\*(C' can also be specified. The default is \*(C`undef\*(C' in which case the \s-1CSS\s0 Validator determines a value; this would currently be as if \*(C`all\*(C' had been specified. The \s-1CSS\s0 Version or profile to validate against, legal values are \*(C`css1\*(C', \*(C`css2\*(C', \*(C`css21\*(C', \*(C`css3\*(C', \*(C`svg\*(C', \*(C`svgbasic\*(C', \*(C`svgtiny\*(C', \*(C`mobile\*(C', \*(C`atsc-tv\*(C', and \*(C`tv\*(C'. A special value \*(C`none\*(C' can also be used. The default is \*(C`undef\*(C' in which case the \s-1CSS\s0 Validator determines a default.

warnings => 2

Either \*(L"no\*(R" or an integer 0 - 2 that determines how many warning messages you want to get back from the \s-1CSS\s0 Validator. \*(L"no\*(R" means no warning, 0 means only the most serious warnings, and 2 will give all warnings, including low level ones. The defaut is \*(C`undef\*(C' in which case the \s-1CSS\s0 Validator determines a default value; this is expected to be as if 1 had been specified. The desired language of the supposedly human-readable messages. The string will passed as an \*(C`Accept-Language\*(C' header in the \s-1HTTP\s0 request. The \s-1CSS\s0 Validator currently supports \*(C`en\*(C', \*(C`de\*(C', \*(C`fr\*(C', \*(C`ja\*(C', \*(C`nl\*(C', \*(C`zh\*(C', and \*(C`zh-cn\*(C'.

Same as the return value of \*(C`validate()\*(C'. Returns a true value if the last attempt to \*(C`validate()\*(C' succeeded and the validator reported no errors in the style sheet. returns the number of errors found for the checked style sheet. Get the details of the errors with $val->errors (see below). Returns a list with information about the errors found for the style sheet. An error is a hash reference; the example in the synopsis would currently return something like ( { context => 'p', property => 'color', expression => { start => '', end => 'not-a-color' } errortype => 'parse-error', message => 'not-a-color is not a color value', line => 0, } ) returns the number of warnings found for the checked style sheet. Get the details of each warning with $val->warnings (see below). Returns a list with information about the warnings found for the style sheet. The LWP::UserAgent object you supplied to the constructor or a custom object created at construction time you can manipulate. # set timeout to 30 seconds $val->user_agent->timeout(30); You can also supply a new object to replace the old one. Gets or sets the \s-1URI\s0 of the validator. If you did not specify a custom \s-1URI\s0, \*(C`http://jigsaw.w3.org/css-validator/validator\*(C' by default. The HTTP::Response object returned from the last request. This is useful to determine why validation might have failed. if (!$val->validate(string => $css)) { if (!$val->response->is_success) { print $val->response->message, "\n" } } The \s-1URI\s0 object used for the last request. The \s-1SOAP::SOM\s0 object for the last successful deserialization, check the return value of \*(C`validate()\*(C' or \*(C`success()\*(C' before using the object.

BUGS

This module uses the \s-1SOAP\s0 interface for the W3C \s-1CSS\s0 validatom, which still has a number of bugs, tracked via W3C's Bugzilla, <http://www.w3.org/Bugs/Public/>.

Please report bugs in the W3C \s-1CSS\s0 Validator to [email protected] or enter them directly in Bugzilla (see above). Please report bugs in this module via \s-1RT\s0, <http://rt.cpan.org/>.

NOTE

This module is not directly associated with the W3C. Please remember that the \s-1CSS\s0 Validator is a shared resource so do not abuse it: you should sleep between requests, and consider installing the Validator locally, see http://jigsaw.w3.org/css-validator/DOWNLOAD.html <http://jigsaw.w3.org/css-validator/DOWNLOAD.html>.

AUTHOR / COPYRIGHT / LICENSE

Copyright 2004-2013 Bjoern Hoehrmann <[email protected]>. This module is licensed under the same terms as Perl itself.