blib/lib/WWW/Search/RPMPbone.pm

filter: Statementstmt 26.4% 18 / 68 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 2 totaltotal 22.4% 22 / 98 CC 14 SCAR 36.4
CC
14
Cov
20%
_get_next_urlparameters
56.0
native_retrieve_some
56.0
native_setup_search
6.0
CRAP 38.2
↑ Summary
1 package WWW::Search::RPMPbone;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 require Exporter;
7 1 @EXPORT = qw();
8 1 @EXPORT_OK = qw();
9 1 @ISA = qw(WWW::Search Exporter);
10 1 $VERSION = ('$Revision: 1.0 $ ' =~ /(\d+\.\d+)/)[0];
11  
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use WWW::Search(qw (generic_option strip_tags));
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 require WWW::SearchResult;
15  
16 0 ▶sub _get_next_urlparameters {
Subroutine _get_next_urlparameters: not called CC=7 SCAR=40.3
17 0 my ($self) = @_;
18 0 ▶ if (!defined($self->{_options})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'_options'}) { } 0 0 0
19 $self->{_options} =
20 {
21 'stat' => 3,
22 'limit' => 1,
23 'srodzaj' => 4,
24 'dl' => 20,
25 'search' => $self->{'native_query'},
26 'dist[]' => 42,
27 0 'search_url' => $self->{'search_base_url'}
28 };
29 }
30 else {
31 0 $self->{_options}{'limit'}++;
32 }
33 0 my($options_ref) = $self->{_options};
34 0 ▶ if (defined($self->{'native_options_ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"native_options_ref"}) 0 0 0
35 0 my $native_options_ref = $self->{'native_options_ref'};
36 0 foreach (keys %$native_options_ref)
37 0 {$options_ref->{$_} = $native_options_ref->{$_};}
38 }
39 0 my($options) = '';
40 0 foreach (sort keys %$options_ref) {
41 0 ▶ next if (generic_option($_));
Branch: 1 branch
BranchTrueFalseTotal
if generic_option($_) 0 0 0
42 $options .= $_ . '=' . $options_ref->{$_} . '&'
43 0 ▶ if (defined $options_ref->{$_});
Branch: 1 branch
BranchTrueFalseTotal
if defined $options_ref->{$_} 0 0 0
44 }
45 0 return $options;
46 }
47  
48 0 ▶sub native_setup_search {
Subroutine native_setup_search: not called CC=2 SCAR=17.9
Pod undocumented
49 0 my($self, $native_query, $native_options_ref) = @_;
50 0 $self->{'native_query'} = $native_query;
51 0 ▶ $self->{'native_options_ref'} = $native_options_ref if (defined $native_options_ref);
Branch: 1 branch
BranchTrueFalseTotal
if defined $native_options_ref 0 0 0
52 0 $self->user_agent('WWW::Search::RpmPbone');
53 0 $self->{'search_base_url'} = 'http://rpm.pbone.net/index.php3';
54 0 my $options = $self->_get_next_urlparameters();
55 $self->{_base_url} = $self->{_next_url}
56 0 = $self->{_options}{'search_url'} ."?" . $options;
57 }
58  
59 0 ▶sub native_retrieve_some {
Subroutine native_retrieve_some: not called CC=7 SCAR=40.3
Pod undocumented
60 0 my ($self) = @_;
61 0 my($hits_found) = 0;
62 0 ▶ return undef if (!defined($self->{_next_url}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_next_url"} 0 0 0
63 0 my($response) = $self->http_request('GET', $self->{_next_url});
64 0 $self->{response} = $response;
65 0 ▶ if (!$response->is_success) {return undef;}
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
66 0 ▶ if ($response->content =~ /FILE WASN\'T FOUND ON FTP SERVERS/sm) { print "No match\n"; return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if ($response->content =~ /FILE WASN\'T FOUND ON FTP SERVERS/ms) 0 0 0
67 0 $self->{_next_url} = $self->{_options}{'search_url'} ."?" .$self->_get_next_urlparameters();
68 0 ▶ if ($response->content =~ /^Display 1 - (\d+) hits of (\d+)/sm) { $self->{'totalhits'} = $2; print $2;}
Branch: 1 branch
BranchTrueFalseTotal
if ($response->content =~ /^Display 1 - (\d+) hits of (\d+)/ms) 0 0 0
69 0 my @response_content = split("\n",$response->content);
70 0 foreach my $content (@response_content) {
71 0 $content =~ s/ //g;
72 0 ▶ if ($content =~ /<TR><TD>(.*?)<\/TD>.*<a href=\"(.*)\">(.*rpm)<\/a><\/TD><TD><\/TD><TD>(.*)<\/TD><\/TR>/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ m[<TR><TD>(.*?)</TD>.*<a href=\"(.*)\">(.*rpm)</a></TD><TD></TD><TD>(.*)</TD></TR>]) 0 0 0
73 0 $self->_new_hit($1,$2,$3,$4);
74 0 $hits_found++;
75 }
76 }
77 0 return $hits_found;
78 }
79  
80 0 ▶sub _new_hit {
Subroutine _new_hit: not called CC=1 SCAR=6.9
81 0 my ($self,$site,$site_url,$rpm,$distribution) = @_;
82 0 my $hit = new WWW::SearchResult;
83 0 $hit->add_url($site_url);
84 0 $hit->source($rpm);
85 0 $hit->description($distribution);
86 0 push(@{$self->{cache}},$hit);
87 0 return $hit;
88 }
89  
90 =head1 NAME
91  
92 WWW::Search::RPMPbone - class for searching rpm.pbone.net
93  
94 =head1 SYNOPSIS
95  
96 #!/usr/bin/perl
97 use WWW::Search;
98 use strict;
99 my $oSearch = new WWW::Search('RPMPbone');
100  
101 # Create request
102 $oSearch->native_query(WWW::Search::escape_query("ccache*src.rpm"));
103  
104 print "I find ", $oSearch->approximate_result_count()," elem\n";
105 while (my $oResult = $oSearch->next_result())
106 {
107 print "---------------------------------\n",
108 "Url :", $oResult->url,"\n",
109 "Distrib:", $oResult->description,"\n",
110 "Rpm:", $oResult->source,"\n";
111 }
112  
113 =head1 DESCRIPTION
114  
115 This class is an RpmPbone (http://rpm.pbone.net/index.php3) specialization of WWW::Search.
116 It handles making and interpreting searches from rpm.pbone.net, a database search engine on RPM packages..
117  
118 This class exports no public interface; all interaction should be done
119 through WWW::Search objects.
120  
121 =head1 SEE ALSO
122  
123 The WWW::Search man pages
124  
125 =head1 AUTHOR
126  
127 C<WWW::Search::RPMPbone> is written by Alagar,
128 samy@cpan.org
129  
130 =cut
131  
↑ Summary