lib/WWW/Crawler/Mojo/Queue/Memory.pm

filter: Statementstmt 90.2% 37 / 41 Branchbran 100% 4 / 4 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 5 / 5 Subroutinesub 92.8% 13 / 14 Podpod 100% 6 / 6 totaltotal 93.5% 73 / 78 CC 6 SCAR 7.9
CC
6
Cov
92%
_enqueue
5.0
next
2.0
shuffle
2.0
CRAP 2.2
« lib/WWW/Crawler/Mojo/UserAgent.pm ↑ Summary lib/WWW/Crawler/Mojo/Job.pm »
1 package WWW::Crawler::Mojo::Queue::Memory;
2 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Mojo::Base 'WWW::Crawler::Mojo::Queue';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 has 'cap';
9 15 ▶has jobs => sub { [] };
Subroutine __ANON__: called CC=1 SCAR=0.0
10 15 ▶has redundancy_storage => sub { {} };
Subroutine __ANON__: called CC=1 SCAR=0.0
11  
12 sub dequeue {
13 46 ▶ return shift(@{shift->jobs});
Subroutine dequeue: called CC=1 SCAR=0.0
Pod documented
14 }
15  
16 sub enqueue {
17 59 ▶ return shift->_enqueue(@_);
Subroutine enqueue: called CC=1 SCAR=0.0
Pod documented
18 }
19  
20 sub length {
21 25 ▶ return scalar(@{shift->jobs});
Subroutine length: called CC=1 SCAR=0.0
Pod documented
22 }
23  
24 sub next {
25 20 ▶ return shift->jobs->[shift || 0];
Subroutine next: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
shift() || 0
l!l
416
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
26 }
27  
28 sub requeue {
29 1 ▶ shift->_enqueue(@_, 1);
Subroutine requeue: called CC=1 SCAR=0.0
Pod documented
30 }
31  
32 sub shuffle {
33 0 ▶ my $self = shift;
Subroutine shuffle: not called CC=1 SCAR=6.9
Pod documented
34 0 @{$self->jobs} = List::Util::shuffle @{$self->jobs};
35 }
36  
37 sub _enqueue {
38 60 ▶ my ($self, $job, $requeue) = @_;
Subroutine _enqueue: called CC=5 SCAR=16.1
39 60 my $digest = $job->digest;
40 60 my $redund = $self->redundancy_storage;
41 60 ▶ return if !$requeue && $redund->{$digest};
Branch: 1 branch
BranchTrueFalseTotal
if not $requeue and $redund->{$digest} 7 53 60
Condition100%3/3
not $requeue and $redund->{$digest}
!ll&&!rl&&r
1527
MC/DC100%2/2
not $requeue and $redund->{$digest}
not $requeue $redund->{$digest}
Truth table100%3/3
not(A) and B
A= not $requeueB= $redund->{$digest}
ABresult
0X0
100
111
42 53 ▶ return if $self->cap && $self->cap < $self->length;
Branch: 1 branch
BranchTrueFalseTotal
if $self->cap and $self->cap < $self->length 1 52 53
Condition100%3/3
$self->cap and $self->cap < $self->length
!ll&&!rl&&r
5021
MC/DC100%2/2
$self->cap and $self->cap < $self->length
$self->cap $self->cap < $self->length
Truth table100%3/3
A and B
A= $self->capB= $self->cap < $self->length
ABresult
0X0
100
111
43 52 push(@{$self->jobs}, $job);
44 52 $redund->{$digest} = 1;
45 52 return $job;
46 }
47  
48 10 1;
49  
50 =head1 NAME
51  
52 WWW::Crawler::Mojo::Queue::Memory - Crawler queue with memory
53  
54 =head1 SYNOPSIS
55  
56 =head1 DESCRIPTION
57  
58 Crawler queue with memory.
59  
60 =head1 ATTRIBUTES
61  
62 This class inherits all methods from L<WWW::Crawler::Mojo::Queue> and implements
63 following new ones.
64  
65 =head2 cap
66  
67 Capacity of queue, indecating how many jobs can be kept in queue at a time.
68 If you enqueue over capacity, the oldest job will be automatically disposed.
69  
70 =head2 jobs
71  
72 jobs.
73  
74 =head2 redundancy_storage
75  
76 A hash ref in which the class keeps DONE flags for each jobs
77 in order to avoid to perform resembling jobs multiple times.
78  
79 # Mark a job as DONE
80 $queue->redundancy_storage->{$job->digest} = 1;
81
82 # Delete the mark
83 delete($queue->redundancy_storage->{$job->digest});
84  
85 =head1 METHODS
86  
87 This class inherits all methods from L<WWW::Crawler::Mojo::Queue> class and
88 implements following new ones.
89  
90 =head2 dequeue
91  
92 Implementation for L<WWW::Crawler::Mojo::Queue> interface.
93  
94 =head2 enqueue
95  
96 Implementation for L<WWW::Crawler::Mojo::Queue> interface.
97  
98 =head2 length
99  
100 Implementation for L<WWW::Crawler::Mojo::Queue> interface.
101  
102 =head2 next
103  
104 Implementation for L<WWW::Crawler::Mojo::Queue> interface.
105  
106 =head2 requeue
107  
108 Implementation for L<WWW::Crawler::Mojo::Queue> interface.
109  
110 =head2 shuffle
111  
112 Implementation for L<WWW::Crawler::Mojo::Queue> interface.
113  
114 =head1 AUTHOR
115  
116 Keita Sugama, E<lt>sugama@jamadam.comE<gt>
117  
118 =head1 COPYRIGHT AND LICENSE
119  
120 Copyright (C) Keita Sugama.
121  
122 This program is free software; you can redistribute it and/or
123 modify it under the same terms as Perl itself.
124  
125 =cut
« lib/WWW/Crawler/Mojo/UserAgent.pm ↑ Summary lib/WWW/Crawler/Mojo/Job.pm »