| 1 | package WWW::Crawl4AI::StrategyChain; | ||||||||||
| 2 | # ABSTRACT: ordered list of strategy objects, pluggable at construction time | ||||||||||
| 3 | 5 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use WWW::Crawl4AI::Strategy::Plain (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 5 | ▶ | use WWW::Crawl4AI::Strategy::Browser (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use WWW::Crawl4AI::Strategy::Stealth (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use WWW::Crawl4AI::Strategy::CloakBrowser (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 5 | ▶ | use WWW::Crawl4AI::Strategy::Proxy (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 5 | ▶ | use WWW::Crawl4AI::Strategy::Callback (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 5 | our $VERSION = '0.001'; | |||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | # Default order, cheapest first. Override in subclass or at construction. | ||||||||||
| 15 | 5 | my @CHAIN_CLASSES = qw( | |||||||||
| 16 | WWW::Crawl4AI::Strategy::Plain | ||||||||||
| 17 | WWW::Crawl4AI::Strategy::Browser | ||||||||||
| 18 | WWW::Crawl4AI::Strategy::Stealth | ||||||||||
| 19 | WWW::Crawl4AI::Strategy::CloakBrowser | ||||||||||
| 20 | WWW::Crawl4AI::Strategy::Proxy | ||||||||||
| 21 | WWW::Crawl4AI::Strategy::Callback | ||||||||||
| 22 | ); | ||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | 18 | ▶ | sub chain_classes { @CHAIN_CLASSES } | ||||||||
|
Subroutine
chain_classes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 26 | |||||||||||
| 27 | 5 | has strategies => ( | |||||||||
| 28 | is => 'ro', | ||||||||||
| 29 | builder => 1, | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | 18 | ▶ | sub _build_strategies { | ||||||||
|
Subroutine
_build_strategies: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 18 | my ( $self ) = @_; | |||||||||
| 35 | 18 | return [ map { $_->new } $self->chain_classes ]; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 0 | ▶ | sub add_strategy { | ||||||||
|
Subroutine
add_strategy: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 39 | 0 | my ( $self, $strategy ) = @_; | |||||||||
| 40 | 0 | push @{ $self->{strategies} }, $strategy; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | sub remove_strategy { | ||||||||
|
Subroutine
remove_strategy: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 44 | 0 | my ( $self, $name ) = @_; | |||||||||
| 45 | 0 | @{ $self->{strategies} } = grep { $_->name ne $name } @{ $self->{strategies} }; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub replace_strategy { | ||||||||
|
Subroutine
replace_strategy: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 49 | 0 | my ( $self, $name, $strategy ) = @_; | |||||||||
| 50 | 0 | my $s = $self->{strategies}; | |||||||||
| 51 | 0 | for my $i ( 0 .. $#$s ) { | |||||||||
| 52 | 0 | ▶ | $s->[$i] = $strategy if $s->[$i]->name eq $name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | } | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | # Filter strategies by applicable($crawler) for this crawler instance. | ||||||||||
| 57 | 8 | ▶ | sub applicable { | ||||||||
|
Subroutine
applicable: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 58 | 8 | my ( $self, $crawler ) = @_; | |||||||||
| 59 | 8 | return [ grep { $_->applicable($crawler) } @{ $self->strategies } ]; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 5 | 1; | |||||||||
| 63 | |||||||||||
| 64 | __END__ | ||||||||||