Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Alex I think this one's for you...

Quote Reply
Alex I think this one's for you...
I'm wondering, I've created a file Connect.pm that interlinks LinkSQL with WWWThreads.
This is all it is:
use strict;
use w3ttheme qw(%theme);
use w3tvars qw(%config);
use vars qw($dbh $VERSION %lang);
use lib '..';
use Links;
use Links::DB_Utils;
use Links::DBSQL;
But the thing is there are some routines I'm worried will get confused. The only subs I could find by the same name were in w3t.pm and DBSQL.pm. &authentic I already took care of as this was one of the main reasons for doing this...for the most part I'm not worried about the w3t programs getting the wrong one because he mostly calls his functions w3t::function_name(...);

But in DBSQL.pm there is &do () , &prepare() that I'm somewhat worried about as they are also SQL functions, so if in a w3t sub the do function is called will it use the SQL call or will it use the DBSQL version?

I'm worried about any kind of conflicts arising between the w3t.pm and DBSQL subs or restrictions, but what doesn't make sense is that this particular one is a SQL function.

Can you (or someone) give me their thoughts on how this might create errors and affect perfomance, pretty please Smile.
Quote Reply
Re: Alex I think this one's for you... In reply to
sql is also called that way..

except first an object is created for DBSQL.. ie:

my $db = new Links::DBSQL "blah/blah/Blah.def";


its just like saying..


don't worry.. because they have the same names nothing will happen.. it only gets affected in requires or stuff.. ie:

sub do in perlLib.pl and sqlLib.pl

require "perlLib.pl";
require "sqlLib.pl";

the sub do in sqlLib.pl will get overwrited..

Jerry Su
Quote Reply
Re: Alex I think this one's for you... In reply to
Thanks for the post & Happy Thanksgiving everyone!

If I understand what you are saying, then this prolly will cause prolems. Doesn't the use statement work the same as a require? WEll so far I have seen no significant errors pop up but I haven't been testing much.

In the above example you use. Is $db->do just like saying Links::DBSQL::do because of the line above it (my $db = new Links::DBSQL "...b...l...a";) that already links $db to the appropriate table or is it just because do is a sub in a "use"d file?

Sorry, your response has tipped off more questions than answers for me, isn't it always thus.

Quote Reply
Re: Alex I think this one's for you... In reply to
use isn't like require.. when you use 'use' it just links to that file for further use.. when you require.. the file you require's code is executed and becomes part of the current script..

a 'use'd file's routines is usually executed using the object or link to it.. ie: Links::DBSQL is like a link to it and $db = new Links::DBSQL.. $db becomes a variable holding the object which is created in DBSQL.pm..

'use'ing multiple modules
containing the same subroutine name is ok.. nothing wrong will happen.. just say you have two modules.. DBSQL.pm and vB.pm .. if DBSQL.pm and vB.pm both contain sub 'user' nothing will happen.. you use them like this..

$something = pathto::DBSQL->user ();
$another = pathto::vB->user ();

i'm not sure if thats the correct code.. memory's fading..

Jerry Su
Quote Reply
Re: Alex I think this one's for you... In reply to
Excellent...thanks so much! I feel much more comfortable now.

Quote Reply
Re: Alex I think this one's for you... In reply to
One other thing to remember about USE and REQUIRE is:

"use" is a compile time option, and "require" is a runtime option!

That means any code that is "used" is imported, and CHECKED, at compile time.

Any code that is "required" is only loaded and checked at RUN TIME!

If you include code in a large switch statement, for example, you may not find all the bugs until the code goes into production, since the "require" is _ONLY_ executed when the statement that holds the "require" is run!

This can make loading faster, if you have a large switch statement to load different files depending on what was asked of it.

This is a _real_ source of errors.

And, you can't use "use" in a BEGIN block, since it most likely will_not_ behave as you expect!

These are not just different names for the same actions!

PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