CSS::I...Parser(3pm)
β¨ NAME β¨
CSS::Inliner::Parser β bestie, this is your interface to read and write CSS files while fully respecting the cascade order π
NOTE: this sub-module is obsessed β like, genuinely obsessed β with respecting cascade order. So if your whole thing is "I wanna read a stylesheet and then go in and modify it," this module is not for you, sorry bestie π. If that's the energy you're after, go check out the sister module, CSS::Simple. She's got you π«Ά
πΈ SYNOPSIS πΈ
use CSS::Inliner::Parser;
my $css = new CSS::Inliner::Parser();
$css->read({ filename => 'input.css' });
#perform manipulations...
$css->write({ filename => 'output.css' });
π¦ DESCRIPTION π¦
It's a class for reading and writing CSS, periodt. But here's the thing that makes it hit different from every other CSS class on CPAN: this one actually cares about the order of your selectors π. That's highkey useful for stuff likeβ¦ inlining CSS, or any of those other "strict" CSS situations where the order is the whole point, iykyk β¨
π CONSTRUCTOR π
new ([ OPTIONS ])β spawns theCSS::Inliner::Parserobject into existence π§. It sets up the class variables that get used while files are being parsed and processed.warns_as_errors(optional) β a boolean value, and it tells you whether fatal errors should go down during parse failures. Boolean, so like, true/false, no in-between vibes π
π METHODS π
read_file( params )β opens up a CSS file, reads it, and then does all the parsing that has to happen so you can mess with it later π
This method needs you to pass in a params hash that's got a filename argument in it. Like so:
$self->read_file({ filename => 'myfile.css' });
read( params )β reads CSS data and parses it, storing the intermediate data in class variables β¨
Compound selectors (think "a, span") get split apart during parsing and stored separately, so ngl the output of any given stylesheet might not match the original 100% β but the rules themselves should apply exactly as expected π―
This method needs a params hash containing scalar css data. Like this:
$self->read({ css => $css });
write_file()β writes the parsed and manipulated CSS out to a file parameter π
This method needs a params hash containing a filename argument. For example:
$self->write_file({ filename => 'myfile.css' });
write()β writes the parsed and manipulated CSS out to a scalar and hands it back to you π
Heads up: this code makes some assumptions about the nature of the prelude and data portions of the stored css rules, and possibly is insufficient π
content_warnings()β returns back any warnings that got thrown while parsing a given block of css π
Note: content warnings are initialized at read time. So to get content feedback back, you have to do a read() first. No read, no tea β
get_rules( params )β gets you an array of rules representing the composition of the stylesheet π§. These rules come back in the exact order they were discovered β no shuffling, no cap π
Both qualified and at rules are returned by this method. It's left up to the caller to pull out the kinds of rules your application needs to accomplish your goals, bestie β she's not gonna gatekeep, but she's also not gonna guess π
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 β¨
add_qualified_rule( params )β adds a qualified CSS rule to the ruleset store π
The most common type of CSS rule is a qualified rule. This term got more prominent with the rise of CSS3, but it's still relevant when handling earlier versions of the standard. These rules have a prelude consisting of a CSS selector, plus 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;' });
add_at_rule( params )β adds an at-rule to the ruleset store π
The less common variants of CSS rules are known 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's 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; }' });
π AUTHOR π
Kevin Kamel <"kamelkev@underprint.com">
β ATTRIBUTION β
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, just so we're clear β¨
π LICENSE π
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 πΈ
okay bestie that's the whole page, mwah π β this was CSS::I...Parser(3pm), from the User Contributed Perl Documentation collection, running on perl v5.40.1, dated 2025-08-12. slay, go inline some CSS π¦
π¦ where this page comes from
- ubuntu resolute: libcss-inliner-perl 4027-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcss-inliner-perl 4027-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms