Apache2-ClickPath

 view release on metacpan or  search on metacpan

lib/Apache2/ClickPath/Store.pm  view on Meta::CPAN

sub handler {
  my $r=shift;

  my $restorecwd=Perl::AtEndOfScope->new( sub{chdir shift}, Cwd::getcwd );

  my $cfg=Apache2::Module::get_config( __PACKAGE__, $r->server );

  my $d=$cfg->{"ClickPathStoreDirectory"};

  if( $cfg->{"ClickPathStoreTimeout"} ) {
    # Call cleanup at the end of a connection. So keep-alive requests
    # are served at full speed.
    $r->connection->pool->cleanup_register( \&cleanup, [$r->connection, $cfg] )
      unless( $r->connection->keepalives );
  }

  my ($what, $session, $k, $v, $param);

  if( $r->main and		# is subreq
      $param=$r->pnotes( 'Apache2::ClickPath::StoreClient::storeparams' ) ) {
    ($what, $session, $k, $v)=@{$param}{qw{a s k v}};
  } else {
    $CGI::Q=CGI->new( $r );
    $what=CGI::param( 'a' );

lib/Apache2/ClickPath/StoreClient.pm  view on Meta::CPAN

      } else {
	$I->store="$https://$ENV{SERVER_ADDR}:$ENV{SERVER_PORT}".$I->store;
      }
    }
  }

  return unless( length $I->store );

  unless( $I->store_is_local ) {
    $I->ua=LWP::UserAgent->new( timeout=>5,
				keep_alive=>3 );
  }

  return $I;
}

