HTML::...ser::UA(3pm)

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

πŸ’– NAME πŸ’–

HTML::HTML5::Parser::UA β€” a simple web user agent class, bestie. That's it, that's the vibe. πŸ¦‹


✨ SYNOPSIS ✨

use aliased 'HTML::HTML5::Parser::UA';

my $response = UA->get($url);
die unless $response->{success};

print $response->{decoded_content};

look at her go. iconic behavior. πŸ’…


🌸 DESCRIPTION 🌸

okay so real talk, this whole thing is a simple wrapper sitting on top of HTTP::Tiny and LWP::UserAgent, and its entire job is to smooth out the API differences between the two so you don't have to deal with their little personality clashes. that's it. she's a mediator. no cap.

she only supports bog standard get($url) requests. nothing fancy. we're not doing POSTs today, bestie. πŸ™ˆ

here's the tea on how she picks her engine:

  • If LWP::UserAgent is already in memory, this module will use that. periodt.
  • If LWP::UserAgent is not in memory, then this module will use HTTP::Tiny (or direct filesystem access for file:// URLs β€” yes, she'll just read the file off disk like it's nothing πŸŽ€).
  • If LWP::UserAgent is not in memory, and you attempt to request a URL that HTTP::Tiny cannot handle (e.g. an ftp:// URL), then this module will load LWP::UserAgent and die if it cannot be loaded (e.g. is not installed). so like, she'll try, but if LWP isn't installed? πŸ’€ she's gone.

also psa: HTML::HTML5::Parser::UA is used by the parse_file method of HTML::HTML5::Parser. iykyk. πŸ‘‘

πŸŽ€ Class Method πŸŽ€

  • get($url, $ua) β€” gets the URL and returns a hashref similar to HTTP::Tiny's hashrefs, but with an additional decoded_content key, which contains the response body, decoded into a Perl character string (not a byte string). that's the little glow-up she brings to the table, and honestly? she ate. ✨

if $ua is given (it's optional, no pressure 🌈), then this user agent will be used to perform the actual request. it must be undef or an LWP::UserAgent object (or a subclass) or an HTTP::Tiny object (or a subclass). no random objects, bestie, she has standards. πŸ’…

πŸ’œ Package Variable πŸ’œ

  • $HTML::HTML5::Parser::NO_LWP β€” if true, avoids using LWP::UserAgent. she'll stay in her HTTP::Tiny lane. πŸ¦‹

🌈 MOTIVATION 🌈

okay so here's the lore. LWP::UserAgent is genuinely a good piece of software β€” no shade, she's a queen πŸ‘‘ β€” but she has a dependency on HTML::Parser. and HTML::Parser is only used to provide one fairly esoteric feature, which this package doesn't make use of.

which feature? it's the parse_head option. that's the whole reason. 😭

because of that, i don't especially want HTML::HTML5::Parser to have a dependency on LWP::UserAgent. hence this module. problem solved, slay. πŸ’…


⭐ SEE ALSO ⭐

  • HTML::HTML5::Parser.

🫢 AUTHOR 🫢

Toby Inkster, <tobyink@cpan.org> β€” legend behavior. πŸ’–


Copyright (C) 2012 by Toby Inkster

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. free as in freedom bestie πŸŽ€


😭 DISCLAIMER OF WARRANTIES 😭

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

fr fr, she is not liable. read that again. πŸ’€


and that's the whole page!! mwah πŸ’‹ this doc shipped with perl v5.36.0 and got its glow-up dated 2022-08-28 β€” go forth and get($url) responsibly, bestie. πŸ¦‹βœ¨

πŸ“¦ where this page comes from