Roger C Haslock wrote:
>
> The thoughts behind my questions included the following
>
> 'Why "our $variable"?'
>
> I looked at the 'our' variables. It seemed to me that they should be local
> to the enclosing module: only the database connect/disconnect subroutine
> names need be exported. Certainly it seems unwise to write code which
> exports the database password all over the place. Surely this should not
> even be hard coded.
if it weren't hard-coded, how could you get a database handle?
this wasn't meant to be a tutorial on databases, but i would hope that
users know to create a restricted user (called 'http' or 'www', for
example) that has access to just the one database and has no grant
permissions, etc., and use that username/password in the base class.
> 'Why "class"?'
>
> 'Class' and 'method' are terminology used by OOP. Beginners to Perl will
> need to learn Perl terminology, and will not find these terms in the index
> of most extant perl books. Furthermore, how to implement a class in perl
> needs a tutorial of its own.
> I note you are equating 'class' with 'package': do you mean by this that a
> class needs a package of several modules for its implementation?
from 'Programming Perl, 3rd edition', p. 289:
in perl, classes and packages and modules are all so closely related
that novices can often think of them as being interchangeable.
and besides, why shouldn't a beginner be learning oop? it will save
them time in the long run if they learn it now. i kick myself sometimes
at the fact that i didn't learn it right away.
> 'Why not CGI.pm?'
>
> Beginners will wish to learn to use this module; it is highly thought of.
> I looked for HTML::Template in Active State, and again in CPAN, with no
> luck.
http://search.cpan.org/search?mode=module&query=HTML%3A%3ATemplate
once again, i *do* use cgi.pm, but only for reading the form parameters,
not for generating output. again, i refer you to the introduction as to
why.
> Incidentally, I noticed that you are making a new database connection each
> time you call cgi->new. Do you intend this, and if so, why?
the database handle is created when the handler ref is constructed, not
when the ref to cgi.pm is constructed:
my $cgi = new CGI; # get a ref to a CGI object
my $action = $cgi->param('action') || 'start';
my $c = PEACE::AddressBook::Handler->new(
action => $action,
cgi => $cgi
); # get a ref to a handler object (initiating the db connection)