Perl Diver 2.33
Main Environment Variables Perl Default Values Perl Config - Summary Perl Config - Full Installed Modules List Directory uptime Docs

Module Documentation
Details and documentation about a specific module, including version and documentation (if available). Note that while links to perldoc.com and search.cpan.org are provided, the module may be part of a larger distribution. If you reach a File Not Found page on either site, please try the parent module.

Web::Scraper::Filter

Name Web::Scraper::Filter
Version
Located at /usr/share/perl5
File /usr/share/perl5/Web/Scraper/Filter.pm
Is Core No
Search CPAN for this module Web::Scraper::Filter
Documentation Web::Scraper::Filter
Module Details Web::Scraper::Filter


NAME

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


SYNOPSIS

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


DESCRIPTION

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


AUTHOR

Tatsuhiko Miyagawa

Perl Diver brought to you by ScriptSolutions.com © 1997- 2026