Parse:...e::Tag(3pm)

๐Ÿ“ฆ
version 0.15 ยท 2 versions
  • 0.15 ยท debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.15 ยท ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– NAME ๐Ÿ’–

Parse::BBCode::Tag โ€” the Tag Class for Parse::BBCode ๐Ÿท๏ธโœจ (it's a Perl module, bestie, from the User Contributed Perl Documentation collection ๐Ÿซถ)


๐ŸŒธ DESCRIPTION ๐ŸŒธ

okay so picture this: you parse some bbcode with Parse::BBCode, and Parse::BBCode::parse hands you back a parse tree made entirely of Tag objects. that's it. that's the whole vibe. every little tag you ever wrote is now a lil object in a tree and it's giving very organized, very demure ๐ŸŒˆ


โœจ METHODS โœจ

  • add_content
$tag->add_content('string');

glues 'string' right onto the end of the tag content. like adding a bead to a bracelet ๐Ÿ’…

$tag->add_content($another_tag);

same energy, but it appends $another_tag to the end of the tag content instead. tag-on-tag, no cap ๐ŸŽ€

  • raw_text
my $bbcode = $tag->raw_text;

gives you the raw text of the parse tree โ€” so every tag gets converted back into bbcode. it's the un-parsing. the reverse slay ๐Ÿ”ฅ

  • raw_content
my $bbcode = $tag->raw_content;

returns the raw content of the tag without the opening and closing tags. so if you have a tag that was parsed from

[i]italic and [bold]test[/b][/i]

you get back

italic and [bold]test[/b]

(yes the tags are messy in that example, that's literally the point, we're showing you the inside bits only ๐Ÿ™ˆ)

  • walk

utility to do a breadth first search ('bfs') over the parsed tree ๐ŸŒณ

$tag->walk('bfs', sub {
        # tag is in $_
        ...
        return 0;
    });

when the sub returns 1 it stops walking the tree. super useful for finding a certain tag โ€” like a little scavenger hunt but make it code ๐Ÿ”๐Ÿ’–


๐Ÿ‘‘ ACCESSORS ๐Ÿ‘‘

the accessors of a tag are currently

name attr attr_raw content finished start end close class

you can call each accessor with get_* and set_* โ€” so get it, set it, live your truth ๐Ÿ’…

  • name โ€” the tag name. for [i]...[/i] it is i, the lowercase tag name.
  • attr โ€” TODO ๐Ÿ™ˆ (yes that's really what it says, we're not hiding anything from you, bestie)
  • attr_raw โ€” the raw text of the attribute.
  • content โ€” an arrayref of the content of the tag, and each element is either a string or a tag itself. nesting! iconic.
  • finished โ€” used during parsing, true if the end of the tag was found. like a little checkbox that goes โœ… when the closing tag shows up.
  • start โ€” the original start string, e.g. "[size=7]"
  • end โ€” the original end string, e.g. "[/size]"
  • close โ€” true if the tag needs a closing tag. a tag which doesn't need a closing tag is [*] for example, inside of [list] tags.
  • class โ€” 'block', 'inline' or 'url'
  • single โ€” if this tag does not have a closing tag and also no content, like [hr], for example, set this to true. default is 0.
  • num โ€” absolute number of tag with this name in the tree. useful if you want to number code tags and offer download links. ๐Ÿงฎ
  • level โ€” level of tag.

for the tag [u] in the following bbcode

[b]bold [i]italic [u]underlined[/u][/i][/b]

it returns 3. deep in the stack, three levels down, main character energy ๐Ÿซถ


quick vibe check: everything above is exactly what the module does โ€” no invented features, no extra tips, just the facts wearing a cuter outfit โœจ

and that's a wrap, bestie!! this page came from the User Contributed Perl Documentation for perl v5.34.0, dated 2022-06-16 โ€” shoutout to that version and that date for making all of this possible ๐ŸŽ€๐Ÿฆ‹๐Ÿ’– mwah, go parse something gorgeous ๐Ÿ’…

๐Ÿ“ฆ where this page comes from