require from autoload module

M

Marc Girod

Hello,

From an autoloaded function, a require statement succeeds, without
importing any function.
Using the same module works fine from a normal script.
I suspect a problem with my own autoloaded module, or an interaction
of the autoload mechanism.

The code snippet from my autoloaded function:

--8<------
package ClearCase::Wrapper::MGi;

$VERSION = '0.11';

use warnings;
use strict;
use vars qw($ct $eqhl $prhl $diat);
($eqhl, $prhl, $diat) = qw(EqInc PrevInc DelInc);

sub compareincs($$) {
....
}
use AutoLoader 'AUTOLOAD';
use ClearCase::Wrapper;
....
sub unlock() {
my $fl = "ClearCase::Wrapper::ForceLock";
eval "require $fl";
....
--8<------

My test script:

--8<------
#!/usr/bin/perl -w

use ClearCase::Wrapper::ForceLock;

my $lt = 'ZZZ_1.00';
my $v = '/wran_cm_makesystem';
flocklt($lt, $v);
--8<------

Under the debugger, with the latter, I get:

main::(./flock:5): my $lt = 'ZZZ_1.00';
DB<1> S ClearCase::Wrapper::ForceLock.*
ClearCase::Wrapper::ForceLock::BEGIN
ClearCase::Wrapper::ForceLock::flocklt
ClearCase::Wrapper::ForceLock::funlocklt
ClearCase::Wrapper::ForceLock::ssh

Whereas with the former:

o blib/lib/auto/ClearCase/Wrapper/MGi/unlock.al):954):
954: eval "require $fl";
DB<3> S ClearCase::Wrapper::(For|MGi).*
ClearCase::Wrapper::ForceLock::BEGIN
ClearCase::Wrapper::MGi::BEGIN
ClearCase::Wrapper::MGi::compareincs
ClearCase::Wrapper::MGi::unlock
DB<4> n
ClearCase::Wrapper::MGi::unlock((eval 303)[blib/lib/ClearCase/Wrapper/
MGi.pm (autosplit into blib/lib/auto/ClearCase/Wrapper/MGi/unlock.al):
954]:3):
3:
DB<4> p $?
0
DB<5> S ClearCase::Wrapper::(For|MGi).*
ClearCase::Wrapper::ForceLock::BEGIN
ClearCase::Wrapper::MGi::BEGIN
ClearCase::Wrapper::MGi::compareincs
ClearCase::Wrapper::MGi::unlock

Clearly (!?) I have 'entered' the ForceLock module (even before my run-
time require!), but not have not gone far enough to define and import
the functions there...
It seems to me like the problem is not in the imported module, since
it works from the test script.
As if there was a cycle?

Can you help me make sense of that?
Thanks!

Marc
 
M

Marc Girod

Just a precision...

The code snippet from my autoloaded function:

--8<------ ....
use AutoLoader 'AUTOLOAD';
use ClearCase::Wrapper;
... 1;

__END__
....
sub unlock() {
...
--8<------
Can you help me make sense of that?

Also, I read now perlmod, and try to use the UNITCHECK, CHECK, and
INIT blocks...

Thanks!

Marc
 
M

Marc Girod

Also, I read now perlmod, and try to use the UNITCHECK, CHECK, and
INIT blocks...

Some progress...
I use now:
require $fl
with $fl having the file name...
Somehow, eval "require $fl" seems not to inject the functions names to
my scope.
And I added a 'no AutoLoader' at the block level.

I am not quite there yet, but there is some hope that your help might
come too late!

Marc
 
A

A. Sinan Unur

Some progress...
I use now:
require $fl
with $fl having the file name...
Somehow, eval "require $fl" seems not to inject the functions names to
my scope.
And I added a 'no AutoLoader' at the block level.

It is hard for me to follow what you are doing and I am not sure why you
need the eval.

Is:

require $fl;
$fl->import;

not doing what you want?

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
M

Marc Girod

It is hard for me to follow what you are doing and I am not sure why you
need the eval.

I am sorry. It is a bit hard to extract enough, yet not too much.
I got now something that works, but there surely is room for
improvement.
Is:

require $fl;
$fl->import;

not doing what you want?

"perldoc -f require" explains that eval is required in that case.
I didn't try 'import'. Isn't it implicit?
This would explain why my attempts failed...

In my current version, there is no import, and I convert myself
the Foo::Bar syntax into Foo/Bar.pm before passing to require.

Marc
 
M

Marc Girod

What do you have to change to get it to stop working?

Without the import, I had to use 'no AutoLoad'
to call the function from the required module.

I guess I don't anymore, but I'll verify it only later.
Thanks.
Marc
 
A

A. Sinan Unur

I am sorry. It is a bit hard to extract enough, yet not too much.
I got now something that works, but there surely is room for
improvement.


"perldoc -f require" explains that eval is required in that case.

I cannot believe I failed to realize this for such a long time. Thank
you for pointing it out.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
M

Marc Girod

I cannot believe I failed to realize this for such a long time. Thank
you for pointing it out.

Well, thank you for the 'import'.
I had read the 'require' page, but not the 'use' one.
And 'import' is not mentioned with 'require',
understandably so, would I admit in hindsight...

I could drop the no Autoload.
The resulting code (diffs) are in:

http://code.google.com/p/clearcase-cpan/source/detail?r=330

or in context:

http://code.google.com/p/clearcase-...th=/branches/ClearCase-Wrapper-MGi/dev/MGi.pm

Thanks!
Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top