| CSS::Inliner::Parser(3pm) | User Contributed Perl Documentation | CSS::Inliner::Parser(3pm) |
CSS::Inliner::Parser - Interface through which to read/write CSS files while respecting the cascade order
NOTE: This sub-module very seriously focuses on respecting cascade
order. As such this module is not for you
if you want to modified a stylesheet once it's read. If you are looking for
that functionality you may
want to look at the sister module, CSS::Simple
use CSS::Inliner::Parser;
my $css = new CSS::Inliner::Parser();
$css->read({ filename => 'input.css' });
#perform manipulations...
$css->write({ filename => 'output.css' });
Class for reading and writing CSS. Unlike other CSS classes on CPAN this particular module focuses on respecting the order of selectors. This is very useful for things like... inlining CSS, or for similar "strict" CSS work.
warns_as_errors (optional). Boolean value to indicate whether fatal errors should occur during parse failures.
This method requires you to pass in a params hash that contains a filename argument. For example:
$self->read_file({ filename => 'myfile.css' });
Compound selectors (i.e. "a, span") are split apart during parsing and stored separately, so the output of any given stylesheet may not match the output 100%, but the rules themselves should apply as expected.
This method requires you to pass in a params hash that contains scalar css data. For example:
$self->read({ css => $css });
This method requires you to pass in a params hash that contains a filename argument. For example:
$self->write_file({ filename => 'myfile.css' });
This code makes some assumptions about the nature of the prelude and data portions of the stored css rules and possibly is insufficient.
Note: content warnings are initialized at read time. In order to receive back content feedback you must perform read() first.
The structures returned match up with the fields set while adding the rules via the add_x_rule collection methods.
Specifically at-rules will contain a type, prelude and block while qualified rules will contain a selector and declarations.
The most common type of CSS rule is a qualified rule. This term became more prominent with the rise of CSS3, but is still relevant when handling earlier versions of the standard. These rules have a prelude consisting of a CSS selector, along with a data block consisting of various rule declarations.
Adding a qualified rule is trivial, for example: $self->add_qualified_rule({ selector => 'p > a', block => 'color: blue;' });
The less common variants of CSS rules are know as at-rules. These rules implement various behaviours through various expressions containing a rule type, prelude and associated data block. The standard is evolving here, so it is not easy to enumerate such examples, but these rules always start with @.
At rules are a little more complex, an example: $self->add_at_rule({ type => '@media', prelude => 'print', block => 'body { font-size: 10pt; }' });
Kevin Kamel <"kamelkev@underprint.com">
This module is directly based off of Adam Kennedy's <adamk@cpan.org> CSS::Tiny module.
This particular version differs in terms of interface and the ultimate ordering of the CSS.
This module is a derived version of Adam Kennedy's CSS::Tiny Module.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
| 2023-08-02 | perl v5.36.0 |