You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by pascal barbedor <pa...@laposte.net> on 2001/10/06 23:24:45 UTC
piece of code in mod_perl guide
hello,
I am reading mod_perl guide and i had a problem with a piece of code in chapter 9.7.4.2 about
reloading configuration files. this is version jan 2001 but i have checked in the last one the piece of code is the same.
when running the code exactly, things don't work, even outside mod_perl environnment.
the sub below print file is different even though I don't change the file.
I have located that if i change $MODIFIED{$file} = -M _; to an explicit $MODIFIED{$file} = -M $file;
in the last line, everything works fine.
since i do no test on any other file and I have understood that _ account s for the last file tested, I don't understand why it does work.
I am on NT4 perl 5.6.1
try it yourself ! so strange !
thanks for any explanation
*********************************
for (1..10){
reread_conf("l:/asperl/site/lib/afpa/evolif/config.pm");
sleep 2;
}
our %MODIFIED;
sub reread_conf{
my $file=shift;
return unless $file;
return unless -e $file and -r _;
if ($MODIFIED{$file} and $MODIFIED{$file}== -M _){
print "same" ; }else {print "different";}
print "\n";
unless ($MODIFIED{$file} and $MODIFIED{$file}== -M _){
unless (my $result = do $file) {
warn ...
}
print "\nmod:",$MODIFIED{$file},' :', -M _,"\n";
$MODIFIED{$file} = -M _;
}
}
Re: piece of code in mod_perl guide
Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> pascal barbedor wrote:
>
>>>>
>>> [ .... ]
>>>
>>>> config.pm file
>>>> ---------------------------------------------
>>>> package AFPA::Evolif::Config ;
>>>>
>>>> use XML::LibXML () ;
>>>> use XML::LibXSLT () ;
>>>> use XML::XPath () ;
>>>> use XML::Simple () ;
>>>> use DBI () ;
>>>>
>>> [ ... ]
>>>
>>> Hi,
>>> Could it be that XML::XPath does file tests on the
>>> file $xmlfile passed to it through
>>> XML::XPath->new(filename => $xmlfile)
>>> which would cause '_' to use the stat on $xmlfile, rather
>>> than the original config file?
>>>
>>> best regards,
>>> randy kobes
>>>
>>>
>>>
>>
>>
>>
>> oh yes, this was the answer ! XML::XPATh->new stats the file.
>>
>> thanks for clearing it out !
>>
>> then maybe the last line of reread_conf in mod_perl guide should be
>> modified to
>>
>> $MODIFIED{$file} = -M $file;
>>
>> in case the do ( ) loads something which can possibily stat file.
>
>
> ok, I'll add a note, saying that _ shouldn't be used if it's not known
> whether no other files are stat'ed in between. Or even the other way
> around, so the default will be -M $file
At the end I've just cached the value of -M, and saved an otherwise
needed stat() syscall :)
use vars qw(%MODIFIED);
sub reread_conf{
my $file = shift;
return unless defined $file;
return unless -e $file and -r _;
my $mod = -M _;
unless (exists $MODIFIED{$file} and $MODIFIED{$file} == $mod){
my $result;
unless ($result = do $file) {
warn "couldn't parse $file: $@" if $@;
warn "couldn't do $file: $!" unless defined $result;
warn "couldn't run $file" unless $result;
}
$MODIFIED{$file} = $mod; # Update the MODIFICATION times
}
} # end of reread_conf
--
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: piece of code in mod_perl guide
Posted by Stas Bekman <st...@stason.org>.
pascal barbedor wrote:
>>>
>>[ .... ]
>>
>>>config.pm file
>>>---------------------------------------------
>>>package AFPA::Evolif::Config ;
>>>
>>>use XML::LibXML () ;
>>>use XML::LibXSLT () ;
>>>use XML::XPath () ;
>>>use XML::Simple () ;
>>>use DBI () ;
>>>
>>[ ... ]
>>
>>Hi,
>> Could it be that XML::XPath does file tests on the
>>file $xmlfile passed to it through
>> XML::XPath->new(filename => $xmlfile)
>>which would cause '_' to use the stat on $xmlfile, rather
>>than the original config file?
>>
>>best regards,
>>randy kobes
>>
>>
>>
>
>
>
> oh yes, this was the answer ! XML::XPATh->new stats the file.
>
> thanks for clearing it out !
>
> then maybe the last line of reread_conf in mod_perl guide should be
> modified to
>
> $MODIFIED{$file} = -M $file;
>
> in case the do ( ) loads something which can possibily stat file.
ok, I'll add a note, saying that _ shouldn't be used if it's not known whether no other files are stat'ed in between. Or even the other way around, so the default will be -M $file
Good catch, Randy!
--
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
Re: piece of code in mod_perl guide
Posted by pascal barbedor <pa...@laposte.net>.
> >
> >
> [ .... ]
> > config.pm file
> > ---------------------------------------------
> > package AFPA::Evolif::Config ;
> >
> > use XML::LibXML () ;
> > use XML::LibXSLT () ;
> > use XML::XPath () ;
> > use XML::Simple () ;
> > use DBI () ;
> [ ... ]
>
> Hi,
> Could it be that XML::XPath does file tests on the
> file $xmlfile passed to it through
> XML::XPath->new(filename => $xmlfile)
> which would cause '_' to use the stat on $xmlfile, rather
> than the original config file?
>
> best regards,
> randy kobes
>
>
oh yes, this was the answer ! XML::XPATh->new stats the file.
thanks for clearing it out !
then maybe the last line of reread_conf in mod_perl guide should be
modified to
$MODIFIED{$file} = -M $file;
in case the do ( ) loads something which can possibily stat file.
pascal barbedor
sub reread_conf{
> my $file=shift;
> return unless $file;
> return unless -e $file and -r _;
> unless ($MODIFIED{$file} and $MODIFIED{$file}== -M _){
> unless (my $result = do $file){
> print "lecture\n";
> warn "lecture de $file impossible: $@" if $@;
> warn "do de $file impossible: $!" unless defined $result;
> warn "run de $file impossible" unless $result;
> }
> $MODIFIED{$file} = -M _
> }
> }
Re: piece of code in mod_perl guide
Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
----- Original Message -----
From: "pascal barbedor" <pa...@laposte.net>
To: "Stas Bekman" <st...@stason.org>
Cc: <mo...@apache.org>
Sent: Sunday, October 07, 2001 12:03 PM
Subject: Re: piece of code in mod_perl guide
>
> ----- Original Message -----
> From: "Stas Bekman" <st...@stason.org>
> To: "pascal barbedor" <pa...@laposte.net>
> Cc: <mo...@apache.org>
> Sent: Sunday, October 07, 2001 2:22 PM
> Subject: Re: piece of code in mod_perl guide
>
> > > I have located that if i change $MODIFIED{$file} = -M _; to an
> > > explicit $MODIFIED{$file} = -M $file;
> >
> > That's weird. _ uses the cached stat's output from the last stat call.
> > Does this work for you?
> >
> > perl -e '-s "/etc/passwd"; print -M _'
> >
>
> yes it works, but the piece of code in mod_perl guide does not work, on my
> specific config.pm, I don't understand why.
> see below, the code, the output of the code, the config file .
>
> In fact, it looks like when I try it on any other file that my config
file,
> it works. or it works on my config file with the explicit -M $file instead
> of -M _.
>
> for (1..10){ reread_conf("l:/config.pm") }
> our %MODIFIED;
> sub reread_conf{
> my $file=shift;
> return unless $file;
> return unless -e $file and -r _;
> if ($MODIFIED{$file} and $MODIFIED{$file}== -M _){
> print "same" } else { print "different" }
> print "\n";
> unless ($MODIFIED{$file} and $MODIFIED{$file}== -M _){
> unless (my $result = do $file){
> print "lecture\n";
> warn "lecture de $file impossible: $@" if $@;
> warn "do de $file impossible: $!" unless defined $result;
> warn "run de $file impossible" unless $result;
> }
> print "\nmod:",$MODIFIED{$file},' :', -M _,"\n";
> $MODIFIED{$file} = -M _
> }
> }
>
[ .... ]
> config.pm file
> ---------------------------------------------
> package AFPA::Evolif::Config ;
>
> use XML::LibXML () ;
> use XML::LibXSLT () ;
> use XML::XPath () ;
> use XML::Simple () ;
> use DBI () ;
[ ... ]
Hi,
Could it be that XML::XPath does file tests on the
file $xmlfile passed to it through
XML::XPath->new(filename => $xmlfile)
which would cause '_' to use the stat on $xmlfile, rather
than the original config file?
best regards,
randy kobes
Re: piece of code in mod_perl guide
Posted by pascal barbedor <pa...@laposte.net>.
----- Original Message -----
From: "Stas Bekman" <st...@stason.org>
To: "pascal barbedor" <pa...@laposte.net>
Cc: <mo...@apache.org>
Sent: Sunday, October 07, 2001 2:22 PM
Subject: Re: piece of code in mod_perl guide
> >
> >
> >
> > I have located that if i change $MODIFIED{$file} = -M _; to an
> > explicit $MODIFIED{$file} = -M $file;
>
>
> That's weird. _ uses the cached stat's output from the last stat call.
> Does this work for you?
>
> perl -e '-s "/etc/passwd"; print -M _'
>
yes it works, but the piece of code in mod_perl guide does not work, on my
specific config.pm, I don't understand why.
see below, the code, the output of the code, the config file .
In fact, it looks like when I try it on any other file that my config file,
it works. or it works on my config file with the explicit -M $file instead
of -M _.
If you can find any explanation...
pascal barbedor
code run
: --------------------------------------------------------------------------
------------------
print -s 'l:/config.pm',"\n", -M _,"\n";
for (1..10){ reread_conf("l:/config.pm") }
our %MODIFIED;
sub reread_conf{
my $file=shift;
return unless $file;
return unless -e $file and -r _;
if ($MODIFIED{$file} and $MODIFIED{$file}== -M _){
print "same" } else { print "different" }
print "\n";
unless ($MODIFIED{$file} and $MODIFIED{$file}== -M _){
unless (my $result = do $file){
print "lecture\n";
warn "lecture de $file impossible: $@" if $@;
warn "do de $file impossible: $!" unless defined $result;
warn "run de $file impossible" unless $result;
}
print "\nmod:",$MODIFIED{$file},' :', -M _,"\n";
$MODIFIED{$file} = -M _;
}
}
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-----------
output of code (see that the first stat worked and gives an age of very few
fraction of days, where reread_conf gives 66 days.)
with -M _ last line
983
0.00259259259259259
different
mod: :
different
mod: :67.2868981481481
different
mod:67.2868981481481 :67.2868981481481
different
mod:67.2868981481481 :67.2868981481481
different
mod:67.2868981481481 :67.2868981481481
different
mod:67.2868981481481 :67.2868981481481
different
mod:67.2868981481481 :67.2868981481481
different
mod:67.2868981481481 :67.2868981481481
different
mod:67.2868981481481 :67.2868981481481
different
mod:67.2868981481481 :67.2868981481481
Bonne exécution du processus
----------------------------------------------------------------------------
---------------------
output of code with -M $file last line
983
0.0047337962962963
different
mod: :
same
same
same
same
same
same
same
same
same
Bonne exécution du processus
----------------------------------------------------------------------------
------
config.pm file
package AFPA::Evolif::Config ;
use XML::LibXML () ;
use XML::LibXSLT () ;
use XML::XPath () ;
use XML::Simple () ;
use DBI () ;
my $base='l:/perlinclude';
$CHASH{pconn}->disconnect() if $CHASH{pconn};
our %CHASH = (
indicateurs =>
XML::LibXML->new->parse_file('l:/perlinclude/indicateurs.xml')
,
glups =>
XML::LibXSLT->new->parse_stylesheet
(XML::LibXML->new->parse_file("l:/perlinclude/glups.xsl"))
,
groupes =>XML::XPath->
new(filename=>"l:/perlinclude/categories/groupements.xml")
,
zones =>XML::XPath->
new(filename=>"l:/perlinclude/categories/decoupages.xml")
,
select=>XML::LibXSLT->new->parse_stylesheet
(XML::LibXML->new->parse_file("l:/perlinclude/evselecteur.xsl"))
,
pconn=>DBI->connect("DBI:mysql:database=evolif;host=localhost",
"pconn",
undef,
{RaiseError=>1}
)
,
) ;
#my $stylesheet=
# XML::LibXSLT->new->parse_stylesheet (F_GLUP_XML);
#print $stylesheet->transform(F_IND_XML);
1 ;
Re: piece of code in mod_perl guide
Posted by Stas Bekman <st...@stason.org>.
pascal barbedor wrote:
> hello,
>
>
>
> I am reading mod_perl guide and i had a problem with a piece of code in
> chapter 9.7.4.2 about
>
> reloading configuration files. this is version jan 2001 but i have
> checked in the last one the piece of code is the same.
>
>
>
> when running the code exactly, things don't work, even outside mod_perl
> environnment.
>
>
>
> the sub below print file is different even though I don't change the file.
>
>
>
> I have located that if i change $MODIFIED{$file} = -M _; to an
> explicit $MODIFIED{$file} = -M $file;
That's weird. _ uses the cached stat's output from the last stat call.
Does this work for you?
perl -e '-s "/etc/passwd"; print -M _'
use some existing file of course.
> in the last line, everything works fine.
>
>
>
>
>
> since i do no test on any other file and I have understood that _
> account s for the last file tested, I don't understand why it does work.
>
> I am on NT4 perl 5.6.1
>
> try it yourself ! so strange !
>
>
>
>
>
> thanks for any explanation
>
>
>
>
>
> *********************************
>
>
>
> for (1..10){
>
>
>
> reread_conf("l:/asperl/site/lib/afpa/evolif/config.pm");
>
>
>
> sleep 2;
>
>
>
> }
>
>
>
>
>
>
>
> our %MODIFIED;
>
>
> sub reread_conf{
>
>
>
> my $file=shift;
>
>
>
> return unless $file;
>
>
>
> return unless -e $file and -r _;
>
>
>
> if ($MODIFIED{$file} and $MODIFIED{$file}== -M _){
>
>
>
> print "same" ; }else {print "different";}
>
>
>
> print "\n";
>
>
>
>
> unless ($MODIFIED{$file} and $MODIFIED{$file}== -M _){
>
>
> unless (my $result = do $file) {
>
> warn ...
>
>
>
> }
>
>
>
>
> print "\nmod:",$MODIFIED{$file},' :', -M _,"\n";
>
>
>
> $MODIFIED{$file} = -M _;
>
>
>
> }
>
>
>
>
> }
>
>
>
>
>
--
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/