blib/lib/WWW/Search/Jobserve.pm

filter: Statementstmt 9.1% 10 / 109 Branchbran 0.0% 0 / 60 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 40.0% 2 / 5 Podpod 33.3% 1 / 3 totaltotal 6.6% 13 / 197 CC 41 SCAR 61.9
CC
41
Cov
5%
parse_tree
702.0
native_setup_search
240.0
preprocess_results_page
6.0
CRAP 485.9
↑ Summary
1 # Jobserve.pm
2 # Written by Andy Pritchard.
3 # $Id: Jobserve.pm,v 1.02 2003-09-25 16:13:30 ninja $
4  
5 package WWW::Search::Jobserve;
6  
7 1 @ISA = qw( WWW::Search );
8  
9 1 ▶use WWW::Search qw( generic_option strip_tags );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use WWW::Search::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 $VERSION = '1.02';
13 1 $MAINTAINER = 'Andy Pritchard <pilchkinstein@hotmail.com>';
14  
15 # private
16 sub native_setup_search
17 0 ▶ {
Subroutine native_setup_search: not called CC=15 SCAR=54.8
Pod undocumented
18 0 my ($self, $native_query, $rhOptsArg) = @_;
19
20 # Set some private variables:
21 0 ▶ $self->{_debug} ||= $rhOptsArg->{'search_debug'};
Condition0%0/3
$self->{"_debug"} ||= $rhOptsArg->{"search_debug"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_debug"} ||= $rhOptsArg->{"search_debug"}
$self->{"_debug"} $rhOptsArg->{"search_debug"}
Truth table0%0/3
A ||= B
A= $self->{"_debug"}B= $rhOptsArg->{"search_debug"}
ABresult
1X1
011
000
22 0 ▶ $self->{_debug} = 2 if ($rhOptsArg->{'search_parse_debug'});
Branch: 1 branch
BranchTrueFalseTotal
if $rhOptsArg->{"search_parse_debug"} 0 0 0
23 0 ▶ $self->{_debug} ||= 0;
Condition0%0/2
$self->{"_debug"} ||= 0
l!l
00
MC/DC0%0/1
$self->{"_debug"} ||= 0
$self->{"_debug"}
Truth table0%0/2
A
A= $self->{"_debug"}
Aresult
11
00
24
25  
26 0 my $DEFAULT_HITS_PER_PAGE = 50;
27 0 $self->{'_hits_per_page'} = $DEFAULT_HITS_PER_PAGE;
28
29 0 my $sjob_category = $rhOptsArg->{'job_category'};
30 0 my $sjobserve_site = $rhOptsArg->{'jobserve_site'};
31 0 my $sjob_type = $rhOptsArg->{'job_type'};
32 0 my $sjob_lookahead = $rhOptsArg->{'job_lookahead'};
33 0 my $sjob_order = $rhOptsArg->{'job_order'};
34 0 ▶ $sjobserve_site ||= 'uk'; # Default to English site
Condition0%0/2
$sjobserve_site ||= "uk"
l!l
00
MC/DC0%0/1
$sjobserve_site ||= "uk"
$sjobserve_site
Truth table0%0/2
A
A= $sjobserve_site
Aresult
11
00
35 0 ▶ $sjob_type ||= '*'; # Default to all
Condition0%0/2
$sjob_type ||= "*"
l!l
00
MC/DC0%0/1
$sjob_type ||= "*"
$sjob_type
Truth table0%0/2
A
A= $sjob_type
Aresult
11
00
36 0 ▶ $sjob_lookahead ||= '5'; # Default to 5 Days
Condition0%0/2
$sjob_lookahead ||= 5
l!l
00
MC/DC0%0/1
$sjob_lookahead ||= 5
$sjob_lookahead
Truth table0%0/2
A
A= $sjob_lookahead
Aresult
11
00
37 0 ▶ $sjob_order ||= 'Rank';# Default to Rank (Best Match)
Condition0%0/2
$sjob_order ||= "Rank"
l!l
00
MC/DC0%0/1
$sjob_order ||= "Rank"
$sjob_order
Truth table0%0/2
A
A= $sjob_order
Aresult
11
00
38
39 0 my %Country_Params = ( uk => 'jobserve.com/jobserve/',
40 au => 'job-serve.com.au/jobserve/',
41 ) ;
42  
43 0 $self->user_agent('non-robot');
44  
45 0 $self->{'_next_to_retrieve'} = 0;
46 0 $self->{'_num_hits'} = 0;
47 0 $self->{'_base_url'} = "http://www.$sjob_category.$Country_Params{$sjobserve_site}";
48  
49 0 ▶ if (!defined($self->{_options}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_options"}) 0 0 0
50 {
51 $self->{_options} = {
52 0 'search_url' => $self->{'_base_url'} . 'searchresults.asp',
53 'jobType' => $sjob_type, # Job Type (*|C|P) == (Any|Contract|Permanent)
54 'd' => $sjob_lookahead, # No of days to look ahead
55 'order' => $sjob_order,# Sort order (Rank|DateTime) == (Best Match|Latest Job)
56 'q' => $native_query, # The escaped query
57 };
58 } # if
59 0 ▶ if (defined($rhOptsArg))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rhOptsArg) 0 0 0
60 {
61 # Copy in new options.
62 0 foreach my $key (keys %$rhOptsArg)
63 {
64 #print STDERR " + inspecting option $key...";
65 0 ▶ if (WWW::Search::generic_option($key))
Branch: 1 branch
BranchTrueFalseTotal
if (WWW::Search::generic_option($key)) { } 0 0 0
66 {
67 0 print STDERR "promote & delete\n";
68 0 ▶ $self->{$key} = $rhOptsArg->{$key} if defined($rhOptsArg->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if defined $rhOptsArg->{$key} 0 0 0
69 0 delete $rhOptsArg->{$key};
70 }
71 else
72 {
73 #print STDERR "copy\n";
74 0 ▶ $self->{_options}->{$key} = $rhOptsArg->{$key} if defined($rhOptsArg->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if defined $rhOptsArg->{$key} 0 0 0
75 }
76 } # foreach
77 } # if
78  
79 0 ▶ die " - Must specify a job category to search...\n" unless (defined($self->{_options}->{'job_category'}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_options"}{"job_category"} 0 0 0
80 # Finally, figure out the url.
81 0 $self->{_next_url} = $self->{_options}->{'search_url'} .'?'. $self->hash_to_cgi_string($self->{_options});
82 } # native_setup_search
83  
84 sub preprocess_results_page
85 0 ▶ {
Subroutine preprocess_results_page: not called CC=2 SCAR=17.9
Pod documented
86 0 my $self = shift;
87 0 my $sPage = shift;
88 0 ▶ print STDERR " + RawHTML ===>$sPage<=== RawHTML\n" if 2 < $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 2 < $self->{"_debug"} 0 0 0
89 0 return $sPage;
90 } # preprocess_results_page
91  
92 # private
93 sub parse_tree
94 0 ▶ {
Subroutine parse_tree: not called CC=26 SCAR=65.5
Pod undocumented
95 0 my $self = shift;
96 0 my $tree = shift;
97  
98 # A pattern to match HTML whitespace:
99 0 my $W = q{[\ \t\r\n\240]};
100 0 my $hits_found = 0;
101 0 ▶ if (2 < $self->{_debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if (2 < $self->{"_debug"}) 0 0 0
102 0 print STDERR "=========================== HTML::Tree Dump START ============================\n";
103 0 print STDERR $tree->as_HTML();
104 0 print STDERR "============================ HTML::Tree Dump END =============================\n";
105 }
106 # The hit count is in a FONT tag:
107 0 my @aoFONT = $tree->look_down('_tag', 'font');
108 0 my @aoTABLE = $tree->look_down('_tag', 'table');
109
110 FONT:
111 0 foreach my $oFONT (@aoFONT)
112 {
113 0 ▶ print STDERR " + try FONT ===", $oFONT->as_text, "===\n" if 1 < $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 1 < $self->{"_debug"} 0 0 0
114 0 ▶ if ($oFONT->as_text =~ m!of (\d+) Matching Jobs!)
Branch: 1 branch
BranchTrueFalseTotal
if ($oFONT->as_text =~ /of (\d+) Matching Jobs/) 0 0 0
115 {
116 0 $self->approximate_result_count($1);
117 0 last FONT;
118 } # if
119 } # foreach
120 TABLE:
121 0 foreach my $oTABLE (@aoTABLE) # Go <table> -> <td> -> <font1> -> <font2> -> <font3> -> <font4>
122 {
123 0 ▶ print STDERR " + try TABLE ===", $oTABLE->as_HTML, "===\n" if 1 < $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 1 < $self->{"_debug"} 0 0 0
124 0 my @aoFONT = $oTABLE->look_down('_tag', 'font');
125 0 my $oFONT = shift(@aoFONT);
126 0 ▶ next TABLE unless ref $oFONT;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $oFONT 0 0 0
127 0 ▶ print STDERR " + try TABLE->FONT ===", $oFONT->as_text, "===\n" if 1 < $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 1 < $self->{"_debug"} 0 0 0
128 # First A tag contains the url & title:
129 0 my @aoA = $oFONT->look_down('_tag', 'a');
130 0 my $oA = shift(@aoA);
131 0 ▶ next TABLE unless ref $oA;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $oA 0 0 0
132 0 ▶ next TABLE if (($oA->as_HTML) =~ m!class="ToolBar"!ig);
Branch: 1 branch
BranchTrueFalseTotal
if $oA->as_HTML =~ /class="ToolBar"/gi 0 0 0
133 0 ▶ print STDERR " + try TABLE->FONT->A ===", $oA->as_HTML, "===\n" if 1 < $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 1 < $self->{"_debug"} 0 0 0
134 # Occasionally they have these atsco links in there, this skips over in this case.
135 0 ▶ if (($oA->as_HTML) !~ m!\?jobid\=!ig) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($oA->as_HTML =~ /\?jobid\=/gi) 0 0 0
136 0 $oA = shift(@aoA);
137 0 ▶ print STDERR " + Re-try TABLE->FONT->A ===", $oA->as_HTML, "===\n" if 1 < $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 1 < $self->{"_debug"} 0 0 0
138 }
139 # Jobserve only gives us a path relative to the _base_url
140 0 my $sURL = $self->{'_base_url'} . $oA->attr('href');
141 0 ▶ print STDERR " + GOT URL:$sURL:\n" if 1 < $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 1 < $self->{"_debug"} 0 0 0
142 0 my $sTitle = $oA->as_text;
143 0 ▶ print STDERR " + GOT Title:$sTitle:\n" if 1 < $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 1 < $self->{"_debug"} 0 0 0
144 # Now go down another font
145 0 my $oFONT2 = shift(@aoFONT);
146 # And another
147 0 my $oFONT3 = shift(@aoFONT);
148 0 ▶ print STDERR " + try TABLE->FONT3 ===", $oFONT3->as_text, "===\n" if 1 < $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 1 < $self->{"_debug"} 0 0 0
149 0 my $sDesc = $oFONT3->as_text;
150 # And yet another
151 0 my $oFONT4 = shift(@aoFONT);
152 0 ▶ $oFONT4 = shift(@aoFONT) if (($oFONT4->as_text) =~ m!more\.\.\.!);
Branch: 1 branch
BranchTrueFalseTotal
if $oFONT4->as_text =~ /more\.\.\./ 0 0 0
153 0 ▶ print STDERR " + try TABLE->FONT4 ===", $oFONT4->as_text, "===\n" if 1 < $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 1 < $self->{"_debug"} 0 0 0
154 0 $sDesc .= $oFONT4->as_text;
155  
156 0 my $hit = new WWW::Search::Result;
157 0 $hit->add_url($sURL);
158 0 $hit->title($sTitle);
159 0 $hit->description($sDesc);
160 #$hit->change_date($sDate);
161 0 push(@{$self->{cache}}, $hit);
162 0 $self->{'_num_hits'}++;
163 0 $hits_found++;
164 # Delete this HTML element so that future searches go faster!
165 0 $oTABLE->detach;
166 0 $oTABLE->delete;
167 } # foreach TABLE
168  
169 # Look for a Next Page link:
170 0 my @aoA = $tree->look_down('_tag', 'a');
171 TRY_NEXT:
172 0 foreach my $oA (reverse @aoA)
173 {
174 0 ▶ next TRY_NEXT unless ref $oA;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $oA 0 0 0
175 0 ▶ print STDERR " + try NEXT A ===", $oA->as_HTML, "===\n" if 1 < $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 1 < $self->{"_debug"} 0 0 0
176 0 my $href = $oA->attr('href');
177 0 ▶ next TRY_NEXT unless $href;
Branch: 1 branch
BranchTrueFalseTotal
unless $href 0 0 0
178 0 ▶ last TRY_NEXT if $href =~ m!JobDetail!;
Branch: 1 branch
BranchTrueFalseTotal
if $href =~ /JobDetail/ 0 0 0
179 0 ▶ if ($oA->as_text =~ m!Next Page!i)
Branch: 1 branch
BranchTrueFalseTotal
if ($oA->as_text =~ /Next Page/i) 0 0 0
180 {
181 0 $self->{_next_url} = $self->absurl(undef, $href);
182 0 ▶ print STDERR " + got NEXT A ===", $self->{_next_url}, "===\n" if 1 < $self->{_debug};
Branch: 1 branch
BranchTrueFalseTotal
if 1 < $self->{"_debug"} 0 0 0
183 0 last TRY_NEXT;
184 } # if
185 } # foreach
186  
187 # All done with this page.
188 0 $tree->delete;
189 0 return $hits_found;
190 } # parse_tree
191  
192 1 1;
193  
194 __END__
↑ Summary