| 1 | |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use LWP::Protocol::https; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use HTTP::Cookies; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use HTML::LinkExtor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use URI::URL; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use English; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =pod | ||||||||||||||||||||||||||||
| 14 | GnaData::Load::Agent is a subclass of the LWP::UserAgent which allows | ||||||||||||||||||||||||||||
| 15 | redirects for POST requests | ||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | package GnaData::Load::Agent; | ||||||||||||||||||||||||||||
| 19 | 1 | @GnaData::Load::Agent::ISA = qw(LWP::UserAgent); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub redirect_ok { | ||||||||||||||||||||||||||
|
Subroutine
redirect_ok: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 23 | 0 | return 1; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | package GnaData::Load; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 1 | my $proto = shift; | |||||||||||||||||||||||||||
| 31 | 1 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 32 | 1 | my $self = {}; | |||||||||||||||||||||||||||
| 33 | 1 | bless ($self, $class); | |||||||||||||||||||||||||||
| 34 | 1 | $self->{'agent'} = GnaData::Load::Agent->new(); | |||||||||||||||||||||||||||
| 35 | 1 | $self->{'sleep'} = 1; | |||||||||||||||||||||||||||
| 36 | 1 | $self->{'cookie_jar'} = HTTP::Cookies->new(); | |||||||||||||||||||||||||||
| 37 | 1 | $self->{'agent'}->cookie_jar($self->{'cookie_jar'}); | |||||||||||||||||||||||||||
| 38 | 1 | $self->{'found'} = {}; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | $self->{'output_handle'} = IO::Handle->new(); | |||||||||||||||||||||||||||
| 41 | 1 | $self->{'output_handle'}->fdopen(fileno(STDOUT), "w"); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | return $self; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=3 SCAR=12.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 1 | my $get = shift; | |||||||||||||||||||||||||||
| 49 | 1 | my $post = shift; | |||||||||||||||||||||||||||
| 50 | 1 | my ($returnval) = ""; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | ▶ | if (defined($post)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 53 | 0 | my $req = HTTP::Request::Common::POST($get, $post); | |||||||||||||||||||||||||||
| 54 | 0 | my $res = $self->{'agent'}->request($req); | |||||||||||||||||||||||||||
| 55 | 0 | $self->{'reply'} = $res->as_string; | |||||||||||||||||||||||||||
| 56 | 0 | $self->{'base'} = $res->base; | |||||||||||||||||||||||||||
| 57 | 0 | sleep($self->{'sleep'}); | |||||||||||||||||||||||||||
| 58 | } elsif (defined($get)) { | ||||||||||||||||||||||||||||
| 59 | 1 | my $req = new HTTP::Request 'GET', $get; | |||||||||||||||||||||||||||
| 60 | 1 | my $res = $self->{'agent'}->request($req); | |||||||||||||||||||||||||||
| 61 | 1 | $self->{'reply'} = $res->as_string; | |||||||||||||||||||||||||||
| 62 | 1 | $self->{'base'} = $res->base; | |||||||||||||||||||||||||||
| 63 | 1 | sleep($self->{'sleep'}); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 1 | return $self->{'reply'}; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub reply { | ||||||||||||||||||||||||||
|
Subroutine
reply: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 70 | 0 | return $self->{'reply'}; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | my (@currentlinks) = (); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub callback { | ||||||||||||||||||||||||||
|
Subroutine
callback: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 76 | 0 | my($tag, %attr) = @_; | |||||||||||||||||||||||||||
| 77 | 0 | local($_); | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | return if ($tag ne 'a' && $tag ne 'frame'); # we only look closer at <img ...> | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tag ne "a" and $tag ne "frame"
MC/DC0%0/2
$tag ne "a" and $tag ne "frame"
$tag ne "a"
$tag ne "frame"
Truth table0%0/3
A and B
A= $tag ne "a"B= $tag ne "frame"
| |||||||||||||||||||||||||||||
| 79 | 0 | foreach (values %attr) { | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | if (!/^mailto:/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | s/\#.*?$//; | |||||||||||||||||||||||||||
| 82 | 0 | push (@currentlinks, $_); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | my($p) = HTML::LinkExtor->new(\&callback); | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | sub extract_hrefs { | ||||||||||||||||||||||||||
|
Subroutine
extract_hrefs: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 91 | 1 | my $regexp = shift; | |||||||||||||||||||||||||||
| 92 | 1 | @currentlinks = (); | |||||||||||||||||||||||||||
| 93 | 1 | $p->parse($self->{'reply'}); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | @currentlinks = map { $_ = URI::URL::url($_, $self->{'base'})->abs; } | |||||||||||||||||||||||||||
| 96 | @currentlinks; | ||||||||||||||||||||||||||||
| 97 | 1 | ▶ | if (defined($regexp) && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $regexp and $regexp ne ""
MC/DC0%0/2
defined $regexp and $regexp ne ""
defined $regexp
$regexp ne ""
Truth table33%1/3
A and B
A= defined $regexpB= $regexp ne ""
| |||||||||||||||||||||||||||||
| 98 | $regexp ne "") { | ||||||||||||||||||||||||||||
| 99 | 0 | @currentlinks = grep (/$regexp/, @currentlinks); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 1 | return (@currentlinks); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub extract_data { | ||||||||||||||||||||||||||
|
Subroutine
extract_data: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 105 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 106 | 0 | my $regexp = shift; | |||||||||||||||||||||||||||
| 107 | 0 | my $replyin = shift; | |||||||||||||||||||||||||||
| 108 | 0 | my (@returnval); | |||||||||||||||||||||||||||
| 109 | my ($reply) = defined($replyin) ? $replyin : | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $self->{'reply'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | while ($reply =~ m/$regexp/is) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | push (@returnval, $1); | |||||||||||||||||||||||||||
| 113 | 0 | $reply = $::POSTMATCH; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 0 | return @returnval; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub dump_links { | ||||||||||||||||||||||||||
|
Subroutine
dump_links: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 0 | my ($self, @list) = @_; | |||||||||||||||||||||||||||
| 120 | 0 | my ($href); | |||||||||||||||||||||||||||
| 121 | 0 | foreach $href (@list) { | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($self->{'found'}->{$href} != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | $self->{'found'}->{$href} = 1; | |||||||||||||||||||||||||||
| 124 | 0 | $self->print (">> $href\n"); | |||||||||||||||||||||||||||
| 125 | 0 | $self->print ( $self->load($href)); | |||||||||||||||||||||||||||
| 126 | 0 | $self->flush(); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub print { | ||||||||||||||||||||||||||
|
Subroutine
print: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | 0 | my ($self, $s) = @_; | |||||||||||||||||||||||||||
| 133 | 0 | $self->{'output_handle'}->print($s); | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub flush { | ||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 137 | 0 | my ($self, $s) = @_; | |||||||||||||||||||||||||||
| 138 | 0 | $self->{'output_handle'}->flush(); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | sub output_handle { | ||||||||||||||||||||||||||
|
Subroutine
output_handle: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 144 | 0 | my ($self, $outh) = @_; | |||||||||||||||||||||||||||
| 145 | 0 | $self->{'output_handle'} = $outh; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub extract_cycle { | ||||||||||||||||||||||||||
|
Subroutine
extract_cycle: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 149 | 0 | my ($self, $href, $elements, $cycle_regexp, | |||||||||||||||||||||||||||
| 150 | $extract_regexp, $row) = @_; | ||||||||||||||||||||||||||||
| 151 | 0 | my (@courselist) = (); | |||||||||||||||||||||||||||
| 152 | 0 | my ($pageindex) = 1; | |||||||||||||||||||||||||||
| 153 | 0 | while (1) { | |||||||||||||||||||||||||||
| 154 | 0 | my (%hash) = %$elements; | |||||||||||||||||||||||||||
| 155 | 0 | $hash{$row} = $pageindex; | |||||||||||||||||||||||||||
| 156 | 0 | my ($reply) = | |||||||||||||||||||||||||||
| 157 | $self->load($href, \%hash); | ||||||||||||||||||||||||||||
| 158 | 0 | push (@courselist, | |||||||||||||||||||||||||||
| 159 | $self->extract_hrefs($extract_regexp)); | ||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ($reply =~ /$cycle_regexp/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | print "# Found next", "\n"; | |||||||||||||||||||||||||||
| 162 | 0 | $pageindex += $1; | |||||||||||||||||||||||||||
| 163 | } else { | ||||||||||||||||||||||||||||
| 164 | 0 | last; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | 0 | return @courselist; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =pod | ||||||||||||||||||||||||||||
| 172 | Backward conpatibility with GnaCatalog::Load | ||||||||||||||||||||||||||||
| 173 | =cut | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub extract { | ||||||||||||||||||||||||||
|
Subroutine
extract: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 176 | 0 | print STDERR "Warning: extract is depreciated, use extract_hrefs"; | |||||||||||||||||||||||||||
| 177 | 0 | my ($self, $get, $post); | |||||||||||||||||||||||||||
| 178 | 0 | $self->load($get, $post); | |||||||||||||||||||||||||||
| 179 | 0 | return $self->extract_hrefs(); | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =pod | ||||||||||||||||||||||||||||
| 183 | Backward conpatibility with GnaCatalog::Load | ||||||||||||||||||||||||||||
| 184 | =cut | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | package GnaCatalog::Load; | ||||||||||||||||||||||||||||
| 187 | 1 | @GnaCatalog::Load::ISA = qw(GnaData::Load); | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 190 | 0 | print STDERR "Warning: GnaCatalog::Load is depreciated use GnaCatalog::Load"; | |||||||||||||||||||||||||||
| 191 | 0 | return GnaCatalog::Load::new(@_); | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 1 | 1; | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||