GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  WEB::SCRAPER::FILTER (3)

.ds Aq ’

NAME

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

CONTENTS

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
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 WEB::SCRAPER::FILTER (3) 2014-10-20

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.