I store some value with an array reference like :
$self->{stash}->{css_files} = ['a.css', 'b.css'];
I append another css file after with push function, so the array expand more and more.
So I must be avoid to using array reference in config variables.
Re:what's the trouble?
beckheng on 2007-02-28T15:55:49
Any help is luck for me.
These three script show what happens.
-------configuration file(MyConfigTest.pm)---------startup file(mystartup.pl)-------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;-------my module file(ControllerTest.pm)--#!/usr/bin/perl
use lib qw(/path/myprj);
use strict;
1;and the follow is the apache config sectionpackage 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;
print Dumper($t->{stash});
push @{$t->{stash}->{css_files}}, "a.js", "b.js";
print "<br/><br />";
print Dumper($t->{stash});
return Apache2::Const::OK;
}
1;
while browse with http://127.0.0.1/ptest<IfModule mod_perl.c>
PerlRequire "/path/myprj/mystartup.pl"
<Location/ptest>
SetHandler perl-script
PerlResponseHandler PBB::ControllerTest
PerlOptions +ParseHeaders
Order allow,deny
Allow from all
</Location>
</IfModule>,I see the result:
$VAR1 = { 'p_type' => 'text/html', 'css_files' => [ 'aa.js', 'bb.js', 'a.js', 'b.js', 'c.js', 'a.js', 'b.js', 'c.js', 'a.js', 'b.js', 'c.js' ], 'p_theme' => 'gnome-default', 'p_charset' => 'UTF-8' };
$VAR1 = { 'p_type' => 'text/html', 'css_files' => [ 'aa.js', 'bb.js', 'a.js', 'b.js', 'c.js', 'a.js', 'b.js', 'c.js', 'a.js', 'b.js', 'c.js', 'a.js', 'b.js', 'c.js' ], 'p_theme' => 'gnome-default', 'p_charset' => 'UTF-8' };
What's wrong with me?
Regards.
Re:what's the trouble?
perrin on 2007-02-28T18:40:34
I don't understand. Didn't you want the array to expand? If you were trying to replace it, just set it directly instead of using push:
$t->{stash}->{css_files} = ['a.js', 'b.js'];
There are several other things in this code that I would suggest changing, but this forum isn't the best place to do a code review. If you'd like more advice on your code, please post it on the mod_perl mailing list, or on http://perlmonks.org/.
Re:what's the trouble?
beckheng on 2007-03-01T02:55:16
I make mistake.
Direct assign value works good.
I never think it before.I always use push.
For more advice, I post it on
http://perlmonks.org/?node_id=602639
thx.
Regards.