perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Taras Yurij Vasylovitch <y...@softsky.com.ua>
Subject handler object: data sometimes resetting
Date Thu, 22 Sep 2005 13:11:35 GMT
Hello all. 
I have a problem in writing mutlithread-safe application on mod_perl. 
I have a file main.pm which is my object implementation:

package admin::main;
1;
package svntrac::admin;

use ..........
..............

print STDERR "I am require\n";
$Apache2::PerlSections::Save = 1;
$handlers::svntrac = svntrac::admin->new(
#config here
);


sub new
{
	my $class = shift;
	my $self = {config => {@_}};
	bless $self, $class;
	print STDERR "SVN DAV + Trac ADMIN: Starting up...\n";
###
# Some additional object initialization
###
	$self->{'edited'} = 0;
	$self->{'creation'} = time();
	return $self;
}


sub list : method
{
	my $self = shift;
	my $r = shift;
# What do we have in our flag??
	warn "Edited:".$self->{'edited'};
	$self->{'edited'} += 1;
	$r->content_type ('text/plain');
	$r->print ("HELLO!!!\n");
	$r->print ("Locking TestRepo\n");
	$r->print ('Writing in file during 5secs +-1minute '.
		time()."\n");

	sleep 5; # Doing something......
	$r->print('End of writing'.time()."\n");
	return Apache2::Const::OK;
};

__END__

Including it from Apache2:
PerlRequire				/home/yura/mod_perl/trac/admin/main.pm
# Creating instance of the object

<Location /projects/tracadmin>
	SetHandler				modperl
	PerlResponseHandler			$handlers::svntrac->list
</Location>


Looks good, isn't it?

And now i'll try to open this page (localhost/projects/tracadmin) in the
same time in 3 browser windows. After many times of "Refresh" hitting i
have such log:
Edited:0 at /home/yura/mod_perl/trac/admin/main.pm line 393. <-- good..
Edited:0 at /home/yura/mod_perl/trac/admin/main.pm line 393. <-- what's
that?
Edited:0 at /home/yura/mod_perl/trac/admin/main.pm line 393. <-- and
that???
Edited:1 at /home/yura/mod_perl/trac/admin/main.pm line 393. <-- ok,
going right...
Edited:2 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:3 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:4 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:5 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:6 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:7 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:0 at /home/yura/mod_perl/trac/admin/main.pm line 393. <-- hey,
why counter is 0 again???
Edited:1 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:2 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:3 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:4 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:5 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:6 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:7 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:8 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:9 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:10 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:11 at /home/yura/mod_perl/trac/admin/main.pm line 393.
Edited:12 at /home/yura/mod_perl/trac/admin/main.pm line 393. 

'edited' field it's just an example, a lot of variables somewhy gets their
initial values, but constructor is called only once, on Apache start...
Also i've been checking 'creation' field and address of this object(by
including in list() such strings: 
warn "Created: ".$self->{'creation'}; 
warn "Obj ref: ".$self;
), and it always prints out the same creation time and address, so it's
the same object... I can't imagine, why 'edited' field is falling to 0,
can you?

My Apache2 and mod_perl version:
$ ./httpd2_mod_perl -v
Server version: Apache/2.0.54
Server built:   Sep 20 2005 17:44:36

mod_perl: 2.0.1

Thanks for answer.


Mime
View raw message