Web::Scraper::Filter(3pm)

Web::Scraper::Filter3pm

Base class for web::scraper filters

Usage

  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' ];
  };

Overview

Web::Scraper::Filter is a base class for text filters in Web::Scraper. You can create your own text filter by subclassing this module.

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',

  process $exp, $key => [ 'TEXT', '+MyApp::Filter::Foo' ];

You can also inline your filter function or regexp without creating a filter class:

  process $exp, $key => [ 'TEXT', sub { s/foo/bar/ } ];
  process $exp, $key => [ 'TEXT', qr/Price: (\d+)/ ];
  process $exp, $key => [ 'TEXT', qr/(?<name>\w+): (?<value>\w+)/ ];

Note that 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.

You can, of course, stack filters like:

  process $exp, $key => [ '@href', 'Foo', '+MyApp::Filter::Bar', \&baz ];

Releases

7 releases since Debian 7 (Wheezy); the text changed 3 times.

  1. 7
  2. 8–10
  3. 11
  4. 12–13

Author

Tatsuhiko Miyagawa

From libweb-scraper-perl 0.38-2 in Debian 13 (Trixie). Parsed by carta from the page's man source.