| 1 | package WWW::Crawl4AI::Strategy; | ||||||||||||||||||||||
| 2 | # ABSTRACT: role for a single crawl strategy in the WWW::Crawl4AI fallback chain | ||||||||||||||||||||||
| 3 | 6 | ▶ | use Moo::Role; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 6 | ▶ | use WWW::Crawl4AI::Request (); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | 6 | our $VERSION = '0.001'; | |||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | 6 | requires 'name'; | |||||||||||||||||||||
| 10 | 6 | requires 'cost_class'; | |||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | # Whether this strategy belongs in the chain for the given crawler. | ||||||||||||||||||||||
| 13 | # Plain/Browser/Stealth are always applicable; CloakBrowser/Proxy/Callback | ||||||||||||||||||||||
| 14 | # override this to gate on configuration. | ||||||||||||||||||||||
| 15 | 26 | ▶ | sub applicable { 1 } | ||||||||||||||||||||
|
Subroutine
applicable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | # Default execution: build a Request and run it through the client, returning a | ||||||||||||||||||||||
| 21 | # single normalized page. Strategies that don't fetch via Crawl4AI (Callback) | ||||||||||||||||||||||
| 22 | # override this instead of providing build_request. | ||||||||||||||||||||||
| 23 | 39 | ▶ | sub crawl { | ||||||||||||||||||||
|
Subroutine
crawl: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 24 | 39 | my ( $self, $crawler, $url, %opts ) = @_; | |||||||||||||||||||||
| 25 | 39 | my $req = $self->build_request( $crawler, $url, %opts ); | |||||||||||||||||||||
| 26 | 39 | my $pages = $crawler->client->crawl( $req, $self->name ); | |||||||||||||||||||||
| 27 | 37 | return $pages->[0]; | |||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | |||||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | # Helper for build_request implementations. | ||||||||||||||||||||||
| 33 | 39 | ▶ | sub _request { | ||||||||||||||||||||
|
Subroutine
_request: called CC=3 SCAR=11.1
| |||||||||||||||||||||||
| 34 | 39 | my ( $self, $url, %p ) = @_; | |||||||||||||||||||||
| 35 | return WWW::Crawl4AI::Request->new( | ||||||||||||||||||||||
| 36 | urls => $url, | ||||||||||||||||||||||
| 37 | browser_params => $p{browser} || {}, | ||||||||||||||||||||||
| 38 | crawler_params => $p{crawler} || {}, | ||||||||||||||||||||||
| 39 | 39 | ▶ | ); | ||||||||||||||||||||
|
Condition75%3/4
$p{'browser'} || {}
$p{'crawler'} || {}
MC/DC0%0/1
$p{'browser'} || {}
$p{'browser'}
MC/DC100%1/1
$p{'crawler'} || {}
$p{'crawler'}
Truth table50%1/2
A
A= $p{'browser'}
Truth table100%2/2
A
A= $p{'crawler'}
| |||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | 6 | 1; | |||||||||||||||||||||
| 44 | |||||||||||||||||||||||
| 45 | __END__ | ||||||||||||||||||||||