| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::MSA::Hadith; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Hadith.pm,v 1.3 2003/06/21 09:03:22 sherzodr Exp $ |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7253
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
41
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
71
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION $PROXY $HADITH_URLF); |
|
|
1
|
|
|
|
|
13
|
|
|
|
1
|
|
|
|
|
1697
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$VERSION = '1.01'; |
|
10
|
|
|
|
|
|
|
$PROXY = 'http://www.usc.edu/cgi-bin/msasearch'; |
|
11
|
|
|
|
|
|
|
$HADITH_URLF = 'http://www.usc.edu/dept/MSA/fundamentals/hadithsunnah/%s/%03d.sbt.html'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Preloaded methods go here. |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
|
19
|
1
|
|
|
1
|
0
|
140
|
my $class = shift; |
|
20
|
1
|
|
33
|
|
|
13
|
$class = ref($class) || $class; |
|
21
|
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
7
|
my $self = { |
|
23
|
|
|
|
|
|
|
_USER_AGENT => undef, |
|
24
|
|
|
|
|
|
|
_QUERY => "", |
|
25
|
|
|
|
|
|
|
_RESULTS => [], |
|
26
|
|
|
|
|
|
|
}; |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
4
|
return bless ($self, $class); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
0
|
|
0
|
sub DESTROY { } |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub query { |
|
37
|
4
|
|
|
4
|
0
|
78
|
my ($self, $str) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
4
|
100
|
|
|
|
13
|
if ( defined $str ) { |
|
40
|
1
|
|
|
|
|
3
|
$self->{_QUERY} = $str; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
4
|
|
|
|
|
22
|
return $self->{_QUERY}; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub submit { |
|
48
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
|
49
|
|
|
|
|
|
|
|
|
50
|
1
|
50
|
|
|
|
3
|
unless ( defined $self->query ) { |
|
51
|
0
|
|
|
|
|
0
|
croak "You didn't call query() yet"; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
5
|
my $user_agent = $self->user_agent(); |
|
55
|
1
|
|
|
|
|
4
|
my %form_ref = ( |
|
56
|
|
|
|
|
|
|
querystring => $self->query(), |
|
57
|
|
|
|
|
|
|
database => 'bukhari', |
|
58
|
|
|
|
|
|
|
dbpath => '/www/dept/MSA/reference/indices', |
|
59
|
|
|
|
|
|
|
logpath => '/www/dept/MSA/reference/indices/logfile', |
|
60
|
|
|
|
|
|
|
xpath => '/www/dept/MSA/reference/xfile' |
|
61
|
|
|
|
|
|
|
); |
|
62
|
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
6
|
my $response = $user_agent->post($PROXY, \%form_ref); |
|
64
|
1
|
50
|
|
|
|
528225
|
if ( $response->is_error ) { |
|
65
|
0
|
|
|
|
|
0
|
croak "couldn't fetch the results: " . $response->status_line; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
22
|
$self->{_CONTENT} = $response->content_ref; |
|
69
|
1
|
|
|
|
|
18
|
return $self->_parse_response($response); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _parse_response { |
|
75
|
1
|
|
|
1
|
|
2
|
my ($self, $response) = @_; |
|
76
|
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
2
|
my $content = ${$self->{_CONTENT}}; |
|
|
1
|
|
|
|
|
2
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
1779
|
require HTML::TreeBuilder; |
|
80
|
1
|
|
|
|
|
27686
|
my $html = new HTML::TreeBuilder(); |
|
81
|
1
|
|
|
|
|
333
|
$html->parse($content); |
|
82
|
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
1413
|
for my $a ( $html->look_down(\&_is_hadith) ) { |
|
84
|
0
|
|
|
|
|
0
|
my $href = $a->attr('href'); |
|
85
|
0
|
|
|
|
|
0
|
my $abs_href = URI->new_abs($href, $response->base); |
|
86
|
0
|
|
|
|
|
0
|
my $id = $abs_href->fragment; |
|
87
|
0
|
|
|
|
|
0
|
my ($volume, $book, $report) = $id =~ m/^(\d+)\.(\d+)\.(\d+w?)/; |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
0
|
push @{$self->{_RESULTS}}, { |
|
|
0
|
|
|
|
|
0
|
|
|
90
|
|
|
|
|
|
|
id => $id, |
|
91
|
|
|
|
|
|
|
url => $abs_href->as_string, |
|
92
|
|
|
|
|
|
|
book => $book, |
|
93
|
|
|
|
|
|
|
volume => $volume, |
|
94
|
|
|
|
|
|
|
report => $report |
|
95
|
|
|
|
|
|
|
}; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
1
|
|
|
|
|
18
|
$html->delete(); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub get_result { |
|
106
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
|
107
|
|
|
|
|
|
|
|
|
108
|
1
|
|
|
|
|
2
|
return shift @{$self->{_RESULTS}}; |
|
|
1
|
|
|
|
|
3
|
|
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub read { |
|
114
|
1
|
|
|
1
|
0
|
10
|
my ($self, $id) = @_; |
|
115
|
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
2
|
my $text = ""; |
|
117
|
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
4
|
my ($volume, $book, $report) = $id =~ m/^(\d+)\.(\d+)\.(\d+\w?)$/; |
|
119
|
1
|
|
|
|
|
10
|
my $url = sprintf($HADITH_URLF, 'bukhari', $book); |
|
120
|
|
|
|
|
|
|
|
|
121
|
1
|
|
|
|
|
5
|
my $user_agent = $self->user_agent(); |
|
122
|
1
|
|
|
|
|
7
|
my $response = $user_agent->get($url); |
|
123
|
1
|
50
|
|
|
|
808600
|
if ( $response->is_error ) { |
|
124
|
0
|
|
|
|
|
0
|
die $response->status_line; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
1
|
|
|
|
|
1816
|
require HTML::TokeParser; |
|
127
|
1
|
50
|
|
|
|
2979
|
my $html = HTML::TokeParser->new($response->content_ref) or die $!; |
|
128
|
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
197
|
my $header = 0; |
|
130
|
1
|
|
|
|
|
3
|
my $inside = 0; |
|
131
|
1
|
|
|
|
|
11
|
while ( my $token = $html->get_token() ) { |
|
132
|
107
|
50
|
66
|
|
|
2134
|
if ( !$header && ($token->[0] eq 'S') && ($token->[1] eq 'a') |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
133
|
|
|
|
|
|
|
&& ($token->[2]->{name}) && ($token->[2]->{name} eq $id) ) { |
|
134
|
0
|
|
|
|
|
0
|
$header = 1; |
|
135
|
0
|
|
|
|
|
0
|
next; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
107
|
50
|
|
|
|
429
|
$header or next; |
|
138
|
0
|
0
|
0
|
|
|
0
|
if ( ($token->[0] eq 'E') && ($token->[1] eq 'blockquote') ) { |
|
139
|
0
|
|
|
|
|
0
|
$header = 0; |
|
140
|
0
|
|
|
|
|
0
|
$inside = 0; |
|
141
|
0
|
|
|
|
|
0
|
last; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
0
|
0
|
0
|
|
|
0
|
if ( ($token->[0] eq 'S') && ($token->[1] eq 'blockquote') ) { |
|
144
|
0
|
|
|
|
|
0
|
$inside = 1; |
|
145
|
0
|
|
|
|
|
0
|
next; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
0
|
0
|
|
|
|
0
|
$inside or next; |
|
148
|
|
|
|
|
|
|
|
|
149
|
0
|
0
|
0
|
|
|
0
|
if ( ($token->[0] eq 'S') && ($token->[1] eq 'p') ) { |
|
|
|
0
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
0
|
$text .= "\n"; |
|
151
|
|
|
|
|
|
|
} elsif ( $token->[0] eq 'T' ) { |
|
152
|
0
|
|
|
|
|
0
|
$text .= $token->[1]; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
} |
|
155
|
1
|
|
|
|
|
87
|
return $text; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub result_count { |
|
161
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
162
|
|
|
|
|
|
|
|
|
163
|
0
|
0
|
|
|
|
0
|
unless ( $self->{_RESULTS} ) { |
|
164
|
0
|
|
|
|
|
0
|
return 0; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
0
|
|
|
|
|
0
|
return scalar @{$self->{_RESULTS}}; |
|
|
0
|
|
|
|
|
0
|
|
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub _is_hadith { |
|
171
|
9
|
|
|
9
|
|
141
|
my $el = shift; |
|
172
|
|
|
|
|
|
|
|
|
173
|
9
|
50
|
|
|
|
23
|
$el->tag() eq 'a' or return; |
|
174
|
0
|
0
|
|
|
|
0
|
$el->attr('href') or return; |
|
175
|
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
0
|
return $el->attr('href') =~ m!bukhari!; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub user_agent { |
|
189
|
3
|
|
|
3
|
0
|
5
|
my $self = shift; |
|
190
|
|
|
|
|
|
|
|
|
191
|
3
|
100
|
|
|
|
14
|
if ( defined $self->{_USER_AGENT} ) { |
|
192
|
2
|
|
|
|
|
8
|
return $self->{_USER_AGENT}; |
|
193
|
|
|
|
|
|
|
} |
|
194
|
1
|
|
|
|
|
1213
|
require LWP::UserAgent; |
|
195
|
1
|
|
|
|
|
57735
|
my $ua = LWP::UserAgent->new(from => 'sherzodr@handalak.com'); |
|
196
|
1
|
|
|
|
|
5355
|
$ua->agent( sprintf("%s (%s/%s)", $ua->agent(), ref($self), $self->VERSION) ); |
|
197
|
|
|
|
|
|
|
|
|
198
|
1
|
|
|
|
|
282
|
$self->{_USER_AGENT} = $ua; |
|
199
|
1
|
|
|
|
|
7
|
return $self->user_agent(); |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
1; |
|
204
|
|
|
|
|
|
|
__END__ |