Re: Modules inter-relay ?

2006-12-04 Thread Bill Jones

On 12/4/06, Mug [EMAIL PROTECTED] wrote:

 BEGIN {
 unshift (@INC, /special);
 unshift (@INC, /special/packages);
 }

 use strict;
 use InitGlobal;



And if I didn't get mis-understood on what I've studied, 'use' still
comes earlier than 'BEGIN{}', so what is the mystery why this
method can do that ?


In this particular case BEGIN comes first and simply tells Perl to
look at /special and /special/packages BEFORE looking anywhere else
for the packages you wish to use in your various projects.

You still need to make sure the proper functions/sub-routines are
exported so that your code is called in preference over the Perl
code.

However, if you wish to control what is required -- say branch
logic, you will need to stick with te 'require' directive as use
packages referenced will always be brought in even if they are not
called.

HTH/-Sx-
--
WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Modules inter-relay ?

2006-12-04 Thread Jenda Krynicky
From: Mug [EMAIL PROTECTED]
 Say I have 2 modules ( below pseudo codes ) , which the first
 package ( InitGlobal ) will be used through out the other project
 modules. However, InitGlobal itself would relay on some other modules,
 which the modules using InitGlobal too.
 
 This sometimes caused some weir problem, or perhaps it
 just runable with luck. So I have to fix it one by on with to cutting
 some shareable code to another .pl file with require() to call them,
 but sound quite terrible enough. Not sure how do Perl handle this, or
 is that any standard way for module inter-relay ( or Is that any
 formal term to call this ? )

So you have two interdependend modules, right? A uses stuff from B, B 
uses stuff from A.

You should reorder your code to prevent this. And if the two are too 
intertwined to do that, put them both into the same file.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Modules inter-relay ?

2006-12-03 Thread Mug
Hi all,

Say I have 2 modules ( below pseudo codes ) , which the first
package ( InitGlobal ) will be used through out the other project
modules. However, InitGlobal itself would relay on some other
modules, which the modules using InitGlobal too.

This sometimes caused some weir problem, or perhaps it
just runable with luck. So I have to fix it one by on with to cutting
some shareable code to another .pl file with require() to call
them, but sound quite terrible enough. Not sure how do Perl
handle this, or is that any standard way for module inter-relay
( or Is that any formal term to call this ? )

Any pointers are greatly appreciate.

Thank you very much,
Mug


package InitGlobal ;
use strict;
use LocalePrint ;

sub GetVars { .. }

sub PhaseError {
shift ; LocalePrint @_ ;
}

sub Build {
# add something to %ENV;
bless {}
}
1;
__END__


package LocalePrint ;
use strict;
use InitGlobal ;

 exported LocalePrint ...
..

our $gvar = InitGlobal::Build ;


sub LocalePrint {

my %vars = gvar - GetVars ( @_ );

my $remote = $ENV{REMOTE_ADDR} ;

if ( $remote ) { # CGI mode

if ( $remote eq $localhost ) {
# using %vars
# return error details
}
else { # not admin on localhost
# using %vars
# write sys log;
# return friendly message;
}

}
else {
# using %vars
# return shell message
}
}
1;
__END__





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Modules inter-relay ?

2006-12-03 Thread Bill Jones

On 12/4/06, Mug [EMAIL PROTECTED] wrote:


Say I have 2 modules ( below pseudo codes ) , which the first
package ( InitGlobal ) will be used through out the other project
modules. However, InitGlobal itself would relay on some other
modules, which the modules using InitGlobal too.



You can place the special packages in their own directory and point to it:

BEGIN {
   unshift (@INC, /special);
   unshift (@INC, /special/packages);
}

use strict;
use InitGlobal;

HTH/-Sx-
--
WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Modules inter-relay ?

2006-12-03 Thread Mug
Bill Jones wrote:
 On 12/4/06, Mug [EMAIL PROTECTED] wrote:

 Say I have 2 modules ( below pseudo codes ) , which the first
 package ( InitGlobal ) will be used through out the other project
 modules. However, InitGlobal itself would relay on some other
 modules, which the modules using InitGlobal too.


 You can place the special packages in their own directory and point
 to it:

 BEGIN {
 unshift (@INC, /special);
 unshift (@INC, /special/packages);
 }

 use strict;
 use InitGlobal;

 HTH/-Sx-


Thank you very much Bill,

But may I ask a bit further because a bit can't get what should in terms
of 'special'
and what should in terms of 'their' and this piece of code should put to
where ? ( self
use or in the other all packages )

And if I didn't get mis-understood on what I've studied, 'use' still
comes earlier than
'BEGIN{}', so what is the mystery why this method can do that ?

Thank you for more hints, =)
Mug









-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response