List Info

Thread: RE: How best to modularise with strict




RE: How best to modularise with strict
country flaguser name
United States
2007-05-20 12:19:48
Well, I would put them into a module, like the subject line
to your email suggests.
 
First, create a modules directory, and then in your script
create a module call.  You have to use two module for this:
 
use lib '/home/ete.etc.etc./modules';use db_mod;
 
You can use the 'pwd' unix command to get an accurate lib
path; the name of your module must go beneath it.
 
Next build your module.  Here's a module template:
 
package db_mod;require Exporter;ISA = qw(Exporter);EXPORT =
qw($dbh, $url, say_hey);EXPORT_OK = qw();use
strict;use CGI;use CGI::Carp qw(warningsToBrowser
fatalsToBrowser);
 
our $dbh =
DBI->connect('DBI:mysql:insert_db_name:localhost','insert
_username','insert_password');
 
our $url = 'www.whatever.com';
 
sub say_hey { print "Hello World!n"; }
 
1;
A few notes on the module (in no particular order).  1.) The
EXPORT line must list all the variables and subs you
wish to export, 2.) CHMOD it to 644, as it doesnt need to be
executable, just readable; 3.) The CGI::Carp line is in
there only for development purposes, so take it out when you
have finished your app; 4.) the package line contains the
name of the module, which must be reflected in the script;
5.) The module must end with a 1, i.e. it must return a 1
value, or it will fail.
 
You should protect your modules directory with an .htaccess
file.  The following code works:
 
<FilesMatch ".pm$">Order deny,allow Deny
from all</FilesMatch>
 
Just c&p it into a notepad file, title it .htaccess and
upload it.
 
There may be some typos in the above scripts, as I just woke
up, but I think they should work.
 
Good luck.
HTH,
 
q
 
 
 


To: perl-beginner@yahoogroups.comFrom: kenshail.co.ukDate: Sun, 20 May 2007 15:21:23
+0000Subject: [PBML] How best to modularise with strict




I have a fairly large script that uses strict and has a
signifcantnumber of global variables declared at the
beginning with 'our'.I would like to move them all in to a
separate file in order tosimplify layout.What is the
recommended method, if indeed it is possible? 


____________________________________________________________
_____
Download Messenger. Start an i’m conversation. Support a
cause. Join now.
http://im.live.com/messenger/im/home/?source=TAGWL_MAY07


[Non-text portions of this message have been removed]



Unsubscribing info is here: h
ttp://help.yahoo.com/help/us/groups/groups-32.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://g
roups.yahoo.com/group/perl-beginner/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http
://groups.yahoo.com/group/perl-beginner/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:perl-beginner-digest@yahoogroups.com 
    mailto:perl-beginner-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    perl-beginner-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

Re: How best to modularise with strict
country flaguser name
United States
2007-05-21 14:07:11

--- In perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com, essential quint
&lt;quintessential1...> wrote:
&gt;
>
> Well, I would put them into a module, like the subject line to your
email suggests.
>
> First, create a modules directory, and then in your script create a
module call. You have to use two module for this:
&gt;
> use lib '/home/ete.etc.etc./modules';use db_mod;
>
> You can use the 'pwd' unix command to get an accurate lib path; the
name of your module must go beneath it.
>
> Next build your module. Here's a module template:
>
> package db_mod;require Exporter;ISA = qw(Exporter);EXPORT =
qw($dbh, $url, say_hey);EXPORT_OK = qw();use strict;use CGI;use
CGI::Carp qw(warningsToBrowser fatalsToBrowser);
>
> our $dbh =
DBI-&gt;connect('DBI:mysql:insert_db_name:localhost','insert_username','insert_password');
>
> our $url = 'www.whatever.com';
>
> sub say_hey { print "Hello World!n&quot;; }
>
> 1;
> A few notes on the module (in no particular order). 1.) The EXPORT
line must list all the variables and subs you wish to export, 2.)
CHMOD it to 644, as it doesnt need to be executable, just readable;
3.) The CGI::Carp line is in there only for development purposes, so
take it out when you have finished your app; 4.) the package line
contains the name of the module, which must be reflected in the
script; 5.) The module must end with a 1, i.e. it must return a 1
value, or it will fail.
&gt;
> You should protect your modules directory with an .htaccess file.
The following code works:
&gt;
> <FilesMatch ".pm$">Order deny,allow Deny from all</FilesMatch>;
>
> Just c&p it into a notepad file, title it .htaccess and upload it.
>
> There may be some typos in the above scripts, as I just woke up, but
I think they should work.
&gt;
> Good luck.
&gt; HTH,
>;
> q
>
Thanks for such a comprehensive and helful reply.

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )