| 1 | package WWW::Crawl4AI::Strategy::Callback; | ||||||||||||||||||||
| 2 | # ABSTRACT: last-resort Crawl4AI strategy delegating to a user coderef | ||||||||||||||||||||
| 3 | 5 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 5 | with 'WWW::Crawl4AI::Strategy'; | |||||||||||||||||||
| 5 | 5 | ▶ | use WWW::Crawl4AI::Markdown qw( resolve_markdown_chain ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 5 | our $VERSION = '0.001'; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 13 | ▶ | sub name { 'external_callback' } | ||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | ▶ | sub cost_class { 'paid' } | ||||||||||||||||||
|
Subroutine
cost_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 8 | ▶ | sub applicable { | ||||||||||||||||||
|
Subroutine
applicable: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 17 | 8 | my ( $self, $crawler ) = @_; | |||||||||||||||||||
| 18 | 8 | ▶ | return $crawler->callback ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # Does not go through Crawl4AI at all — hand the URL to the user's coderef and | ||||||||||||||||||||
| 23 | # normalize whatever page-shaped hashref it returns. We accept markdown either | ||||||||||||||||||||
| 24 | # as a plain string or as Crawl4AI's structured object, so Detect and Result | ||||||||||||||||||||
| 25 | # see the same shape they get from every (Crawl4AI-backed) strategy. | ||||||||||||||||||||
| 26 | 2 | ▶ | sub crawl { | ||||||||||||||||||
|
Subroutine
crawl: called CC=5 SCAR=17.3
Pod
documented
| |||||||||||||||||||||
| 27 | 2 | my ( $self, $crawler, $url, %opts ) = @_; | |||||||||||||||||||
| 28 | 2 | my $page = $crawler->callback->( $url, %opts ); | |||||||||||||||||||
| 29 | 2 | ▶ | return undef unless ref $page eq 'HASH'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 2 | ▶ | $page->{markdown} = resolve_markdown_chain( $page->{markdown} ) if ref $page->{markdown} eq 'HASH'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 2 | ▶ | $page->{url} //= $url; | ||||||||||||||||||
|
Condition33%1/3
$page->{"url"} //= $url
MC/DC0%0/2
$page->{"url"} //= $url
$page->{"url"}
$url
Truth table33%1/3
A //= B
A= $page->{"url"}B= $url
| |||||||||||||||||||||
| 32 | 2 | ▶ | $page->{final_url} //= $page->{url}; | ||||||||||||||||||
|
Condition33%1/3
$page->{"final_url"} //= $page->{"url"}
MC/DC0%0/2
$page->{"final_url"} //= $page->{"url"}
$page->{"final_url"}
$page->{"url"}
Truth table33%1/3
A //= B
A= $page->{"final_url"}B= $page->{"url"}
| |||||||||||||||||||||
| 33 | 2 | return $page; | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 5 | 1; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | __END__ | ||||||||||||||||||||