sub _get {
  my ($I,$k)=@_;

  if( $I->store_is_local ) {
    my $subr=$I->_r->lookup_uri( $I->store );

lib/Apache2/ClickPath/StoreClient.pm  view on Meta::CPAN

by C<Apache2::ClickPath> to find the correct store.

C<Apache2::ClickPath::StoreClient> can be used from within a mod_perl handler
or a CGI script.

If called from a mod_perl handler it requires the GlobalRequest to be set.
See L<Apache2::RequestUtil> for more information.

For communication with the store an L<LWP::UserAgent> is used unless a local
store is used, see L<"Local Store"> below. It is configured to use
keep-alive requests.

=head1 METHODS

=over 4

=item B<< Apache2::ClickPath::StoreClient->new >>

the constructor. It uses the environment variables C<SESSION> and
C<ClickPathMachineStore> to initiate itself. These variables are exported
from L<Apache2::ClickPath>. The store address is given as the 3rd column

t/session/011store.t  view on Meta::CPAN

ok t_cmp( t_read_file( "t/store/$session/klaus" ), 'value',
	  'value stored' );

$res=GET( "/store?a=get;s=$session;k=klaus" );
ok t_cmp( $res->content, 'value', 'get stored value' );
ok t_cmp( $res->code, 200, 'get returns code 200' );

$res=GET( "/store?a=get;s=$session;k=otto" );
ok t_cmp( $res->code, 404, 'get returns code 404' );

Apache::TestRequest::user_agent( reset=>1, keep_alive=>300 );
$res=GET( "/store?a=get;s=$session;k=klaus" );
sleep 3;
$res=GET( "/store?a=get;s=$session;k=klaus" );
ok t_cmp( $res->code, 200, 'no timeout yet' );

sleep 3;
Apache::TestRequest::user_agent( reset=>1, keep_alive=>0 );
sleep 1;
ok t_cmp( -d "t/store/#$session", 1, 'session marked for deletion (renamed)' );

$res=GET( "/store?a=get;s=$session;k=klaus" );
ok t_cmp( $res->code, 404, 'data not accessible' );

sleep 3;
$res=GET( "/store?a=get;s=$session;k=klaus" ); # let cleanup() run once again
sleep 1;			# and give it time to accomplish the task
$res=GET( "/store?a=get;s=$session;k=klaus" );
$res=GET( "/store?a=get;s=$session;k=klaus" );
ok t_cmp( $res->code, 404, 'session store deleted => NOT_FOUND' );
ok t_cmp( -d "t/store/#$session", undef, 'session directory deleted' );

Apache::TestRequest::user_agent( reset=>1 ); # close the kept alive connection

Apache::TestRequest::module('Secret');

$session=GET_BODY( "/TestSession__001session_generation?SESSION" );
$session=~s/SESSION=//; chomp( $session );

t_debug( "using session $session" );

$res=GET( "/store?a=set;s=$session;k=klaus;v=value" );

t/session/011store.t  view on Meta::CPAN

ok t_cmp( t_read_file( "t/store/$session/klaus" ), 'value',
	  'value stored (Secret)' );

$res=GET( "/store?a=get;s=$session;k=klaus" );
ok t_cmp( $res->content, 'value', 'get stored value (Secret)' );
ok t_cmp( $res->code, 200, 'get returns code 200 (Secret)' );

$res=GET( "/store?a=get;s=$session;k=otto" );
ok t_cmp( $res->code, 404, 'get returns code 404 (Secret)' );

Apache::TestRequest::user_agent( reset=>1, keep_alive=>300 );
$res=GET( "/store?a=get;s=$session;k=klaus" );
sleep 3;
$res=GET( "/store?a=get;s=$session;k=klaus" );
ok t_cmp( $res->code, 200, 'no timeout yet (Secret)' );

sleep 3;
Apache::TestRequest::user_agent( reset=>1, keep_alive=>0 );
sleep 1;
ok t_cmp( -d "t/store/#$session", 1,
	  'session marked for deletion (renamed) (Secret)' );

$res=GET( "/store?a=get;s=$session;k=klaus" );
ok t_cmp( $res->code, 404, 'data not accessible (Secret)' );

sleep 2;
$res=GET( "/store?a=get;s=$session;k=klaus" ); # let cleanup() run once again
sleep 1;			# and give it time to accomplish the task
$res=GET( "/store?a=get;s=$session;k=klaus" );
ok t_cmp( $res->code, 404, 'session store deleted => NOT_FOUND (Secret)' );
ok t_cmp( -d "t/store/#$session", undef,
	  'session directory deleted (Secret)' );

Apache::TestRequest::user_agent( reset=>1 ); # close the kept alive connection
sleep 3;			# and give the server time to cleanup and
				# prevent a warning if t/store is removed
				# before the server has finished it's cleanup

# Local Variables: #
# mode: cperl #
# End: #

t/session/012storeclient.t  view on Meta::CPAN


$res=GET_BODY( "$session/bin/storeclient.pl" );
ok t_cmp( $res, '2', 'value read' );

$res=GET_BODY( "$session/TestSession__012storeclient?add" );
ok t_cmp( $res, '3', 'value incremented with modperl handler' );

$res=GET_BODY( "$session/TestSession__012storeclient" );
ok t_cmp( $res, '3', 'value read with modperl handler' );

Apache::TestRequest::user_agent( reset=>1, keep_alive=>0 );

sleep 3;

$res=GET_BODY( "/TestSession__012storeclient" ); # run cleanup
sleep 1;			# and give it time to complete

$res=GET_BODY( "$session/TestSession__012storeclient" );
ok t_cmp( $res, '<UNDEF>', 'value read after timeout' );

$res=GET_BODY( "$session/TestSession__012storeclient?add" );

t/session/012storeclient.t  view on Meta::CPAN


$res=GET_BODY( "$session/bin/storeclient.pl" );
ok t_cmp( $res, '2', 'value read (Secret)' );

$res=GET_BODY( "$session/TestSession__012storeclient?add" );
ok t_cmp( $res, '3', 'value incremented with modperl handler (Secret)' );

$res=GET_BODY( "$session/TestSession__012storeclient" );
ok t_cmp( $res, '3', 'value read with modperl handler (Secret)' );

Apache::TestRequest::user_agent( reset=>1, keep_alive=>0 );

sleep 3;

$res=GET_BODY( "/TestSession__012storeclient" ); # run cleanup
sleep 1;			# and give it time to complete

$res=GET_BODY( "$session/TestSession__012storeclient" );
ok t_cmp( $res, '<UNDEF>', 'value read after timeout (Secret)' );

$res=GET_BODY( "$session/TestSession__012storeclient?add" );



( run in 0.860 second using v1.01-cache-2.11-cpan-df04353d9ac )