1Web::Scraper::Filter(3pUms)er Contributed Perl DocumentatWieobn::Scraper::Filter(3pm)
2
3
4

NAME

6       Web::Scraper::Filter - Base class for Web::Scraper filters
7

SYNOPSIS

9         package Web::Scraper::Filter::YAML;
10         use base qw( Web::Scraper::Filter );
11         use YAML ();
12
13         sub filter {
14             my($self, $value) = @_;
15             YAML::Load($value);
16         }
17
18         1;
19
20         use Web::Scraper;
21
22         my $scraper = scraper {
23             process ".yaml-code", data => [ 'TEXT', 'YAML' ];
24         };
25

DESCRIPTION

27       Web::Scraper::Filter is a base class for text filters in Web::Scraper.
28       You can create your own text filter by subclassing this module.
29
30       There are two ways to create and use your custom filter. If you name
31       your filter Web::Scraper::Filter::Something, you just call:
32
33         process $exp, $key => [ 'TEXT', 'Something' ];
34
35       If you declare your filter under your own namespace, like
36       'MyApp::Filter::Foo',
37
38         process $exp, $key => [ 'TEXT', '+MyApp::Filter::Foo' ];
39
40       You can also inline your filter function or regexp without creating a
41       filter class:
42
43         process $exp, $key => [ 'TEXT', sub { s/foo/bar/ } ];
44
45         process $exp, $key => [ 'TEXT', qr/Price: (\d+)/ ];
46         process $exp, $key => [ 'TEXT', qr/(?<name>\w+): (?<value>\w+)/ ];
47
48       Note that this function munges $_ and returns the count of replacement.
49       Filter code special cases if the return value of the callback is number
50       and $_ value is updated.
51
52       You can, of course, stack filters like:
53
54         process $exp, $key => [ '@href', 'Foo', '+MyApp::Filter::Bar', \&baz ];
55

AUTHOR

57       Tatsuhiko Miyagawa
58
59
60
61perl v5.30.0                      2019-07-26         Web::Scraper::Filter(3pm)
Impressum