Web::S...Filter(3pm)
β¨ Web::Scraper::Filter β the base class glow-up β¨
okay bestie, so this is the manual page for Web::Scraper::Filter (which shows up in your terminal as Web::S...Filter(3pm) because, like, the header truncates it β tragic, I know π). It's a User Contributed Perl Documentation page and it is lowkey the blueprint for making your own text filters in Web::Scraper. Let's get into it π«Ά
πΈ NAME πΈ
Web::Scraper::Filter β the base class for Web::Scraper filters. the origin story, the blueprint, the main character π
π SYNOPSIS π
here's the vibe, verbatim, no notes:
package Web::Scraper::Filter::YAML;
use base qw( Web::Scraper::Filter );
use YAML ();
sub filter {
my($self, $value) = @_;
YAML::Load($value);
}
1;
use Web::Scraper;
my $scraper = scraper {
process ".yaml-code", data => [ 'TEXT', 'YAML' ];
};
likeβ¦ a whole custom filter in, what, ten lines? she ate and left no crumbs π
π¦ DESCRIPTION π¦
Web::Scraper::Filter is a base class for text filters in Web::Scraper. You wanna build your own text filter? You subclass this module. That's it. That's the whole assignment. β¨
There are two ways to create and use your custom filter:
- If you name your filter
Web::Scraper::Filter::Something, you just call:
process $exp, $key => [ 'TEXT', 'Something' ];
- If you declare your filter under your own namespace, like
'MyApp::Filter::Foo', then you say:
process $exp, $key => [ 'TEXT', '+MyApp::Filter::Foo' ];
(see that little +? that's the "not a core filter, bestie, look in my namespace" signal π«Ά)
π inline filters, because who has time for a whole class π
You can also inline your filter function or regexp without creating a filter class at all:
process $exp, $key => [ 'TEXT', sub { s/foo/bar/ } ];
process $exp, $key => [ 'TEXT', qr/Price: (\d+)/ ];
process $exp, $key => [ 'TEXT', qr/(?<name>\w+): (?<value>\w+)/ ];
yes, named captures included. we love a glow-up. π
β οΈ okay important, listen up: this function munges$_and returns the count of replacement. Filter code special cases if the return value of the callback is number and$_value is updated. that's the rule, that's the lore, don't fight it π
π stacking, because more is more π
You can, of course, stack filters like:
process $exp, $key => [ '@href', 'Foo', '+MyApp::Filter::Bar', \&baz ];
filter, filter, filter, coderef β a whole little relay race and honestly? iconic. πββοΈπ¨
π AUTHOR π
Tatsuhiko Miyagawa β the legend, the moment, the whole reason we're here π«Ά
and that's the page, bestie!! this gem of a doc came to you via perl v5.34.0, dated 2022-06-28 β so if you're reading this years later, she's vintage and still slaying. bye pookie, go write a filter πβ¨π
π¦ where this page comes from
- debian bookworm: libweb-scraper-perl 0.38-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libweb-scraper-perl 0.38-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libweb-scraper-perl 0.38-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libweb-scraper-perl 0.38-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libweb-scraper-perl 0.38-2 Β· 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