Dear Monks, I have quite a few CGI scripts that with time became slow, so I decided to use Apache::Registry to speed them up. However, I encountered an interesting problem -- automatically generated subroutines get lost. Here's an example I came up with to illustrate the problem:

Dmitri/Test.pm

package Dmitri::Test; INIT { # This does not work under Apache::Registry: *{"Dmitri::Test::ABC::say_hello"} = sub { print "hi\n"; }; *{"Dmitri::Test::ABC::new"} = sub { return bless {}, "Dmitri:: +Test::ABC" ; }; # This works: #sub Dmitri::Test::ABC::say_hello { print "hi\n"; }; #sub Dmitri::Test::ABC::new { return bless {}, "Dmitri::Test:: +ABC"; }; } sub say_hi { my $x = Dmitri::Test::ABC->new; $x->say_hello; } 1;

test.cgi

#!/usr/bin/perl -w use Dmitri::Test; print <<HTML; Content-type: text/plain HTML Dmitri::Test::say_hi; exit(0);

The code runs fine under mod_cgi. Using Apache::Registry, I get this error:

[Wed Nov 6 16:49:12 2002] [error] Can't locate object method "new" via package "Dmitri::Test::ABC" (perhaps you forgot to load "Dmitri::Test::ABC"?) at /usr/lib/perl5/site_perl/5.6.1/Dmitri/Test.pm line 14.

I could theoretically use the second method pointed out in Test.pm code, but the problem is that the routines are generated from code refs, and doing

sub A::B::routine { &$ref }

just causes me mental pain and anguish (inefficient).

I wonder if your collective wisdom could show me the way out of this problem. Many thanks.


In reply to Apache::Registry losing subs created via globs. by dmitri

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.