beckheng has asked for the wisdom of the Perl Monks concerning the following question:

Below is the skeleton:

-------configuration file(MyConfigTest.pm)--

package PBB::Packages::MyConfigTest; use strict; @PBB::Packages::MyConfigTest::ISA = qw(Exporter); %PBB::Packages::MyConfigTest::stash = ( "p_type" => "text/html", "p_charset" => "UTF-8", "p_theme" => "gnome-default", "css_files" => ["aa.js", "bb.js"], ); 1;
-------startup file(mystartup.pl)-------
#!/usr/bin/perl use lib qw(/path/myprj); use strict; 1;
-------my module file(ControllerTest.pm)--
package PBB::ControllerTest; use vars qw($q $t); use vars qw(%stash); use Apache2::RequestIO (); use Apache2::Const -compile => ':common'; use CGI qw(); use CGI::Carp qw(fatalsToBrowser); use PBB::Packages::MyConfigTest; use Data::Dumper; use strict; *stash = \%PBB::Packages::MyConfigTest::stash; sub handler{ my $r = shift; $q = new CGI; print $q->header(); $t = {}; @{$t->{stash}}{keys %stash} = values %stash; $t->{stash}->{css_files} = [@{$t->{stash}->{css_files}}, "a.js", " +b.js"]; #other code here return Apache2::Const::OK; } 1;
Regards.

Replies are listed 'Best First'.
Re: Please share your advice about my mod_perl program
by ides (Deacon) on Mar 01, 2007 at 15:27 UTC

    Without really knowing your actual question, here are some off hand comments about your code, I would suggest the following:

    • Pre-load PBB::ControllerTest and PBB::Packages::MyConfigTest in your startup.pl with simple use statements. This allows the code to be shared among the various Apache children.
    • In fact, pre-load all of the modules you are going to be using such as CGI, CGI::Carp, Apache2::Const, etc, etc.
    • Personally I would use either PerlSetVars, a config file using something like Config::General, or write my own Apache directives for that small amount of config data. It's just a personal pet peeve of mine to have "configs" in code. While it may not be a requirement of your application today, this makes it very difficult to deploy two instances of your application on the same server.

    Frank Wiles <frank@revsys.com>
    www.revsys.com

Re: Please share your advice about my mod_perl program
by TOD (Friar) on Mar 01, 2007 at 04:30 UTC
    and what is your question?
Re: Please share your advice about my mod_perl program
by Joost (Canon) on Mar 01, 2007 at 11:55 UTC
Re: Please share your advice about my mod_perl program
by perrin (Chancellor) on Mar 01, 2007 at 21:56 UTC
    Hi beckheng. Here are some suggestions for you:

    You aren't really using Exporter here. I think you should. Put in a line like this in PBB::Packages::MyConfigTest:

    our @EXPORT_OK = qw(%stash);
    And then call it from PBB::ControllerTest like this:
    use PBB::Packages::MyConfigTest qw(%stash);
    Then you can get rid of the line with the *stash typeglob and the use vars qw(%stash) line. I suggest you put your use strict in PBB::ControllerTest right after the package declaration and add a use warnings.

    Don't make $q and $t global variables. You're only using them in your handler() sub, so just declar them there as lexical (my) variables.

    In general, you should be using our instead of use vars these days.

    When I talked to you on use.perl.org, it sounded like you didn't want those file names added to the end of your array ref. What you're showing here though looks like you're trying to append two entries to the end of this array reference, which is best done with a push, like you had before.

Re: Please share your advice about my mod_perl program
by jesuashok (Curate) on Mar 01, 2007 at 08:00 UTC
    hi beckheng,

    If you could provide some more information about your requirement, could be useful to guide you properly