CSS(3pm)

πŸ“¦
version 1.09 Β· 4 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– 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 CSS object is the head of the tree, the mother of the house.
  • she contains a list of CSS::Style objects β€” each one is a CSS ruleset.
  • each of those contains a list of selectors and properties.
  • every selector gets stored as a CSS::Selector object.
  • every property gets stored as a CSS::Property object and holds a list of values.
  • those values are stored as CSS::Value objects.

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() or new( { ..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 ) or read_file( @filenames ) β€” Read one or mores files and parse the CSS within them. πŸ“‚ (again, mores is the original, we leave it, it's part of the lore)
  • read_string( $scalar ) or read_string( @strings ) β€” Read one or more strings and parse the CSS within them. πŸ“
  • output() or output( '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 first CSS::Style object 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::Style
  • CSS::Selector
  • CSS::Property
  • CSS::Value
  • CSS::Parse
  • CSS::Parse::Lite
  • CSS::Parse::Heavy
  • CSS::Parse::Compiled
  • CSS::Parse::PRDGrammar
  • CSS::Adaptor
  • CSS::Adaptor::Pretty
  • CSS::Adaptor::Debug
  • perl(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