You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jay Lawrence <Ja...@Lawrence.Net> on 2002/03/16 15:51:52 UTC
FYI Small hints for modules using directives
If anyone out there's building modules with directives you'll know
that its a tricky business. I ran across two problems and related
solutions. (Thanks for nudging me along for #1 Geoff - but #2 I solved
all by my lonesome!)
FIRST HINT - Modules compirised of several files and make Apache
Directives:
- Apache::ExtUtils is a bit more fussy than the regular ExtUtils
about paths for loading subfiles of a package.
- Can't load main module to resolve function prototypes at
perl Makefile.PL
I found I had to take the following approach. Imagine that I have a
sub module to Apache::Clean (see Listing 7.9 as a basis) called, say,
Apache::Clean::Exception. That means in my module's directory I would
have:
Clean.pm
Clean/Exception.pm
In the module Clean.pm I would load the related Exception module:
use Apache::Clean::Exception;
In modules that I have written where it does not use Apache::ExtUtils
in Makefile.PL this is not a problem - so I know I'm not toally out to
lunch! Turns out what is happening is that Apache::ExtUtils tries to
"use Apache::Clean" which ends up failing because the "use
Apache::Clean::Exception" therein fails. The INC path isn't tweaked
appropriately.
I tried to structure my packages like:
lib/Apache/Clean.pm
lib/Apache/Clean/Exception.pm
and
Apache/Clean.pm
Apache/Clean/Exception.pm
They didn't work either. Hmmm. Odd. Well, I still want that module to
load at some point - so what do I do?
Once the module is built and properly installed things go away - so my
module isn't really problem - that leaves Makefile.PL and friends. Ah
ha! Why not pre-load Apache::Clean::Exception (the problem in the
first place) from Makefile.PL?
So put my files back to how I wanted them in the first place:
Clean.pm
Clean/Exception.pm
Makefile.PL
And inside of Makefile.PL I put:
package Apache::Clean;
require "Clean/Exception.pm";
# however that doesn't quite do the trick since
# it must show as Apache::Clean::Exception having been loaded
# this is just Clean::Exception - which is not the same
# - solution? Fiddle with %INC
$INC{'Apache/Clean/Exception.pm'}=$INC{'Clean/Exception'};
# Of course you could change your module's directory structure to
# feature Apache in the path to begin with.
__END__
Now things work nicely for me!
------------------
SECOND HINT - Modules that use directives are testy about being tested
If you reference one of these modules via PREREQ_PM or try some tests
outside of Apache (it IS possible after all) they will fail at the
bootstrap method.
in your module (ie/ Clean.pm) change:
PACKAGE__->bootstrap($VERSION);
to
PACKAGE__->bootstrap($VERSION) if $ENV{'mod_perl'};
Voila - at least now you should have no complaints via MakeMaker
checking for PREREQ_PM and you can even do some tests - which no doubt
you've been anxious to write!!
---------------
Did all that make sense? I hope so - if not I shall endevour to
clarify.
Cheers,
Jay