| 1 | # ABSTRACT: Scrappy HTTP Request Flow-Control System | ||||||||||||
| 2 | # Dist::Zilla: +PodWeaver | ||||||||||||
| 3 | |||||||||||||
| 4 | package Scrappy::Queue; | ||||||||||||
| 5 | |||||||||||||
| 6 | 10 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 10 | $Scrappy::Queue::VERSION = '0.94112090'; | |||||||||||
| 8 | } | ||||||||||||
| 9 | |||||||||||||
| 10 | # load OO System | ||||||||||||
| 11 | 10 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | # load other libraries | ||||||||||||
| 14 | 10 | ▶ | use Array::Unique; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 10 | ▶ | use URI; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | |||||||||||||
| 17 | # queue and cursor variables for navigation | ||||||||||||
| 18 | 10 | our @_queue = (); | |||||||||||
| 19 | 10 | tie @_queue, 'Array::Unique'; | |||||||||||
| 20 | 10 | our $_cursor = -1; | |||||||||||
| 21 | |||||||||||||
| 22 | |||||||||||||
| 23 | 0 | ▶ | sub list { | ||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 24 | 0 | return @_queue; | |||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | |||||||||||||
| 28 | 0 | ▶ | sub add { | ||||||||||
|
Subroutine
add: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 29 | 0 | my $self = shift; | |||||||||||
| 30 | 0 | my @urls = @_; | |||||||||||
| 31 | |||||||||||||
| 32 | # validate and formulate proper URLs | ||||||||||||
| 33 | 0 | ▶ | for (my $i = 0; $i < @urls; $i++) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | 0 | my $u = URI->new($urls[$i]); | |||||||||||
| 35 | |||||||||||||
| 36 | 0 | ▶ | if ('URI::' =~ ref $u) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | 0 | $urls[$i] = $u->as_string; | |||||||||||
| 38 | } | ||||||||||||
| 39 | else { | ||||||||||||
| 40 | 0 | ▶ | unless ($urls[$i] =~ /\w{2,}\.\w{2,}/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 0 | delete $urls[$i]; | |||||||||||
| 42 | } | ||||||||||||
| 43 | } | ||||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | 0 | push @_queue, @urls; | |||||||||||
| 47 | 0 | return $self; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | 0 | ▶ | sub clear { | ||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 52 | 0 | my $self = shift; | |||||||||||
| 53 | |||||||||||||
| 54 | 0 | @_queue = (); | |||||||||||
| 55 | 0 | $_cursor = -1; | |||||||||||
| 56 | |||||||||||||
| 57 | 0 | return $self; | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | 0 | ▶ | sub reset { | ||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 62 | 0 | my $self = shift; | |||||||||||
| 63 | |||||||||||||
| 64 | 0 | $_cursor = -1; | |||||||||||
| 65 | |||||||||||||
| 66 | 0 | return $self; | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | |||||||||||||
| 70 | 0 | ▶ | sub current { | ||||||||||
|
Subroutine
current: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 71 | 0 | my $self = shift; | |||||||||||
| 72 | |||||||||||||
| 73 | 0 | return $_queue[$_cursor]; | |||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | |||||||||||||
| 77 | 0 | ▶ | sub next { | ||||||||||
|
Subroutine
next: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 78 | 0 | my $self = shift; | |||||||||||
| 79 | |||||||||||||
| 80 | 0 | return $_queue[++$_cursor]; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | |||||||||||||
| 84 | 0 | ▶ | sub previous { | ||||||||||
|
Subroutine
previous: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 85 | 0 | my $self = shift; | |||||||||||
| 86 | |||||||||||||
| 87 | 0 | return $_queue[--$_cursor]; | |||||||||||
| 88 | } | ||||||||||||
| 89 | |||||||||||||
| 90 | |||||||||||||
| 91 | 0 | ▶ | sub first { | ||||||||||
|
Subroutine
first: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 92 | 0 | my $self = shift; | |||||||||||
| 93 | 0 | $_cursor = 0; | |||||||||||
| 94 | |||||||||||||
| 95 | 0 | return $_queue[$_cursor]; | |||||||||||
| 96 | } | ||||||||||||
| 97 | |||||||||||||
| 98 | |||||||||||||
| 99 | 0 | ▶ | sub last { | ||||||||||
|
Subroutine
last: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 100 | 0 | my $self = shift; | |||||||||||
| 101 | 0 | $_cursor = scalar(@_queue) - 1; | |||||||||||
| 102 | |||||||||||||
| 103 | 0 | return $_queue[$_cursor]; | |||||||||||
| 104 | } | ||||||||||||
| 105 | |||||||||||||
| 106 | |||||||||||||
| 107 | 0 | ▶ | sub index { | ||||||||||
|
Subroutine
index: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 108 | 0 | my $self = shift; | |||||||||||
| 109 | 0 | ▶ | $_cursor = shift || 0; | ||||||||||
|
Condition0%0/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 110 | |||||||||||||
| 111 | 0 | return $_queue[$_cursor]; | |||||||||||
| 112 | } | ||||||||||||
| 113 | |||||||||||||
| 114 | |||||||||||||
| 115 | 0 | ▶ | sub cursor { | ||||||||||
|
Subroutine
cursor: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 116 | 0 | return $_cursor; | |||||||||||
| 117 | } | ||||||||||||
| 118 | |||||||||||||
| 119 | 10 | 1; | |||||||||||
| 120 | |||||||||||||
| 121 | __END__ | ||||||||||||