use Scraper::Library::Yahoo;
Scraper::Library::Yahoo->scrape();
####
package Scraper;
sub new {
my( $pkg, $strategy_class ) = @_;
bless {
strategy_class => $strategy_class,
}, $pkg
}
sub scrape {
my $self = shift;
my $config_data = $self->{'strategy_class'}->config_data();
# ... proceed to scrape using this config data
}
package Scraper::Yahoo;
# as a strategy of Scraper, this class only needs to implement those methods
# a Scraper will call.
sub config_data {
return(
starting_page => 'www.yahoo.com/foo/',
some_regex => qr/foo(.*?)bar/,
html_tree_spec => [ '_tag', 'div', 'id', 'headlines' ],
);
}
. . .
package main;
# pass the strategy class name to the constructor:
my $yahoo_scraper = new Scraper 'Scraper::Yahoo';
####
package Scraper;
sub scrape {
my $self = shift;
my $starting_page = $self->{'strategy_class'}->starting_page();
my $some_regex = $self->{'strategy_class'}->some_regex();
my $html_tree_spec = $self->{'strategy_class'}->html_tree_spec();
# ... proceed to scrape using this config data
}
package Scraper::Yahoo;
sub starting_page { 'www.yahoo.com/foo/' }
sub some_regex { qr/foo(.*?)bar/ }
sub html_tree_spec { [ '_tag', 'div', 'id', 'headlines' ] }