moderated >> Global objects and Mod_Perl

by Mark Hughes » Thu, 10 Mar 2005 20:36:19 GMT

Hi

Currently I am re-writing an existing Perl based web survey system. I am
using OO techniques but am new to these concepts and implementation details.

My setup is Mod_Perl, Apache, MySQL and Perl 5.004

My intention is to have a number of classes that 'shadow' their namesake DB
tables. Eg. a 'user' MySQL table and a 'user' Perl class that provides the
methods to deal with real world users. The 'user' class, (and all other DB
table classes) will subclass a class I'm calling 'database'.

In an ideal world, (although correct me if I'm wrong about this...) the
'database' class would subclass 'DBI'. However, I tried this and found it
wasn't straight-forward, a bit of Google homework seemed to suggest that it
would be a can of worms so instead I'm settling for initialising the
database class when each new http request is made and making a seperate DBI
object that 'user' and 'database' methods can use to perform the actual
interaction with MySQL.

My question: What is the best way to handle that DBI object? Do I have to
keeping passing it around as and when required or can I store a seperate
reference to it in each of the table classes that I'm creating? Even
better, can I make it global in scope to my 'database' class, I'm thinking
that this would be a good solution but am concerned because I've always
avoided global variables because of the Mod_Perl issues (ie. system users
start getting each others data). How do I make something globally scoped to
a package but ensure that values remain unique to the owners of each and
every http request?

Appreciate any help, (specific advice or just point me in the right
direction) from those that know about these things.

Cheers
Sparky


moderated >> Global objects and Mod_Perl

by Jeremy Nixon » Sat, 12 Mar 2005 04:26:13 GMT



What I do is this: I have a database class that is basically a minimal
wrapper around DBI, providing debug logging, error handling, and a few
convenience methods. It acts as a singleton, so you always get the same
object back from a new() call. The object creates a DBI object and stores
it. I register a cleanup handler that makes this database object commit
suicide at the end of the request.

Now, whenever and wherever I want to hit the database, I can just do a
new() call on this class and use the returned object; none of the code
has to worry about any of the scope or persistence issues at all.

--
Jeremy | XXXX@XXXXX.COM

moderated >> Global objects and Mod_Perl

by Nathan Eady » Fri, 18 Mar 2005 01:52:59 GMT


This sounds an aweful lot like Class::DBI
http://search.cpan.org/author/TMTM/Class-DBI-0.96/lib/Class/DBI.pm

--
# Replies to the From address get lost in the mists of time;
# an address I actually check is printed by this Perl script
s;;# Visit http://galion.lib.oh.us
;;($\)=reverse split/\//;print'eady@';

moderated >> Global objects and Mod_Perl

by Nathan Eady » Sun, 27 Mar 2005 06:50:17 GMT

or illiterate, whether
you live on the boulevard or in the alley, you're going to catch hell
just like I am. We're all in the same boat and we all are going to catch
the same hell from the same man. He just happens to be a white man. All
of us have suffered here, in this country, political oppression at the
hands of the white man, economic exploitation at the hands of the white
man, and social degradation at the hands of the white man.

Now in speaking like this, it doesn't mean that we're anti-white, but it
does mean we're anti-exploitation, we're anti-degradation, we're
anti-oppression. And if the white man doesn't want us to be anti-him,
let him stop oppressing and exploiting and degrading us. Whether we are
Christians or Muslims or nationalists or agnostics or atheists, we must
first learn to forget our differences. If we have differences, let us
differ in the closet; when we come out in front, let us not have
anything to argue about until we get finished arguing with the man. If
the late President Kennedy could get together with Khrushchev and
exchange some wheat, we certainly have more in common with each other
than Kennedy and Khrushchev had with each other.

If we don't do something real soon, I think you'll have to agree that
we're going to be forced either to us

moderated >> Global objects and Mod_Perl

by Jeremy Nixon » Sun, 27 Mar 2005 06:55:22 GMT

in Latin America. How do you think
he'll react to you when you learn what a real revolution is? You don't
know what a revolution is. If you did, you wouldn't use that word.

A revolution is bloody. Revolution is hostile. Revolution knows no
compromise. Revolution overturns and destroys everything that gets in
its way. And you, sitting around here like a knot on the wall, saying,
"I'm going to love these folks no matter how much they hate me." No, you
need a revolution. Whoever heard of a revolution where they lock arms,
as Reverend Cleage was pointing out beautifully, singing "We Shall
Overcome"? Just tell me. You don't do that in a revolution. You don't do
any singing; you're too busy swinging. It's based on land. A
revolutionary wants land so he can set up his own nation, an independent
nation. These Negroes aren't asking for no nation. They're trying to
crawl back on the plantation.

When you want a nation, that's called nationalism. When the white man
became involved in a revolution in this country against England, what
was it for? He wanted this land so he could set up another white nation.
That's white nationalism. The American Revolution was white nationalism.
The French Revolution was white nationalism. The Russian Revolution too
-- yes, it was -- white nationalism. You don't think so? Why [do] you
think Khrushchev and Mao can't get their heads together? White
nationalism. All the revolutions that's going on in Asia and Africa
today are based on what? Black nationalism. A revolutionary is a black
nationalist. He wants a nation. I was reading some beautiful words by
Reverend Cleage, pointing out why he couldn't get together with someone
else here in the city because all of them were afraid of being
identified with black nationalism. If you're afraid of black
nationalism, you're afraid of revolution. And if you love revolution,
you love black nationalism.

To understand this, you have to g

Similar Threads

1. mod_perl errors: prototype mismatch ... during global destruction

RedHat 7.3, latest patches on everything, cannot be upgraded to newer
releases of RedHat
Apache 1.3.27
modperl 1.26


Apache configuration:

<IfModule mod_perl.c>
  PerlModule Apache::DBI
  PerlRequire        /full/path/secure_cgi-bin/startup.pl
  PerlFreshRestart   On

  Alias /cgi-bin/ /full/path/secure_cgi-bin/
  <Directory "/full_path/secure_cgi-bin/">
  SetHandler perl-script
  PerlHandler Apache::PerlRun
  PerlSendHeader On
  Options +ExecCGI
  </Directory>



I can't seem to pinpoint when exactly this happens, but here's what I
get in the Apache error logs from time to time:

Prototype mismatch: sub
Apache::ROOTwww_2emydomain_2ecom::cgi_2dbin::myscript_2epl::myfunction
vs () at /other/path/required_script.pl line 1234 during global
destruction.

Any insight?

PLEASE: if you're going to reply via Email, please Email my initials
@w98.us, not  XXXX@XXXXX.COM  as I have heavy spam filtering turned on
and your message likely won't be received at all.

id

2. mod_perl and the global variable?

3. Global variables in mod_perl

4. mod_perl and global variables during startup - Perl

5. good mod_perl/mysql object oreinted application

I am looking for a good mod_perl/mysql application to study.  I have been
teaching myself perl for a few years now and have been doing things the
way I have interpreted documentation.  There are several things that I
think I am doing wrong, at least in a design standpoint, I would like a
good mod_perl somewhat basic web based interface to mysql with some help
on object oriented design and request handling.

Thanks for any suggestions.

6. mod_perl: can't locate object method... - Perl

7. mod_perl installed, but mod_perl.so file not created

I have a server with Apache 2.0.53 and Perl 5.8.5.  I installed
mod_perl 2.0.2 using the standard command:

perl MakeFile.PL MP_APXS=/usr/sbin/apxs

and got no error messages (sorry, I no longer have the complete output
that the installer displayed), however the installer gave the message
at the end:

> [warning] You'll need to add the following to httpd.conf:
> [warning]
> [warning]   LoadModule perl_module modules/mod_perl.so
> [warning]
> [warning] depending on your build, mod_perl might not live in
> [warning] the modules/ directory.

However, in my /usr/lib/httpd/modules directory, there are lots of .so
files, but no mod_perl.so file -- and I have searched my entire drive
on that machine but found no mod_perl.so file.  If mod_perl was
installed successfully, why wasn't the file created and what should I
do?

Thanks,

-Bennett

8. embedding DB handle in object (was adding key to DB object) - Perl DBI