CSS(3pm)
π CSS(3pm) β the manual, but make it slay π
okay bestie, listen up. this is CSS, from the User Contributed Perl Documentation, and she is that girl. a whole object-oriented glow-up for Cascading Style Sheets. let's get into it π«Ά
β¨ NAME β¨
CSS β Object oriented access to Cascading Style Sheets (CSS). literally what it says on the tin, no cap π
πΈ SYNOPSIS πΈ
here's the vibe, copy-paste ready:
use CSS;
# create a CSS object with the default options
my $css = CSS->new();
# create a CSS object with a specific parser
my $css = CSS->new( { 'parser' => 'CSS::Parse::Lite' } );
my $css = CSS->new( { 'parser' => 'CSS::Parse::Heavy' } );
my $css = CSS->new( { 'parser' => 'CSS::Parse::Compiled' } );
# create a CSS object with a specific adaptor
my $css = CSS->new( { 'adaptor' => 'CSS::Adaptor' } );
my $css = CSS->new( { 'adaptor' => 'CSS::Adaptor::Pretty' } );
my $css = CSS->new( { 'adaptor' => 'CSS::Adaptor::Debug' } );
# parse some CSS from a string
$css->read_string( $css_data );
$css->read_string( ( $css_data, $more_css_data ) );
# parse some CSS from a file
$css->read_file( 'my_file.css' );
$css->read_file( ( 'my_file.css', 'my_other_file.css' ) );
# output the CSS using the current adaptor
print $css->output();
# set a new adaptor and then output the CSS
$css->set_adaptor( 'CSS::Adaptor::Foo' );
print $css->output();
# output the CSS using a tempory adaptor
print $css->output( 'CSS::Adaptor::Bar' );
# forget about the CSS we've already parsed
$css->purge();
(yes, tempory. that's the original spelling, we don't touch it, we respect the ancestors π)
π¦ DESCRIPTION π¦
so this module, right? pair it with a CSS::Parse::* module and it will parse your CSS data and turn it into a whole tree of objects. very demure, very structured. π³
then β and this is the iconic part β team it up with a CSS::Adaptor::* module and that cute little CSS data tree can get transformed into other formats. main character energy fr fr β¨
π¨ NOTICE π¨
bestie. read this one. From version 1.00 of this module onwards, backwards compatibility is broken. not a little broken. broken broken. π
why? because the way data is parsed and then represented internally changed a lot. huge. massive.
good news tho: Version 0.08 is still available on CPAN if you're feeling nostalgic: <http://search.cpan.org/author/IAMCAL/CSS-0.08/>
π TREE STRUCTURE π
okay so picture the family tree π
- the
CSSobject is the head of the tree, the mother of the house. - she contains a list of
CSS::Styleobjects β each one is a CSS ruleset. - each of those contains a list of selectors and properties.
- every selector gets stored as a
CSS::Selectorobject. - every property gets stored as a
CSS::Propertyobject and holds a list of values. - those values are stored as
CSS::Valueobjects.
here's the example:
foo, bar {
baz: fop;
woo: yay houpla;
}
the glow-up of that ^ would be one single CSS::Style object. that object then has two CSS::Selector objects repping 'foo' and 'bar'. it also has two CSS::Property objects repping 'baz' and 'woo'.
and then β nesting era β the 'baz' object has a single child CSS::Value object for 'fop', whilst the 'woo' object has two child objects for 'yay' and 'houpla'. it's giving β¨generationalβ¨ π
π METHODS π
π CONSTRUCTOR
new()ornew( { ..options.. } )β An optional hash can contain arguments:
parser module to use as the CSS parser
adaptor adaptor to use for output
π§ ACCESSORS
read_file( $filename )orread_file( @filenames )β Read one or mores files and parse the CSS within them. π (again,moresis the original, we leave it, it's part of the lore)read_string( $scalar )orread_string( @strings )β Read one or more strings and parse the CSS within them. πoutput()oroutput( 'CSS::Adaptor::Foo' )β Return a string representation of the CSS tree, using either the current adaptor or the specified one. π¨οΈset_adaptor( 'CSS::Adaptor::Bar' )β Set the current adaptor for the CSS tree. π§purge()β Forget all the objects in the CSS tree; π§Ή (yes the original ends on a semicolon, we keep it, she's quirky like that)get_style_by_selector( 'selector_name' )β Returns the firstCSS::Styleobject with the specified selector name attached. Returns zero on failure. π
π AUTHORS π
Copyright (C) 2001-2002, Allen Day <allenday@ucla.edu> π
Copyright (C) 2003-2004, Cal Henderson <cal@iamcal.com> π
π«Ά SEE ALSO π«Ά
go give these lil modules some love:
CSS::StyleCSS::SelectorCSS::PropertyCSS::ValueCSS::ParseCSS::Parse::LiteCSS::Parse::HeavyCSS::Parse::CompiledCSS::Parse::PRDGrammarCSS::AdaptorCSS::Adaptor::PrettyCSS::Adaptor::Debugperl(1)
and that's the whole page bestie, you ate it up π this lil doc is brought to you by perl v5.32.0, dated 2020-12-29, and it's the CSS(3pm) manual. periodt. π β¨π¦πΈ
π¦ where this page comes from
- debian bookworm: libcss-perl 1.09-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libcss-perl 1.09-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcss-perl 1.09-1.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