XML::SA...tLocator(3)

🌸 NAME 🌸

XML::SAX::DocumentLocator β€” bestie's fave little helper class for document locators, no cap πŸ’…


✨ SYNOPSIS ✨

okay so here's the whole vibe, literally copy-paste blessed:

my $locator = XML::SAX::DocumentLocator->new(
    sub { $object->get_public_id },
    sub { $object->get_system_id },
    sub { $reader->current_line },
    sub { $reader->current_column },
    sub { $reader->get_encoding },
    sub { $reader->get_xml_version },
);

like… look at her go πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

so this module hands you a tied hash reference that calls the closures you specify whenever someone asks it for PublicId, SystemId, LineNumber and ColumnNumber. the way that it just knows?? iconic. πŸ”₯

it's highkey useful when you're writing SAX Parsers, because then you don't have to constantly update the line numbers in a hash reference on the object you pass to set_document_locator(). that's the whole point, fr fr β€” no more manual bookkeeping era πŸ’€

want a usage example? go peek at the source code for XML::SAX::PurePerl, it's right there being a whole role model πŸ‘‘


πŸ‘‘ API πŸ‘‘

there is literally only 1 method: new. that's it. that's the API. slay πŸ’–

simply pass it a list of closures that, when called, will return the PublicId, the SystemId, the LineNumber, the ColumnNumber, the Encoding and the XMLVersion respectively β€” in that exact order, bestie, order matters πŸ™ˆ

the closures are passed a single parameter: the key being requested. but honestly? you're free to ignore that. do what feels right ✨


and that's the whole page, bestie β€” go forth and locate those documents 🫢

this gem was brought to you by perl v5.42.0, dated 2024-03-04 β€” mwah, ily, bye πŸ’‹

πŸ“¦ where this page comes from