Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.17.162.245
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : Filter.pm
package Web::Scraper::Filter;
use strict;
use warnings;

sub new {
    my $class = shift;
    bless {}, $class;
}

1;

__END__

=for stopwords namespace inline callback

=head1 NAME

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

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

=head1 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 C<$_> and returns the count of
replacement. Filter code special cases if the return value of the
callback is number and C<$_> value is updated.

You can, of course, stack filters like:

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

=head1 AUTHOR

Tatsuhiko Miyagawa

=cut
© 2025 GrazzMean