You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2005/09/15 01:42:56 UTC
[rfc] a function to adjust @INC for live modules
When you develop several independent modules which are using each other,
it's usually a pain to always run 'make install' in all of them to get the
latest changes in, while working on the current module. I usually try to
add the lib subdirs to @INC so that I can test against liv, un-installed
dirs. Things get more complicated when you have .xs modules, since now you
have to include blib as well, but lib must come before blib. Moreover you
need to deal with -T, so I've come up with the following sub:
sub adjust_INC {
require lib;
require blib;
# untaint dir names
my @dirs = map { (/(.*)/) } @_;
# test against the source lib first for easier dev
do { blib->import($_) }
for grep { -d $_ } map { "$_/blib" } @dirs;
do { lib->import($_) }
for grep { -d $_ } map { "$_/lib" } @dirs;
}
Now let's say you have a layout of:
$HOME/modules/Apache-Foo/lib
$HOME/modules/Apache-Foo/blib
$HOME/modules/Apache-Bar/lib
$HOME/modules/Apache-Tar/lib
you can now include them all in @INC as following (e.g. from t/TEST.PL or
t/conf/modperl_extra.pl)
use Apache::Test ();
use File::Basename 'dirname';
use File::Spec::Functions 'catdir';
my @projects = qw(
Apache-Foo
Apache-Bar
Apache-Tar
);
my $top_dir = dirname Apache::Test::vars('top_dir');
adjust_INC(map { catdir $top_dir, $_ } @projects);
I was thinking to add this to Apache::TestUtil. If you like it, we should
come up with an intuitive name, as adjust_INC is just a temp name I use in
my project.
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://mailchannels.com
Re: [rfc] a function to adjust @INC for live modules
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> I guess I should start Stas::CoolStuff and just throw it there :)
+1
:)
--Geoff
Re: [rfc] a function to adjust @INC for live modules
Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
>
> Stas Bekman wrote:
>
>>When you develop several independent modules which are using each other,
>>it's usually a pain to always run 'make install' in all of them to get
>>the latest changes in, while working on the current module. I usually
>>try to add the lib subdirs to @INC so that I can test against liv,
>>un-installed dirs.
>
>
> yes, I recall :)
>
>
>>Things get more complicated when you have .xs
>>modules, since now you have to include blib as well, but lib must come
>>before blib.
>
>
> what's the point of that? if you need blib for xs modules that implies that
> you're using make to update the .so files, which automatically moves changed
> perl libraries to blib anyway. to me, using lib here starts getting really
> confusing, with the possibility that you would have made changes to .xs
> files that would not be picked up...
>
> but to developer his own methods :)
>
>>Moreover you need to deal with -T, so I've come up with the
>>following sub:
>>
>>sub adjust_INC {
>
> ...
>
>>I was thinking to add this to Apache::TestUtil. If you like it, we
>>should come up with an intuitive name, as adjust_INC is just a temp name
>>I use in my project.
>
>
> I'd much rather see this kind of thing in one of two places
>
> - a separate CPAN module
> - incorporated into standard perl tools, like MakeMaker or Test::Builder
>
> the reason being that this looks to be really useful to people that want to
> develop they way you like to, so it would be more universally useful than
> being isolated in Apache-Test.
>
> in truth, I think Apache-Test contains lots of stuff that really ought to
> have been places somewhere else for the betterment of all.
> t_write_perl_script() and its associated mkpath and cleanup functionality,
> for example, is such a useful testing feature that it's a shame nobody else
> can use it without installing Apache-Test or duplicating the code therein...
I guess I should start Stas::CoolStuff and just throw it there :) Thanks
for the feeback Geoff.
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://mailchannels.com
Re: [rfc] a function to adjust @INC for live modules
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Stas Bekman wrote:
> When you develop several independent modules which are using each other,
> it's usually a pain to always run 'make install' in all of them to get
> the latest changes in, while working on the current module. I usually
> try to add the lib subdirs to @INC so that I can test against liv,
> un-installed dirs.
yes, I recall :)
> Things get more complicated when you have .xs
> modules, since now you have to include blib as well, but lib must come
> before blib.
what's the point of that? if you need blib for xs modules that implies that
you're using make to update the .so files, which automatically moves changed
perl libraries to blib anyway. to me, using lib here starts getting really
confusing, with the possibility that you would have made changes to .xs
files that would not be picked up...
but to developer his own methods :)
> Moreover you need to deal with -T, so I've come up with the
> following sub:
>
> sub adjust_INC {
...
> I was thinking to add this to Apache::TestUtil. If you like it, we
> should come up with an intuitive name, as adjust_INC is just a temp name
> I use in my project.
I'd much rather see this kind of thing in one of two places
- a separate CPAN module
- incorporated into standard perl tools, like MakeMaker or Test::Builder
the reason being that this looks to be really useful to people that want to
develop they way you like to, so it would be more universally useful than
being isolated in Apache-Test.
in truth, I think Apache-Test contains lots of stuff that really ought to
have been places somewhere else for the betterment of all.
t_write_perl_script() and its associated mkpath and cleanup functionality,
for example, is such a useful testing feature that it's a shame nobody else
can use it without installing Apache-Test or duplicating the code therein...
--Geoff