This file is indexed.

/usr/share/doc/libapache2-mod-perl2-doc/docs/2.0/api/ModPerl/MethodLookup.html is in libapache2-mod-perl2-doc 2.0.8+httpd24-r1449661-6ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>

<body style="background-color: white">



<ul id="index">
  <li><a href="#NAME">NAME</a></li>
  <li><a href="#Synopsis">Synopsis</a></li>
  <li><a href="#Description">Description</a></li>
  <li><a href="#API">API</a>
    <ul>
      <li><a href="#lookup_method">lookup_method()</a></li>
      <li><a href="#lookup_module">lookup_module()</a></li>
      <li><a href="#lookup_object">lookup_object()</a></li>
      <li><a href="#preload_all_modules">preload_all_modules()</a></li>
      <li><a href="#print_method">print_method()</a></li>
      <li><a href="#print_module">print_module()</a></li>
      <li><a href="#print_object">print_object()</a></li>
    </ul>
  </li>
  <li><a href="#Applications">Applications</a>
    <ul>
      <li><a href="#AUTOLOAD">AUTOLOAD</a></li>
      <li><a href="#Command-Line-Lookups">Command Line Lookups</a></li>
    </ul>
  </li>
  <li><a href="#Todo">Todo</a></li>
  <li><a href="#See-Also">See Also</a></li>
  <li><a href="#Copyright">Copyright</a></li>
  <li><a href="#Authors">Authors</a></li>
</ul>

<h1 id="NAME">NAME</h1>

<p>ModPerl::MethodLookup -- Lookup mod_perl modules, objects and methods</p>

<h1 id="Synopsis">Synopsis</h1>

