line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Application::Plugin::HelpMan; |
2
|
1
|
|
|
1
|
|
16431
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
4
|
|
|
|
|
|
|
#use base 'CGI::Application'; |
5
|
1
|
|
|
1
|
|
746
|
use LEOCHARRE::DEBUG; |
|
1
|
|
|
|
|
1551
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
73
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
64
|
|
7
|
1
|
|
|
1
|
|
4
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
3
|
use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1658
|
|
9
|
|
|
|
|
|
|
@ISA = qw/ Exporter /; |
10
|
|
|
|
|
|
|
@EXPORT_OK = (qw( |
11
|
|
|
|
|
|
|
__abs_path_doc_to_html |
12
|
|
|
|
|
|
|
__find_abs |
13
|
|
|
|
|
|
|
__string_looks_like_command |
14
|
|
|
|
|
|
|
__term_to_command |
15
|
|
|
|
|
|
|
__term_to_namespace |
16
|
|
|
|
|
|
|
_doc_html |
17
|
|
|
|
|
|
|
_term_abs_path |
18
|
|
|
|
|
|
|
hm_abs_tmp |
19
|
|
|
|
|
|
|
hm_doc_body |
20
|
|
|
|
|
|
|
hm_doc_title |
21
|
|
|
|
|
|
|
hm_found_term_abs |
22
|
|
|
|
|
|
|
hm_found_term_doc |
23
|
|
|
|
|
|
|
hm_found_term_query |
24
|
|
|
|
|
|
|
hm_set_term |
25
|
|
|
|
|
|
|
hm_term_get |
26
|
|
|
|
|
|
|
hm_help_title |
27
|
|
|
|
|
|
|
hm_help_body |
28
|
|
|
|
|
|
|
_hm_reset_data |
29
|
|
|
|
|
|
|
_set_term_as_caller |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
)); |
32
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
33
|
|
|
|
|
|
|
ALL => \@EXPORT_OK, |
34
|
|
|
|
|
|
|
basic => \@EXPORT_OK, |
35
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /(\d+)/g; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# 1) is there something to look for? |
40
|
|
|
|
|
|
|
sub hm_found_term_query { |
41
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
42
|
0
|
0
|
|
|
|
0
|
$self->hm_term_get or return 0; |
43
|
0
|
|
|
|
|
0
|
return 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# 2) can we resolve it to disk? |
47
|
|
|
|
|
|
|
sub hm_found_term_abs { |
48
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
49
|
0
|
0
|
|
|
|
0
|
$self->_term_abs_path or return 0; |
50
|
0
|
|
|
|
|
0
|
return 1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _term_abs_path { |
54
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
55
|
0
|
0
|
0
|
|
|
0
|
$self->{_hm_data_}->{_term_abs_path} ||= __find_abs($self->hm_term_get) or return; |
56
|
0
|
|
|
|
|
0
|
return $self->{_hm_data_}->{_term_abs_path} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# 3) does it have doc? |
60
|
|
|
|
|
|
|
sub hm_found_term_doc { |
61
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
62
|
0
|
0
|
|
|
|
0
|
$self->_doc_html or return 0; |
63
|
0
|
|
|
|
|
0
|
return 1; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# body text for template |
67
|
|
|
|
|
|
|
sub hm_doc_body { |
68
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
69
|
0
|
0
|
|
|
|
0
|
my $html = $self->_doc_html or return 0; |
70
|
0
|
0
|
|
|
|
0
|
if( $html=~m/]*>(.+)<\/body>/si ){ |
71
|
0
|
|
|
|
|
0
|
my $body = $1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# sometimes Pod::Html will output even when there's no doc. |
74
|
0
|
|
|
|
|
0
|
my $length = length($html); |
75
|
0
|
|
|
|
|
0
|
debug("length $length\n"); |
76
|
|
|
|
|
|
|
# if less then 500, report nothing. |
77
|
0
|
0
|
|
|
|
0
|
$length > 500 or return 0; |
78
|
0
|
|
|
|
|
0
|
return $body; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
0
|
return 0; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# title text for template |
84
|
|
|
|
|
|
|
sub hm_doc_title { |
85
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
86
|
0
|
|
|
|
|
0
|
my $title; |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
0
|
my $html = $self->_doc_html or return 0; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
0
|
if( $html=~m/]*>(.+)<\/title>/si ){ |
|
|
0
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
$title = $1; |
93
|
0
|
|
|
|
|
0
|
debug("[$title]via html\n"); |
94
|
0
|
|
|
|
|
0
|
return $title; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
elsif( $self->hm_term_get ){ |
98
|
0
|
|
|
|
|
0
|
my $namespace = __term_to_namespace($self->hm_term_get); |
99
|
0
|
|
|
|
|
0
|
debug("[$namespace] via term to namespace\n"); |
100
|
0
|
|
|
|
|
0
|
return $namespace; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
0
|
return 0; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub hm_abs_tmp { |
107
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
108
|
0
|
|
|
|
|
0
|
my $d = $self->param('abs_tmp'); |
109
|
0
|
|
0
|
|
|
0
|
$d ||= '/tmp'; |
110
|
0
|
|
|
|
|
0
|
return $d; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# force set the term |
114
|
|
|
|
|
|
|
sub hm_set_term { |
115
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
116
|
0
|
|
|
|
|
0
|
my $term = shift; |
117
|
0
|
0
|
|
|
|
0
|
defined $term or confess('missing arg'); |
118
|
0
|
|
|
|
|
0
|
$self->{_hm_data_}->{_man_searchterm} = $term; |
119
|
0
|
|
|
|
|
0
|
return 1; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# term from query string, then from namespace of caller, your cgi app |
123
|
|
|
|
|
|
|
sub hm_term_get { |
124
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
125
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
0
|
unless( $self->{_hm_data_}->{_man_searchterm} ){ |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# first try from query |
129
|
0
|
|
|
|
|
0
|
my $term = $self->query->param('query'); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# then from caller |
132
|
0
|
|
0
|
|
|
0
|
$term ||= caller; # was using caller(1), wrong. |
133
|
0
|
|
|
|
|
0
|
$self->{_hm_data_}->{_man_searchterm} = $term; |
134
|
0
|
|
|
|
|
0
|
debug(" term is [$term]\n"); |
135
|
|
|
|
|
|
|
} |
136
|
0
|
|
|
|
|
0
|
return $self->{_hm_data_}->{_man_searchterm}; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# # private methods.... |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub _doc_html { |
147
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
148
|
0
|
0
|
|
|
|
0
|
unless(defined $self->{_hm_data_}->{_abs_path_htmlcode}){ |
149
|
|
|
|
|
|
|
|
150
|
0
|
0
|
|
|
|
0
|
unless( $self->_term_abs_path ){ |
151
|
0
|
|
|
|
|
0
|
warn("no abs path for term"); |
152
|
0
|
|
|
|
|
0
|
$self->{_hm_data_}->{_abs_path_htmlcode} = 0; |
153
|
0
|
|
|
|
|
0
|
return 0; |
154
|
|
|
|
|
|
|
} |
155
|
0
|
|
|
|
|
0
|
my $help_runmode_name = $self->get_current_runmode; |
156
|
0
|
|
0
|
|
|
0
|
$help_runmode_name ||=undef; |
157
|
0
|
|
|
|
|
0
|
$self->{_hm_data_}->{_abs_path_htmlcode} = |
158
|
|
|
|
|
|
|
__abs_path_doc_to_html( |
159
|
|
|
|
|
|
|
$self->_term_abs_path, $self->hm_abs_tmp, $help_runmode_name ); |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
0
|
|
|
0
|
$self->{_hm_data_}->{_abs_path_htmlcode} ||=0; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
0
|
return $self->{_hm_data_}->{_abs_path_htmlcode}; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# GET TITLE AND BODY FOR THE CALLER, NOT A QUERY |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub hm_help_body { |
171
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
172
|
0
|
|
|
|
|
0
|
$self->_set_term_as_caller; |
173
|
0
|
|
|
|
|
0
|
return $self->hm_doc_body; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub hm_help_title { |
177
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
178
|
0
|
|
|
|
|
0
|
$self->_set_term_as_caller; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
0
|
return $self->hm_doc_title; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub _set_term_as_caller { |
184
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
0
|
my $caller = caller(1); |
187
|
0
|
0
|
|
|
|
0
|
$caller or confess('caller should return'); |
188
|
|
|
|
|
|
|
|
189
|
0
|
0
|
|
|
|
0
|
unless( $self->hm_term_get eq $caller ){ |
190
|
0
|
|
|
|
|
0
|
$self->_hm_reset_data; |
191
|
0
|
|
|
|
|
0
|
$self->hm_set_term($caller); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
0
|
return 1; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub _hm_reset_data { |
199
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
200
|
0
|
|
|
|
|
0
|
$self->{_hm_data_} =undef; |
201
|
0
|
|
|
|
|
0
|
return 1; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
####################################################################### |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
# THE FOLLOWING SUBS ARE NOT OO |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
############################## |
210
|
|
|
|
|
|
|
# get html |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub __abs_path_doc_to_html { |
213
|
9
|
50
|
33
|
9
|
|
15820
|
my ($abs,$tmp,$runmode) = @_; defined $abs and defined $tmp or confess('missing args'); |
|
9
|
|
|
|
|
79
|
|
214
|
9
|
|
|
|
|
44
|
debug("$abs\n"); |
215
|
|
|
|
|
|
|
|
216
|
9
|
|
50
|
|
|
1146
|
$runmode ||= 'help_view'; |
217
|
9
|
|
|
|
|
124
|
debug("runomde = $runmode"); |
218
|
|
|
|
|
|
|
# can we write to this place, the tmp place? # TODO $self->hm_abs_tmp ? |
219
|
9
|
50
|
|
|
|
1112
|
chdir $tmp or confess("$!, cant chdir to $tmp"); # if you dont... breaks. because perl2html ne4eds to write a tmp file |
220
|
|
|
|
|
|
|
|
221
|
9
|
|
|
|
|
1109
|
require Pod::Html; |
222
|
9
|
|
|
|
|
301350
|
require File::Slurp; |
223
|
|
|
|
|
|
|
|
224
|
9
|
|
|
|
|
20062
|
my $out = $tmp.'/helpman_temp_'. (int rand(600000)); |
225
|
9
|
|
|
|
|
43
|
debug("$out\n"); |
226
|
|
|
|
|
|
|
|
227
|
9
|
|
|
|
|
1677
|
Pod::Html::pod2html($abs, |
228
|
|
|
|
|
|
|
"--outfile=$out", |
229
|
|
|
|
|
|
|
# "--verbose", |
230
|
|
|
|
|
|
|
# '--css=http://search.cpan.org/s/style.css' |
231
|
|
|
|
|
|
|
"--htmlroot=?rm=$runmode".'&query=', # WORKS for LINKING |
232
|
|
|
|
|
|
|
); |
233
|
|
|
|
|
|
|
#TODO needs work up there. |
234
|
|
|
|
|
|
|
|
235
|
9
|
50
|
|
|
|
2322243
|
my $html = File::Slurp::slurp($out) or warn("could not slurp $out"); |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# debug("\n\n$html\n\n"); NO |
238
|
|
|
|
|
|
|
|
239
|
9
|
|
|
|
|
2394
|
return $html; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
##################################### |
244
|
|
|
|
|
|
|
# find on disk |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub __find_abs { |
247
|
11
|
50
|
|
11
|
|
391517
|
my $term = shift; $term or confess('missing arg'); |
|
11
|
|
|
|
|
57
|
|
248
|
|
|
|
|
|
|
|
249
|
11
|
|
|
|
|
34
|
my $as_command = __term_to_command($term); |
250
|
11
|
|
|
|
|
39
|
my $as_namespace = __term_to_namespace($term); |
251
|
|
|
|
|
|
|
|
252
|
11
|
|
|
|
|
30
|
my $abs; |
253
|
|
|
|
|
|
|
|
254
|
11
|
|
|
|
|
121
|
require Pod::Simple::Search; |
255
|
11
|
|
|
|
|
107
|
my $pss = Pod::Simple::Search->new; |
256
|
11
|
100
|
|
|
|
645
|
if( $abs = $pss->find($as_namespace) ){ |
|
|
50
|
|
|
|
|
|
257
|
9
|
|
|
|
|
21347
|
debug("via namespace: [$as_namespace] -> $abs\n"); |
258
|
9
|
|
|
|
|
1411
|
return $abs; |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
elsif ( defined $as_command ){ |
261
|
0
|
|
|
|
|
0
|
require File::Which; |
262
|
0
|
0
|
|
|
|
0
|
$abs = File::Which::which($as_command) or return; |
263
|
0
|
|
|
|
|
0
|
debug("via command: [$as_command] -> $abs\n"); |
264
|
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
0
|
require Cwd; |
266
|
0
|
0
|
0
|
|
|
0
|
Cwd::abs_path( $abs ) or warn("cant resolve $abs") and return; |
267
|
0
|
|
|
|
|
0
|
return $abs; |
268
|
|
|
|
|
|
|
} |
269
|
2
|
|
|
|
|
3761
|
return; |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
sub __term_to_command { |
273
|
11
|
50
|
|
11
|
|
21
|
my $term = shift; defined $term or return; |
|
11
|
|
|
|
|
29
|
|
274
|
11
|
|
|
|
|
79
|
$term=~s/^\s+|\s$//g; |
275
|
11
|
100
|
|
|
|
33
|
__string_looks_like_command($term) or return; |
276
|
1
|
|
|
|
|
3
|
return $term; |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
sub __string_looks_like_command { |
280
|
11
|
50
|
|
11
|
|
22
|
my $string = shift; $string or return; |
|
11
|
|
|
|
|
39
|
|
281
|
11
|
100
|
|
|
|
159
|
$string=~/^[a-z]+[\w\-]+[a-zA-Z]+$/ or return 0; |
282
|
1
|
|
|
|
|
4
|
return 1; |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
#turn some silly string into a namespace |
286
|
|
|
|
|
|
|
sub __term_to_namespace { |
287
|
11
|
50
|
|
11
|
|
21
|
my $term = shift ; defined $term or confess('no term arg'); |
|
11
|
|
|
|
|
39
|
|
288
|
11
|
|
|
|
|
742
|
debug($term); |
289
|
11
|
|
|
|
|
1521
|
$term=~s/^\W|\W$//g; |
290
|
|
|
|
|
|
|
|
291
|
11
|
|
|
|
|
40
|
$term=~s/\/+/::/g; |
292
|
|
|
|
|
|
|
|
293
|
11
|
|
|
|
|
57
|
$term=~s/\.html?$|\.pm$|\.pl$//g; |
294
|
11
|
|
|
|
|
62
|
debug(": $term\n"); |
295
|
11
|
|
|
|
|
1532
|
return $term; |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
1; |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
__END__ |