CSS::I...Parser(3pm)

πŸ“¦
version 4027 Β· 5 versions
, in ubuntu resolute, ubuntu stonking

✨ 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 the CSS::Inliner::Parser object 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