Crawl4AI/StrategyChain.pm

filter: Statementstmt 73.3% 33 / 45 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 76.9% 10 / 13 Podpod 20.0% 1 / 5 totaltotal 67.6% 44 / 65 CC 3 SCAR 12.0
CC
3
Cov
70%
replace_strategy
12.0
add_strategy
2.0
remove_strategy
2.0
CRAP 3.3
« Crawl4AI/Markdown.pm ↑ Summary Crawl4AI/Strategy/Callback.pm »
1 package WWW::Crawl4AI::StrategyChain;
2 # ABSTRACT: ordered list of strategy objects, pluggable at construction time
3 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use WWW::Crawl4AI::Strategy::Plain ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use WWW::Crawl4AI::Strategy::Browser ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use WWW::Crawl4AI::Strategy::Stealth ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use WWW::Crawl4AI::Strategy::CloakBrowser ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use WWW::Crawl4AI::Strategy::Proxy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use WWW::Crawl4AI::Strategy::Callback ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.001';
12  
13  
14 # Default order, cheapest first. Override in subclass or at construction.
15 2 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 16 ▶sub chain_classes { @CHAIN_CLASSES }
Subroutine chain_classes: called CC=1 SCAR=0.0
Pod documented
26  
27 2 has strategies => (
28 is => 'ro',
29 builder => 1,
30 );
31  
32  
33 sub _build_strategies {
34 16 ▶ my ( $self ) = @_;
Subroutine _build_strategies: called CC=1 SCAR=0.0
35 16 return [ map { $_->new } $self->chain_classes ];
36 }
37  
38 sub add_strategy {
39 0 ▶ my ( $self, $strategy ) = @_;
Subroutine add_strategy: not called CC=1 SCAR=6.9
Pod undocumented
40 0 push @{ $self->{strategies} }, $strategy;
41 }
42  
43 sub remove_strategy {
44 0 ▶ my ( $self, $name ) = @_;
Subroutine remove_strategy: not called CC=1 SCAR=6.9
Pod undocumented
45 0 @{ $self->{strategies} } = grep { $_->name ne $name } @{ $self->{strategies} };
46 }
47  
48 sub replace_strategy {
49 0 ▶ my ( $self, $name, $strategy ) = @_;
Subroutine replace_strategy: not called CC=3 SCAR=24.8
Pod undocumented
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
BranchTrueFalseTotal
if $s->[$i]->name eq $name 0 0 0
53 }
54 }
55  
56 # Filter strategies by applicable($crawler) for this crawler instance.
57 sub applicable {
58 6 ▶ my ( $self, $crawler ) = @_;
Subroutine applicable: called CC=1 SCAR=0.0
Pod undocumented
59 6 return [ grep { $_->applicable($crawler) } @{ $self->strategies } ];
60 }
61  
62 2 1;
63  
64 __END__
« Crawl4AI/Markdown.pm ↑ Summary Crawl4AI/Strategy/Callback.pm »