<pre><code>  use ModPerl::MethodLookup;
  
  # return all module names containing XS method &#39;print&#39;
  my ($hint, @modules) =
      ModPerl::MethodLookup::lookup_method(&#39;print&#39;);
  
  # return only module names containing method &#39;print&#39; which
  # expects the first argument to be of type &#39;Apache2::Filter&#39;
  # (here $filter is an Apache2::Filter object)
  my ($hint, @modules) =
      ModPerl::MethodLookup::lookup_method(&#39;print&#39;, $filter);
  # or
  my ($hint, @modules) =
      ModPerl::MethodLookup::lookup_method(&#39;print&#39;, &#39;Apache2::Filter&#39;);
  
  # what XS methods defined by module &#39;Apache2::Filter&#39;
  my ($hint, @methods) =
      ModPerl::MethodLookup::lookup_module(&#39;Apache2::Filter&#39;);
  
  # what XS methods can be invoked on the object $r (or a ref)
  my ($hint, @methods) =
      ModPerl::MethodLookup::lookup_object($r);
  # or
  my ($hint, @methods) =
      ModPerl::MethodLookup::lookup_object(&#39;Apache2::RequestRec&#39;);
  
  # preload all mp2 modules in startup.pl
  ModPerl::MethodLookup::preload_all_modules();
  
  # command line shortcuts
  % perl -MModPerl::MethodLookup -e print_module \
    Apache2::RequestRec Apache2::Filter
  % perl -MModPerl::MethodLookup -e print_object Apache2
  % perl -MModPerl::MethodLookup -e print_method \
    get_server_built request
  % perl -MModPerl::MethodLookup -e print_method read
  % perl -MModPerl::MethodLookup -e print_method read APR::Bucket</code></pre>

<h1 id="Description">Description</h1>

<p>mod_perl 2.0 provides many methods, which reside in various modules. One has to load each of the modules before using the desired methods. <code>ModPerl::MethodLookup</code> provides the Perl API for finding module names which contain methods in question and other helper functions, to find out out what methods defined by some module, what methods can be called on a given object, etc.</p>

<h1 id="API">API</h1>

<h2 id="lookup_method"><code>lookup_method()</code></h2>

<p>Find modules (packages) containing a certain method</p>

<pre><code>  ($hint, @modules) = lookup_method($method_name);
  ($hint, @modules) = lookup_method($method_name, $object);
  ($hint, @modules) = lookup_method($method_name, $class));</code></pre>

<dl>

<dt id="arg1:-method_name-string">arg1: <code>$method_name</code> ( string )</dt>
<dd>

<p>the method name to look up</p>

</dd>
<dt id="opt-arg2:-object-or-class">opt arg2: <code>$object</code> or <code>$class</code></dt>
<dd>

<p>a blessed object or the name of the class it&#39;s blessed into. If there is more than one match, this extra information is used to return only modules containing methods operating on the objects of the same kind.</p>

<p>If a sub-classed object is passed it&#39;ll be handled correctly, by checking its super-class(es). This usage is useful when the <code><a href="#C_AUTOLOAD_">AUTOLOAD</a></code> is used to find a not yet loaded module which include the called method.</p>

</dd>
<dt id="ret1:-hint">ret1: <code>$hint</code></dt>
<dd>

<p>a string containing a human readable lookup result, suggesting which modules should be loaded, ready for copy-n-paste or explaining the failure if the lookup didn&#39;t succeed.</p>

</dd>
<dt id="ret2:-modules">ret2: <code>@modules</code></dt>
<dd>

<p>an array of modules which have matched the query, i.e. the names of the modules which contain the requested method.</p>

</dd>
<dt id="since:-2.0.00">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<p>Examples:</p>

<p>Return all module names containing XS method <i>print</i>:</p>

<pre><code>  my ($hint, @modules) =
      ModPerl::MethodLookup::lookup_method(&#39;print&#39;);</code></pre>

<p>Return only module names containing method <i>print</i> which expects the first argument to be of type <code>Apache2::Filter</code>:</p>

<pre><code>  my $filter = bless {}, &#39;Apache2::Filter&#39;;
  my ($hint, @modules) =
      ModPerl::MethodLookup::lookup_method(&#39;print&#39;, $filter);</code></pre>

<p>or:</p>

<pre><code>  my ($hint, @modules) =
      ModPerl::MethodLookup::lookup_method(&#39;print&#39;, &#39;Apache2::Filter&#39;);</code></pre>

<h2 id="lookup_module"><code>lookup_module()</code></h2>

<p>Find methods contained in a certain module (package)</p>

<pre><code>  ($hint, @methods) = lookup_module($module_name);</code></pre>

<dl>

<dt id="arg1:-module_name-string">arg1: <code>$module_name</code> ( string )</dt>
<dd>

<p>the module name</p>

</dd>
<dt id="ret1:-hint1">ret1: <code>$hint</code></dt>
<dd>

<p>a string containing a human readable lookup result, suggesting, which methods the module <code>$module_name</code> implements, or explaining the failure if the lookup failed.</p>

</dd>
<dt id="ret2:-methods">ret2: <code>@methods</code></dt>
<dd>

<p>an array of methods which have matched the query, i.e. the names of the methods defined in the requested module.</p>

</dd>
<dt id="since:-2.0.001">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<p>Example:</p>

<p>What XS methods defined by module <code>Apache2::Filter</code>:</p>

<pre><code>  my ($hint, @methods) =
      ModPerl::MethodLookup::lookup_module(&#39;Apache2::Filter&#39;);</code></pre>

<h2 id="lookup_object"><code>lookup_object()</code></h2>

<pre><code>  ($hint, @methods) = lookup_object($object);
  ($hint, @methods) = lookup_object($class);</code></pre>

<dl>

<dt id="arg1:-object-or-class">arg1: <code>$object</code> or <code>$class</code></dt>
<dd>

<p>an object or a name of a class an object is blessed into</p>

<p>If a sub-classed object is passed it&#39;ll be handled correctly, by including methods provided by its super-class(es).</p>

</dd>
<dt id="ret1:-hint2">ret1: <code>$hint</code></dt>
<dd>

<p>a string containing a human readable lookup result, suggesting, which methods the given object can invoke (including module names that need to be loaded to use those methods), or explaining the failure if the lookup failed.</p>

</dd>
<dt id="ret2:-methods1">ret2: <code>@methods</code></dt>
<dd>

<p>an array of methods which have matched the query, i.e. the names of the methods that can be invoked on the given object (or its class name).</p>

</dd>
<dt id="since:-2.0.002">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<p>META: As of this writing this function may miss some of the functions/methods that can be invoked on the given object. Currently we can&#39;t programmatically deduct the objects they are invoked on, because these methods are written in pure XS and manipulate the arguments stack themselves. Currently these are mainly XS functions, not methods, which of course aren&#39;t invoked on objects. There are also logging function wrappers (<code>Apache2::Log</code>).</p>

<p>Examples:</p>

<p>What XS methods can be invoked on the object <code>$r</code>:</p>

<pre><code>  my ($hint, @methods) =
      ModPerl::MethodLookup::lookup_object($r);</code></pre>

<p>or <code>$r</code>&#39;s class -- <code>Apache2::RequestRec</code>:</p>

<pre><code>  my ($hint, @methods) =
      ModPerl::MethodLookup::lookup_object(&#39;Apache2::RequestRec&#39;);</code></pre>

<h2 id="preload_all_modules"><code>preload_all_modules()</code></h2>

<p>The function <code>preload_all_modules()</code> preloads all mod_perl 2.0 modules, which implement their API in XS. This is similar to the mod_perl 1.0 behavior which has most of its methods loaded at the startup.</p>

<p>CPAN modules developers should make sure their distribution loads each of the used mod_perl 2.0 modules explicitly, and not use this function, as it takes the fine control away from the users. One should avoid doing this the production server (unless all modules are used indeed) in order to save memory.</p>

<dl>

<dt id="since:-2.0.003">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<h2 id="print_method"><code>print_method()</code></h2>

<p><code>print_method()</code> is a convenience wrapper for <code><a href="#C_lookup_method___">lookup_method()</a></code>, mainly designed to be used from the command line. For example to print all the modules which define method <i>read</i> execute:</p>

<pre><code>  % perl -MModPerl::MethodLookup -e print_method read</code></pre>

<p>Since this will return more than one module, we can narrow the query to only those methods which expect the first argument to be blessed into class <code>APR::Bucket</code>:</p>

<pre><code>  % perl -MModPerl::MethodLookup -e print_method read APR::Bucket</code></pre>

<p>You can pass more than one method and it&#39;ll perform a lookup on each of the methods. For example to lookup methods <code>get_server_built</code> and <code>request</code> you can do:</p>

<pre><code>  % perl -MModPerl::MethodLookup -e print_method \
    get_server_built request</code></pre>

<p>The function <code>print_method()</code> is exported by default.</p>

<dl>

<dt id="since:-2.0.004">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<h2 id="print_module"><code>print_module()</code></h2>

<p><code>print_module()</code> is a convenience wrapper for <code><a href="#C_lookup_module___">lookup_module()</a></code>, mainly designed to be used from the command line. For example to print all the methods defined in the module <code>Apache2::RequestRec</code>, followed by methods defined in the module <code>Apache2::Filter</code> you can run:</p>

<pre><code>  % perl -MModPerl::MethodLookup -e print_module \
    Apache2::RequestRec Apache2::Filter</code></pre>

<p>The function <code>print_module()</code> is exported by default.</p>

<dl>

<dt id="since:-2.0.005">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<h2 id="print_object"><code>print_object()</code></h2>

<p><code>print_object()</code> is a convenience wrapper for <code><a href="#C_lookup_object___">lookup_object()</a></code>, mainly designed to be used from the command line. For example to print all the methods that can be invoked on object blessed into a class <code>Apache2::RequestRec</code> run:</p>

<pre><code>  % perl -MModPerl::MethodLookup -e print_object \
    Apache2::RequestRec</code></pre>

<p>Similar to <code><a href="#C_print_object___">print_object()</a></code>, more than one class can be passed to this function.</p>

<p>The function <code>print_object()</code> is exported by default.</p>

<dl>

<dt id="since:-2.0.006">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<h1 id="Applications">Applications</h1>

<h2 id="AUTOLOAD"><code>AUTOLOAD</code></h2>

<p>When Perl fails to locate a method it checks whether the package the object belongs to has an <code>AUTOLOAD</code> function defined and if so, calls it with the same arguments as the missing method while setting a global variable <code>$AUTOLOAD</code> (in that package) to the name of the originally called method. We can use this facility to lookup the modules to be loaded when such a failure occurs. Though since we have many packages to take care of we will use a special <code>UNIVERSAL::AUTOLOAD</code> function which Perl calls if can&#39;t find the <code>AUTOLOAD</code> function in the given package.</p>

<p>In that function you can query <code>ModPerl::MethodLookup</code>, require() the module that includes the called method and call that method again using the goto() trick:</p>

<pre><code>  use ModPerl::MethodLookup;
  sub UNIVERSAL::AUTOLOAD {
      my ($hint, @modules) =
          ModPerl::MethodLookup::lookup_method($UNIVERSAL::AUTOLOAD, @_);
      if (@modules) {
          eval &quot;require $_&quot; for @modules;
          goto &amp;$UNIVERSAL::AUTOLOAD;
      }
      else {
          die $hint;
      }
  }</code></pre>

<p>However we don&#39;t endorse this approach. It&#39;s a better approach to always abort the execution which printing the <code>$hint</code>and use fix the code to load the missing module. Moreover installing <code>UNIVERSAL::AUTOLOAD</code> may cause a lot of problems, since once it&#39;s installed Perl will call it every time some method is missing (e.g. undefined <code>DESTROY</code> methods). The following approach seems to somewhat work for me. It installs <code>UNIVERSAL::AUTOLOAD</code> only when the the child process starts.</p>

<pre><code>  httpd.conf:
  -----------
  PerlChildInitHandler ModPerl::MethodLookupAuto

  startup.pl:
  -----------
  {
      package ModPerl::MethodLookupAuto;
      use ModPerl::MethodLookup;
    
      use Carp;
      sub handler {
    
          *UNIVERSAL::AUTOLOAD = sub {
              my $method = $AUTOLOAD;
              return if $method =~ /DESTROY/; # exclude DESTROY resolving
    
              my ($hint, @modules) =
                  ModPerl::MethodLookup::lookup_method($method, @_);
              $hint ||= &quot;Can&#39;t find method $AUTOLOAD&quot;;
              croak $hint;
          };
          return 0;
      }
  }</code></pre>

<p>This example doesn&#39;t load the modules for you. It&#39;ll print to STDERR what module should be loaded, when a method from the not-yet-loaded module is called.</p>

<p>A similar technique is used by <code><a>Apache2::porting</a></code>.</p>

<p>META: there is a better version of AUTOLOAD discussed on the dev list. Replace the current one with it. (search the archive for EazyLife)</p>

<h2 id="Command-Line-Lookups">Command Line Lookups</h2>

<p>When a method is used and mod_perl has reported a failure to find it, it&#39;s often useful to use the command line query to figure out which module needs to be loaded. For example if when executing:</p>

<pre><code>  $r-&gt;construct_url();</code></pre>

<p>mod_perl complains:</p>

<pre><code>  Can&#39;t locate object method &quot;construct_url&quot; via package
  &quot;Apache2::RequestRec&quot; at ...</code></pre>

<p>you can ask <code>ModPerl::MethodLookup</code> for help:</p>

<pre><code>  % perl -MModPerl::MethodLookup -e print_method construct_url
  To use method &#39;construct_url&#39; add:
          use Apache2::URI ();</code></pre>

<p>and after copy-n-pasting the use statement in our code, the problem goes away.</p>

<p>One can create a handy alias for this technique. For example, C-style shell users can do:</p>

<pre><code>   % alias lookup &quot;perl -MModPerl::MethodLookup -e print_method&quot;</code></pre>

<p>For Bash-style shell users:</p>

<pre><code>   % alias lookup=&quot;perl -MModPerl::MethodLookup -e print_method&quot;</code></pre>

<p>Now the lookup is even easier:</p>

<pre><code>  % lookup construct_url
  to use method &#39;construct_url&#39; add:
          use Apache2::URI;</code></pre>

<p>Similar aliases can be provided for <code><a href="#C_print_object___">print_object()</a></code> and <code><a href="#C_print_module___">print_module()</a></code>.</p>

<h1 id="Todo">Todo</h1>

<p>These methods aren&#39;t yet picked by this module (the extract from the map file):</p>

<pre><code> modperl_filter_attributes     | MODIFY_CODE_ATTRIBUTES
 modperl_spawn_proc_prog       | spawn_proc_prog
 apr_ipsubnet_create           | new</code></pre>

<p>Please report to <a>the mod_perl development mailing list</a> if you find any other missing methods. But remember that as of this moment the module reports only XS functions. In the future we may add support for pure perl functions/methods as well.</p>

<h1 id="See-Also">See Also</h1>

<ul>

<li><p><a>the mod_perl 1.0 backward compatibility document</a></p>

</li>
<li><p><a>porting Perl modules</a></p>

</li>
<li><p><a>porting XS modules</a></p>

</li>
<li><p><code><a>Apache2::porting</a></code></p>

</li>
</ul>

<h1 id="Copyright">Copyright</h1>

<p>mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.</p>

<h1 id="Authors">Authors</h1>

<p><a>The mod_perl development team and numerous contributors</a>.</p>


</body>

</html>