1WebService::Validator::UCsSeSr::CWo3nCt(r3i)buted Perl DWoecbuSmeernvtiactei:o:nValidator::CSS::W3C(3)
2
3
4
6 WebService::Validator::CSS::W3C - Interface to the W3C CSS Validator
7
9 use WebService::Validator::CSS::W3C;
10
11 my $css = "p { color: not-a-color }";
12 my $val = WebService::Validator::CSS::W3C->new;
13 my $ok = $val->validate(string => $css);
14
15 if ($ok and !$val->is_valid) {
16 print "Errors:\n";
17 printf " * %s\n", $_->{message}
18 foreach $val->errors
19 }
20
22 This module is an interface to the W3C CSS Validation online service
23 <http://jigsaw.w3.org/css-validator/>, based on its SOAP 1.2 support.
24 It helps to find errors in Cascading Style Sheets.
25
26 The following methods are available:
27
28 my $val = WebService::Validator::CSS::W3C->new
29 my $val = WebService::Validator::CSS::W3C->new($ua)
30 my $val = WebService::Validator::CSS::W3C->new($ua, $url)
31 Creates a new WebService::Validator::CSS::W3C object. A custom
32 LWP::UserAgent object can be supplied which is then used for HTTP
33 communication with the CSS Validator. $url is the URL of the CSS
34 Validator, "http://jigsaw.w3.org/css-validator/validator" by
35 default.
36
37 my $success = $val->validate(%params)
38 Validate a style sheet, takes %params as defined below. Either
39 "string" or "uri" must be supplied. Returns a true value if the
40 validation succeeded (regardless of whether the style sheet
41 contains errors).
42
43 string => $css
44 A style sheet as a string. It is currently unlikely that
45 validation will work if the string is not a legal UTF-8 string.
46 If a string is specified, the "uri" parameter will be ignored.
47 Note that "GET" will be used to pass the string to the
48 Validator, it might not work with overly long strings.
49
50 uri => $uri
51 The location of a style sheet or a HTML/XHTML/SVG document
52 containing or referencing style sheets.
53
54 medium => "print"
55 The medium for which the style sheet should apply, one of
56 "aural", "braille", "embossed", "handheld", "print", "screen",
57 "tty", "tv", and "presentation". A special value "all" can
58 also be specified. The default is "undef" in which case the CSS
59 Validator determines a value; this would currently be as if
60 "all" had been specified.
61
62 profile => "css3"
63 The CSS Version or profile to validate against, legal values
64 are "css1", "css2", "css21", "css3", "svg", "svgbasic",
65 "svgtiny", "mobile", "atsc-tv", and "tv". A special value
66 "none" can also be used. The default is "undef" in which case
67 the CSS Validator determines a default.
68
69 warnings => 2
70 Either "no" or an integer 0 - 2 that determines how many
71 warning messages you want to get back from the CSS Validator.
72 "no" means no warning, 0 means only the most serious warnings,
73 and 2 will give all warnings, including low level ones. The
74 defaut is "undef" in which case the CSS Validator determines a
75 default value; this is expected to be as if 1 had been
76 specified.
77
78 language => "de"
79 The desired language of the supposedly human-readable messages.
80 The string will passed as an "Accept-Language" header in the
81 HTTP request. The CSS Validator currently supports "en", "de",
82 "fr", "ja", "nl", "zh", and "zh-cn".
83
84 my $success = $val->success
85 Same as the return value of "validate()".
86
87 my $is_valid = $val->is_valid
88 Returns a true value if the last attempt to "validate()" succeeded
89 and the validator reported no errors in the style sheet.
90
91 my $num_errors = $val->errorcount
92 returns the number of errors found for the checked style sheet.
93 Get the details of the errors with $val->errors (see below).
94
95 my @errors = $val->errors
96 Returns a list with information about the errors found for the
97 style sheet. An error is a hash reference; the example in the
98 synopsis would currently return something like
99
100 ( {
101 context => 'p',
102 property => 'color',
103 expression => { start => '', end => 'not-a-color' }
104 errortype => 'parse-error',
105 message => 'not-a-color is not a color value',
106 line => 0,
107 } )
108
109 my $num_warnings = $val->warningcount
110 returns the number of warnings found for the checked style sheet.
111 Get the details of each warning with $val->warnings (see below).
112
113 my @warnings = $val->warnings
114 Returns a list with information about the warnings found for the
115 style sheet.
116
117 my $ua = $val->user_agent
118 my $ua = $val->user_agent($new_ua)
119 The LWP::UserAgent object you supplied to the constructor or a
120 custom object created at construction time you can manipulate.
121
122 # set timeout to 30 seconds
123 $val->user_agent->timeout(30);
124
125 You can also supply a new object to replace the old one.
126
127 my $uri = $val->validator_uri
128 my $uri = $val->validator_uri($validator_uri)
129 Gets or sets the URI of the validator. If you did not specify a
130 custom URI, "http://jigsaw.w3.org/css-validator/validator" by
131 default.
132
133 my $response = $val->response
134 The HTTP::Response object returned from the last request. This is
135 useful to determine why validation might have failed.
136
137 if (!$val->validate(string => $css)) {
138 if (!$val->response->is_success) {
139 print $val->response->message, "\n"
140 }
141 }
142
143 my $uri = $val->request_uri
144 The URI object used for the last request.
145
146 my $som = $val->som
147 The SOAP::SOM object for the last successful deserialization, check
148 the return value of "validate()" or "success()" before using the
149 object.
150
152 This module uses the SOAP interface for the W3C CSS validatom, which
153 still has a number of bugs, tracked via W3C's Bugzilla,
154 <http://www.w3.org/Bugs/Public/>.
155
156 Please report bugs in the W3C CSS Validator to www-validator-css@w3.org
157 or enter them directly in Bugzilla (see above). Please report bugs in
158 this module via RT, <http://rt.cpan.org/>.
159
161 This module is not directly associated with the W3C. Please remember
162 that the CSS Validator is a shared resource so do not abuse it: you
163 should sleep between requests, and consider installing the Validator
164 locally, see <http://jigsaw.w3.org/css-validator/DOWNLOAD.html>.
165
167 Copyright 2004-2013 Bjoern Hoehrmann <bjoern@hoehrmann.de>.
168 This module is licensed under the same terms as Perl itself.
169
170
171
172perl v5.28.1 2013-05-05WebService::Validator::CSS::W3C(3)