Re: Application design patterns

2003-07-24 Thread Eric Sammer
Perrin Harkins wrote:
There are tutorials on the Template Toolkit site, a recent perl.com
article about TT and Class::DBI, and my article:
http://perl.apache.org/docs/tutorials/apps/scale_etoys/etoys.html
I read Perrin's case study awhile ago and it was excellent. Out of 
curiosity (and since most of my code written prior to reading said 
article looks identical in structure) where did you (Perrin) keep 
objects like your database handle (assuming DBI, but please correct 
otherwise) and any objects that could be reused (TT, XML parser objects, 
et al)?

I see a reference to a utility style class (ESR::Util, IIRC), but after 
rereading a number of articles and design pattern books, I'm reluctant 
to go with a handle holder object as I've done in the past. I use a 
configuration object that parses and holds all site config info (DBI 
dsn, user, pass, TT paths, etc.), when apache starts - a singleton style 
class. What I'd like is to have my model (as in MVC) objects reuse the 
process or maybe even server shared objects without doing any of these:

1. Using a singleton utility class
2. Needing to pass objects to model objects' new() in teh controllers
3. Instantiating the objects in the model classes themselves
I guess I could use a class to just act as a namespace to hold the 
objects and create them at server startup time and use a module like 
IPC::MM, File::Cache, or Cache::Mmap but that feels kludgy and offers no 
encapsulation for the objects themselves.

I'm sure I'm either overcomplicating the situation to some great 
extentent or the utility class is the way to go (combined with some 
caching / shared mem module). Is there some obvious pattern I've missed 
or should I just KISS?

Perrin - Have you ever considered revealing more about the Etoys project 
or just the concepts as you applied them? It would be nice to peek at 
some of the details. Or, is this an NDA situation or some such thing? 
Either way, great article.

Thanks in advance.
--
Eric Sammer
[EMAIL PROTECTED]
http://www.ineoconcepts.com


[MP2] Placing Apache::RequestRec Apache::RequestIO APR::Tableuse statements in startup.pl

2003-07-24 Thread Jamie Krasnoo
Will placing Apache::RequestRec  Apache::RequestIO  APR::Table in
startup.pl to load them up for multiple handlers have any bad side
effects? I noticed that when I load them via startup.pl the handlers
that use them don't complain that they don't have the use statements
within the module code and still work as normal.

Jamie Krasnoo



Re: [mp2] BEGIN blocks

2003-07-24 Thread Issac Goldstand
I'm not really sure what's going on...

I tried making a test module to see what was going on inside, which appeared
to function correctly.  However, the real module is still having troubles.
The database handle is opened ($dbh=DBI-connect...) in a BEGIN block in the
real module, but the connections don't seem to work when the server
originally loads, until I make a change in the file and Apache::Reload
reloads it (after which it works fine as long as the server's alive).

Here's the module and test results :

package MyTest;

use strict;
use warnings;
use Apache2;
use Apache::Const qw(-compile OK);
use carp qw(cluck);
#use vars qw($VAR);
our $VAR;
BEGIN {
warn (Calling BEGIN block);
warn (BEGIN: VAR is $VAR);
$VAR=HELLO;
warn (BEGIN: CHANGED VAR to $VAR);
}

warn (Interpreting module);
warn (VAR is $VAR);

sub handler {
my $r=shift;
$r-content_type('text/plain');
$r-print(VAR is $VAR);
return Apache::OK;
}

END {
warn (Calling END block);
warn (VAR is $VAR);
}

1;

(httpd.conf)
PerlModule MyTest;
Location /TEST
  SetHandler perl-script
  PerlResponseHandler MyTest
/Location

(error_log)
[Thu Jul 24 11:42:01 2003] [notice] Parent: Created child process 2896
calling begin at f:/you/web//YOU/Objects.pm line 17.
Calling BEGIN block at f:/you/web//MyTest.pm line 11.
Use of uninitialized value in concatenation (.) or string at
f:/you/web//MyTest.pm line 12.
BEGIN: VAR is  at f:/you/web//MyTest.pm line 12.
BEGIN: CHANGED VAR to HELLO at f:/you/web//MyTest.pm line 14.
Interpreting module at f:/you/web//MyTest.pm line 17.
VAR is HELLO at f:/you/web//MyTest.pm line 18.
[Thu Jul 24 11:42:07 2003] [notice] Child 2896: Child process is running
[Thu Jul 24 11:42:07 2003] [notice] Child 2896: Acquired the start mutex.
[Thu Jul 24 11:42:07 2003] [notice] Child 2896: Starting 250 worker threads.

(the you/objects.pm is the real module giving me trouble)

(output of http://localhost/TEST)
VAR is HELLOHere's the relevant parts (I hope) of my code (full code
available if needed):package YOU::ApacheApp;...use warnings;use CGI;use
DBI;...use YOU::Objects;...my $event=YOU::Event-new($i); #Should
connect to DB using $dbh..unless ($event-valid) {print ERROR
ACCESSING DB! $DB::Objects::VERSION
${YOU::ApacheApp::VERSION}/${YOU::Objects::VERSION}BR /; my
$dump=Dumper($event);$dump=~s/ /\nbsp;/mg;$dump=~s/\n/\BR \/\/mg;print
$dump}# $event-valid returns true if connected to DB(Objects.pm)package
YOU::Objects;use strict;use warnings;use DBI;use DB::Objects;use vars
qw($VERSION);our $dbh;BEGIN {$VERSION=0.01;my
$mysqldsn=DBI:mysql:database=...;host=...;mysql_compression=1;
$dbh=DBI-connect($mysqldsn,...,...) or die couldn't connect:
.DBI-errstr;}END {$dbh-disconnect();}...In this example, I get the
error message until Apache::Reload reloads the module, after which it works
fine.Any insight would be appreciated.  Issac- Original Message - 
From: Stas Bekman [EMAIL PROTECTED]
To: Issac Goldstand [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Sunday, July 20, 2003 10:21 PM
Subject: Re: [mp2] BEGIN blocks


 Issac Goldstand wrote:
  I seem to be having some trouble that I think may be associated with
BEGIN
  blocks.  To make sure I'm not jumping at shadows, could someone tell me
what
  the expected behavior of BEGIN blocks in use()d modules is?  How many
times
  are they called (during server startup and/or restarts of any type) and
  when?

 This is not documented yet for 2.0. I think it should be similar to 1.0.
BEGIN
 blocks are called when the module is loaded. What unusual behavior do you
see?


 __
 Stas BekmanJAm_pH -- Just Another mod_perl Hacker
 http://stason.org/ mod_perl Guide --- http://perl.apache.org
 mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
 http://modperlbook.org http://apache.org   http://ticketmaster.com





Re: [MP2] Placing Apache::RequestRec Apache::RequestIO APR::Tableuse statements in startup.pl

2003-07-24 Thread Stas Bekman
Jamie Krasnoo wrote:
Will placing Apache::RequestRec  Apache::RequestIO  APR::Table in
startup.pl to load them up for multiple handlers have any bad side
effects? I noticed that when I load them via startup.pl the handlers
that use them don't complain that they don't have the use statements
within the module code and still work as normal.
While this works for you, it's a bad practice. Why? Because other people using 
your code may not have these modules loaded from startup.pl.

__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: [MP2] Placing Apache::RequestRec Apache::RequestIO APR::Table use statements in startup.pl

2003-07-24 Thread Jamie Krasnoo


On Thu, 2003-07-24 at 02:15, Stas Bekman wrote:
 Jamie Krasnoo wrote:
  Will placing Apache::RequestRec  Apache::RequestIO  APR::Table in
  startup.pl to load them up for multiple handlers have any bad side
  effects? I noticed that when I load them via startup.pl the handlers
  that use them don't complain that they don't have the use statements
  within the module code and still work as normal.
 
 While this works for you, it's a bad practice. Why? Because other people using 
 your code may not have these modules loaded from startup.pl.
 

Won't loading them for every handler put an instance of it in
memory over and over again though? Or will Perl realize that
its already loaded and not load it again? How would this behave
in MPM threadpool?

Jamie



Re: [MP2] Placing Apache::RequestRec Apache::RequestIO APR::Tableuse statements in startup.pl

2003-07-24 Thread Issac Goldstand
It will work.  Just be careful - if you distribute this module, the people
who use it may not include these modules in their startup.pl, and if you
discontinue usage of this module, you may end up with extra modules in
memory which aren't needed.

  Issac

- Original Message - 
From: Jamie Krasnoo [EMAIL PROTECTED]
To: Modperl list [EMAIL PROTECTED]
Sent: Thursday, July 24, 2003 11:32 AM
Subject: [MP2] Placing Apache::RequestRec  Apache::RequestIO 
APR::Tableuse statements in startup.pl


 Will placing Apache::RequestRec  Apache::RequestIO  APR::Table in
 startup.pl to load them up for multiple handlers have any bad side
 effects? I noticed that when I load them via startup.pl the handlers
 that use them don't complain that they don't have the use statements
 within the module code and still work as normal.

 Jamie Krasnoo





[mp1] Safe segfaults with mp1

2003-07-24 Thread Joel Palmius
This works, separate file /tmp/test.pl:

  use Safe;

  my($compartment) = new Safe;
  $compartment-permit(qw(:browse));
  $compartment-reval(print \gnu\n\;);

  if($@)
  {
die $@;
  }

  print \n\n;

(Script prints gnu)

This does not work, in perl-handler Handler.pm:

  [...]

  use Safe;

  sub handler
  {
my $r = shift;

return DECLINED unless $r-content_type() eq 'text/html';

[...]

print Content-type: text/plain\n\n;
 
my($compartment) = new Safe;
$compartment-permit(qw(:browse));
$compartment-reval(print \gnu\n\;);

if($@)
{
  die $@;
}

[...]

Request results in segfault:

  [Thu Jul 24 12:59:56 2003] [notice] child pid 3003 exit signal 
  Segmentation fault (11)

If I comment out $compartment-reval(), then the process does not 
segfault. 

Since Safe works outside mod_perl, I'm guessing there's something with the 
mod_perl environment that messes things up. 

I have run the rest of the setup for several months now without noticing
any other ill effects, so I don't think it is a bad installation of
something. Setup is:

  Gentoo linux
  perl 5.8.0
  apache 1.3.27
  mod_perl 1.27

Ideas anyone?

  // Joel


how to extend CPAN module?

2003-07-24 Thread ???? ????????
Hi, 

How to correctly extend CPAN module, perldoc only explains how to create
CPAN module from scratch,
but what about extending? I want to add some Foo::My.pm to existing Foo
bundle.
Which Makefile.PLs should patched? all? just one in subsdirectory 'mod'?
Any link?

Thx!

-vlad





Re: [MP2] Placing Apache::RequestRec Apache::RequestIO APR::Tableuse statements in startup.pl

2003-07-24 Thread Stas Bekman
Jamie Krasnoo wrote:
On Thu, 2003-07-24 at 02:15, Stas Bekman wrote:

Jamie Krasnoo wrote:

Will placing Apache::RequestRec  Apache::RequestIO  APR::Table in
startup.pl to load them up for multiple handlers have any bad side
effects? I noticed that when I load them via startup.pl the handlers
that use them don't complain that they don't have the use statements
within the module code and still work as normal.
While this works for you, it's a bad practice. Why? Because other people using 
your code may not have these modules loaded from startup.pl.



Won't loading them for every handler put an instance of it in
memory over and over again though? Or will Perl realize that
its already loaded and not load it again? How would this behave
in MPM threadpool?
perldoc -f require

It gets loaded only once. Why should be any difference with threadpool. 
Application-wise it's all transparent.



__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: how to extend CPAN module?

2003-07-24 Thread Stas Bekman
  wrote:
Hi, 

How to correctly extend CPAN module, perldoc only explains how to create
CPAN module from scratch,
but what about extending? I want to add some Foo::My.pm to existing Foo
bundle.
Which Makefile.PLs should patched? all? just one in subsdirectory 'mod'?
Any link?
Please ask only mod_perl specific question at the mod_perl list. There are 
plenty other lists and discussion forums that can answer generic perl 
questions. Good starting point are:

http://perl.apache.org/docs/offsite/other.html#Perl
http://lists.perl.org/.
__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: templating system opinions (axkit?)

2003-07-24 Thread Jean-Michel Hiver
 I've been considering using a template system for an app that I'm
 working, but decided against it as the designers who would be putting
 the actual pages together (look n feel) use Adobe GoLive which does
 'bad things' to non-html stuff (at least in my experience).

I know everybody's defending their fave templating system... I guess I
can't resist: I have to jump in and defend my baby :)

So why is Petal better than anything else?

First of all, it is an implementation of TAL. TAL is a very clever open
specification for WYSIWYG-friendly templates written by the Zope people.
TAL has three python implementations, one PHP implementation and two
Perl implementations (see Petal::CodePerl). I believe it will become the
standard with which template designers will want to work with.

You can open Petal XHTML templates into GoLive, Dreamweaver, Mozilla,
and they will look fine. Petal is basically an implementation of TAL, an
open specification designed by the ZOPE people to be WYSIWYG-compatible
and which has been extensively tested with all kinds of WYSIWYG-ish
software.

Because Petal templates have to be well-formed XML, it is safe (and in
fact recommended!) to send them through HTML tidy and check for
well-formness with xmllint.

Petal is not limited to XHTML. You can template any kind of XML. RSS,
RDF, SVG, WML... you name it!

It has good support for Unicode / multi-lingual applications and
character set encoding (well, provided you use Perl 5.8).

It is quite fast (templates are turned into subroutines which are cached
on disk and in memory). It has been designed to be very mod_perl
friendly.

Petal has an active community and a mailing list, it is stable and has
already been successfully used in different projects by different
people.

This TAL spec that I've shamelessly stolen / implemented is a really
cool idea.  You should really give it a try in between two Template
Toolkit driven projects :)

Cheers,
-- 
Building a better web - http://www.mkdoc.com/
-
Jean-Michel Hiver
[EMAIL PROTECTED]  - +44 (0)114 255 8097
Homepage: http://www.webmatrix.net/


Re: Application design patterns

2003-07-24 Thread Aaron Ross
Hi Eric,
 
 class. What I'd like is to have my model (as in MVC) objects reuse the 
 process or maybe even server shared objects without doing any of these:
 
 1. Using a singleton utility class
 2. Needing to pass objects to model objects' new() in teh controllers
 3. Instantiating the objects in the model classes themselves

I'm not sure if this violates 3 (the models classes have to know what
resources they need, so i am not sure what wouldn't), but could you use
a singleton for the resource and a factory to access it? The model
classes call a static factory method that handles the configuration,
cache, etc...

This solves the problem of having configuration and resource allocation
code in your model objects. It does mean that you have to write factory
classes for your resources, but they ought to be quite simple. 

package MyModel::SomeObject;

...

sub doSomething {
  ...
  my $dbiHandle = MyDBIHandleFactory-getHandle();
  ...
}

1;

package MyDBIHandleFactory;

sub getHandle {
   if (defined $handle) {
return $handle # implement as singleton
   }
   ... read config or something ...
   $handle = DBI-connect(...);
}

1;

hth, aaron




Re: templating system opinions (axkit?)

2003-07-24 Thread Jean-Michel Hiver
 I know everybody's defending their fave templating system... I guess I
 can't resist: I have to jump in and defend my baby :)
 
 So why is Petal better than anything else?

Oops, I got a bit carried away...

As a side note, Petal is probably not better than anything else, but
different. If you're templating XML / XHTML, it'll do a really good
job. If you're templating text, use something else :)

Cheers,
-- 
Building a better web - http://www.mkdoc.com/
-
Jean-Michel Hiver
[EMAIL PROTECTED]  - +44 (0)114 255 8097
Homepage: http://www.webmatrix.net/


Re: templating system opinions (axkit?)

2003-07-24 Thread Jeff AA
 - Original Message - 
 From: Jean-Michel Hiver [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Sent: Thursday, July 24, 2003 1:46 PM


 First of all, it is an implementation of TAL. TAL is a very clever open
 specification for WYSIWYG-friendly templates written by the Zope people.

Do you have a URL for further reading on TAL?


 Petal has an active community and a mailing list, 

Ditto - a URL would be interesting!


Regards
Jeff


Re: Application design patterns

2003-07-24 Thread Frank Wiles
On Thu, 24 Jul 2003 02:18:17 -0400
Eric Sammer [EMAIL PROTECTED] wrote:

 Perrin - Have you ever considered revealing more about the Etoys
 project or just the concepts as you applied them? It would be nice to
 peek at some of the details. Or, is this an NDA situation or some such
 thing? Either way, great article.

  I too would like to would like to have a better understanding of how
  MVC can be applied to mod_perl.  Maybe even HelloWorld sized example
  showing how all of the different components interact? 

 -
   Frank Wiles [EMAIL PROTECTED]
   http://frank.wiles.org
 -



Re: Application design patterns

2003-07-24 Thread Chris Winters
Frank Wiles wrote:
  I too would like to would like to have a better understanding of how
  MVC can be applied to mod_perl.  Maybe even HelloWorld sized example
  showing how all of the different components interact? 
No examples, but Andy Wardley sent a great email to the Template 
Toolkit mailing list a few months ago about MVC and web apps:

http://lists.ourshack.com/pipermail/templates/2002-November/003974.html

Also no examples but possibly helpful: I place the OpenInteract2 
components in an MVC context (will be in next beta):

http://openinteract.sourceforge.net/docs/oi2-snapshot/OpenInteract2/Manual/Architecture.shtml

Chris

--
Chris Winters ([EMAIL PROTECTED])
Building enterprise-capable snack solutions since 1988.


RE: templating system opinions (axkit?)

2003-07-24 Thread Kitch, David
Do you have a URL for further reading on TAL?

I found one:
http://www.zope.org/Wikis/DevSite/Projects/ZPT/TAL

Regards,
Kitch


no_cache(1) and still cached?

2003-07-24 Thread Frank Maas
Hi,

Recently I found some strange behaviour of the caching-functionality of
Apache. I had configured one httpd as caching proxy and a second one
creating the pages. Two kind of pages are created: dynamic ones (with
no_cache(1)) and static ones (with an expiry set to some minutes or
hours).
What I found was that sometimes users got served 'cached' dynamic pages.
Although the server should not cache the page it looked like this happened
whenever two requests were received at (nearly) the same time by the server.
Has anyone of you experienced this before and does this harm current ideas
about caching proxies?

--Frank



Re: Application design patterns

2003-07-24 Thread Stathy G. Touloumis
## NOTE : Very simple example which for the most part
## will seem like overkill and it is.  Typically the complexity
## of the application can be reduced by breaking it into the
## components below.  It makes for easier maintenance.
## Model responsible for data retrieval not formatting.
##In many architectures data will be retrieved from
## some sort of data storage (rdbms).
#--- MODEL ---
package My::Model
sub title { return 'MVC Hello World Example'; }
sub new { return bless {}, shift };
sub enter_room { return 'Hello'; }
sub leave_room { return 'Bye'; }
## Responisble for presentation/formatting of data not
## modifying/retrieving data.
#--- VIEW ---
package My::View
sub new { return bless {}, shift };
sub output {
  my $p = { @_ };
  print HTML;
html
head
title$p-{'title'}/title
/head
body
h1$p-{'data'}/h1
/html
HTML
}
## Handles user actions/events ... retrieve data through
## model layer and present data through view layer.
#--- CONTROLLER 
## Depending on the application (CGI, etc.) initialization code here

my $m = My::Model-new;
my $v = My::View-new;
my $data = $m-leave_room;

if ( $input == 'enter_room' ) {
$data = $m-enter_room;
}
$v-output(
title= $v-title,
data= $data,
);

  I too would like to would like to have a better understanding of how
  MVC can be applied to mod_perl.  Maybe even HelloWorld sized example
  showing how all of the different components interact?



Re: [mp1] Safe segfaults with mp1

2003-07-24 Thread Stas Bekman
Joel Palmius wrote:
This works, separate file /tmp/test.pl:

  use Safe;

  my($compartment) = new Safe;
  $compartment-permit(qw(:browse));
  $compartment-reval(print \gnu\n\;);
  if($@)
  {
die $@;
  }
  print \n\n;

(Script prints gnu)

This does not work, in perl-handler Handler.pm:

  [...]

  use Safe;

  sub handler
  {
my $r = shift;
return DECLINED unless $r-content_type() eq 'text/html';

[...]

print Content-type: text/plain\n\n;
 
my($compartment) = new Safe;
$compartment-permit(qw(:browse));
$compartment-reval(print \gnu\n\;);

if($@)
{
  die $@;
}
[...]

Request results in segfault:

  [Thu Jul 24 12:59:56 2003] [notice] child pid 3003 exit signal 
  Segmentation fault (11)

If I comment out $compartment-reval(), then the process does not 
segfault. 

Since Safe works outside mod_perl, I'm guessing there's something with the 
mod_perl environment that messes things up. 

I have run the rest of the setup for several months now without noticing
any other ill effects, so I don't think it is a bad installation of
something. Setup is:
  Gentoo linux
  perl 5.8.0
  apache 1.3.27
  mod_perl 1.27
Ideas anyone?
Joel, I have reproduced the segfault using your test script.

It's handy to have p5p people sitting next to you. Just asked this question 
Tim Bunce, and he replied:

  Safe is a failed experiment. It works only for several cases. TIEHANDLE is
  not one of them [print under mod_perl uses a tied STDOUT]. Do not use it if
  it doesn't work for you.
I'm supposed to ask Dan Sugalsky whether perl6 will have this functionality 
designed from the ground up.

We could prevent the segfault in mod_perl, but you still won't be able to use 
Safe under it. So IMHO it's not worth the slowdown to do extra checks.

Should probably add it to the troubleshooting section.

__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: [mp1] Safe segfaults with mp1

2003-07-24 Thread Stas Bekman
Stas Bekman wrote:
Joel Palmius wrote:


  use Safe;

  my($compartment) = new Safe;
  $compartment-permit(qw(:browse));
  $compartment-reval(print \gnu\n\;);
[...]

Request results in segfault:

  [Thu Jul 24 12:59:56 2003] [notice] child pid 3003 exit signal   
Segmentation fault (11)
[...]

Joel, I have reproduced the segfault using your test script.

It's handy to have p5p people sitting next to you. Just asked this 
question Tim Bunce, and he replied:

  Safe is a failed experiment. It works only for several cases. 
TIEHANDLE is
  not one of them [print under mod_perl uses a tied STDOUT]. Do not use 
it if
  it doesn't work for you.

I'm supposed to ask Dan Sugalsky whether perl6 will have this 
functionality designed from the ground up.

We could prevent the segfault in mod_perl, but you still won't be able 
to use Safe under it. So IMHO it's not worth the slowdown to do extra 
checks.

Should probably add it to the troubleshooting section.
And here is the patch that prevents the segfault. I'm not sure whether it 
should go in. I have attached it as well, since the original had \t in it and 
it'll be certainly mangled.

Index: src/modules/perl/Apache.xs
===
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.128
diff -u -r1.128 Apache.xs
--- src/modules/perl/Apache.xs  6 Jul 2003 04:51:20 -   1.128
+++ src/modules/perl/Apache.xs  24 Jul 2003 14:38:33 -
@@ -1134,7 +1134,9 @@
sv_setiv(sendh, 0);
 }
 else {
-   CV *cv = GvCV(gv_fetchpv(Apache::write_client, FALSE, SVt_PVCV));
+/* should exist already */
+CV *cv = GvCV(gv_fetchpv(Apache::write_client, GV_ADDWARN, SVt_PVCV));
+if(!cv) croak(can't find Apache::write_client, are you using Safe.pm?);
soft_timeout(mod_perl: Apache-print, r);
PUSHMARK(mark);
 #ifdef PERL_OBJECT


__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com
Index: src/modules/perl/Apache.xs
===
RCS file: /home/cvs/modperl/src/modules/perl/Apache.xs,v
retrieving revision 1.128
diff -u -r1.128 Apache.xs
--- src/modules/perl/Apache.xs  6 Jul 2003 04:51:20 -   1.128
+++ src/modules/perl/Apache.xs  24 Jul 2003 14:45:16 -
@@ -1134,7 +1134,9 @@
sv_setiv(sendh, 0);
 }
 else {
-   CV *cv = GvCV(gv_fetchpv(Apache::write_client, FALSE, SVt_PVCV));
+/* should exist already */
+CV *cv = GvCV(gv_fetchpv(Apache::write_client, GV_ADDWARN, SVt_PVCV));
+if(!cv) croak(can't find Apache::write_client, are you using Safe.pm?);
soft_timeout(mod_perl: Apache-print, r);
PUSHMARK(mark);
 #ifdef PERL_OBJECT


RE: Templating system opinions (CGI::Application in connection with either HTML::Template or Template::Toolkit)

2003-07-24 Thread Jesse Erlbaum
Hey Randal --

 Maybe because it competes with OpenInteract, which is far 
 more established.

I don't really think OI and CGI-App are in competition at all.  OI
attempts to be a uber-framework, a la Mason -- or maybe more like
ColdFusion or WebObjects.CGI::Application just focuses on web
application state management.

CGI::Application doesn't try to bolt on anything else.  The developer
can choose their favorite modules for templating system, database
interface, object persistence, session management, etc.  CGI-App is
specifically made to allow developers to choose from the best available
CPAN libraries, rather than to pre-select for them.

You could probably use CGI::Application to implement part of
OpenInteract, but you wouldn't use one in lieu of the other.  They're
not really comparable at all.

TTYL,

-Jesse-


--

  Jesse Erlbaum
  The Erlbaum Group
  [EMAIL PROTECTED]
  Phone: 212-684-6161
  Fax: 212-684-6226





Re: [mp1] Safe segfaults with mp1

2003-07-24 Thread Joel Palmius
Ah, well, after a five hours of experimentation I thought up a working
workaround anyway.

This works with an unpatched version of mp1 ($substr is any perl code 
fetched from external source):

  my(@ops) = split(/\x0a/,$substr);
  my($cell,$reval);

  foreach $cell (@ops)
  {
$cell =~ s/^[\x09\ ]+//g;
$cell =~ s/^print\ /\$output\ \.\=\ /;
if($cell)
{
  $reval .= $cell . \n;
}
  }

  my($output);

  $reval .= \$output;\n;

  my($compartment) = new Safe(Tempo);
  $compartment-permit(qw(:browse));
  $output = $compartment-reval($reval);
  if($@)
  {
$self-{ERROR} = gettext(Security exception:  . $@);
$self-{ERRORCODE} = 99;
  }

  print $output;

I just replace all print statements with $output .= , and then make 
sure that the reval results in the final contents of $output, which I then 
print outside the reval().

Works fine now. So far nothing else has crashed, although I'm somewhat
suspicious of a number of rather random events in the code. I'm almost
certain this is me having messed up something else though.

However, if I'm not supposed to use Safe in conjunction with mp, what *am* 
I supposed to use? 

I might be possible to convince to write a version of Safe specifically
for mp1, although I expect I shall have to experience more problems with
the existing Safe code to be bothered. :-)

  // Joel


On Thu, 24 Jul 2003, Stas Bekman wrote:

 Joel, I have reproduced the segfault using your test script.
 
 It's handy to have p5p people sitting next to you. Just asked this question 
 Tim Bunce, and he replied:
 
Safe is a failed experiment. It works only for several cases. TIEHANDLE is
not one of them [print under mod_perl uses a tied STDOUT]. Do not use it if
it doesn't work for you.
 
 I'm supposed to ask Dan Sugalsky whether perl6 will have this functionality 
 designed from the ground up.
 
 We could prevent the segfault in mod_perl, but you still won't be able to use 
 Safe under it. So IMHO it's not worth the slowdown to do extra checks.
 
 Should probably add it to the troubleshooting section.
 
 __
 Stas BekmanJAm_pH -- Just Another mod_perl Hacker
 http://stason.org/ mod_perl Guide --- http://perl.apache.org
 mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
 http://modperlbook.org http://apache.org   http://ticketmaster.com
 
 


Mixing Apache::Filter with other mods like mod_php

2003-07-24 Thread Crispin Bivans

Situation: I have a custom templating package that will lookup translation texts based 
off of keywords so we can use 1 html file for all 8-9 languages. I've made it part of 
an Apache::Filter list that also run's Apache::SSI so that any server side includes in 
the html file will also get run. There is also some mod_php code (a php require line 
that pulls in a different page graphic everytime they refresh the page) that I need to 
also 'run' as part of the web page.

When I have this setup, it fails to run the php code... If I include custom tests to 
look for the php coding and run a subrequest of it using $r-load_file() then it takes 
over the entire request and just displays the results of the php coding. I'd like to 
just include the output of the php coding as part of my reply where it belongs. 

How can I make this work?




Re: templating system opinions (axkit?)

2003-07-24 Thread Jean-Michel Hiver
  First of all, it is an implementation of TAL. TAL is a very clever open
  specification for WYSIWYG-friendly templates written by the Zope people.
 
 Do you have a URL for further reading on TAL?

Yep.

http://www.zope.org/Wikis/DevSite/Projects/ZPT/TAL


  Petal has an active community and a mailing list, 
 
 Ditto - a URL would be interesting!

Sure :)

http://lists.webarch.co.uk/mailman/listinfo/petal


Cheers,
-- 
Building a better web - http://www.mkdoc.com/
-
Jean-Michel Hiver
[EMAIL PROTECTED]  - +44 (0)114 255 8097
Homepage: http://www.webmatrix.net/


Re: Mixing Apache::Filter with other mods like mod_php

2003-07-24 Thread Perrin Harkins
On Thu, 2003-07-24 at 12:48, Crispin Bivans wrote:
 Situation: I have a custom templating package that will lookup translation texts 
 based off of keywords so we can use 1 html file for all 8-9 languages. I've made it 
 part of an Apache::Filter list that also run's Apache::SSI so that any server side 
 includes in the html file will also get run. There is also some mod_php code (a php 
 require line that pulls in a different page graphic everytime they refresh the page) 
 that I need to also 'run' as part of the web page.
[...]
 How can I make this work?

You can't in apache 1.x.  In apache 2.x there is the ability to filter
content in this way, but the filtering done in 1.x by Apache::Filter is
really just at the mod_perl level so it can't deal with additional
apache modules.  The only way to actually get the PHP code to run is to
make a separate request with something like LWP back to the server to
run a PHP page, or maybe run it through the separate PHP executable with
a system call.

- Perrin



Re: no_cache(1) and still cached?

2003-07-24 Thread Perrin Harkins
On Thu, 2003-07-24 at 09:55, Frank Maas wrote:
 What I found was that sometimes users got served 'cached' dynamic pages.
 Although the server should not cache the page it looked like this happened
 whenever two requests were received at (nearly) the same time by the server.

What happens if you use Expires headers instead of the no_cache() stuff?

- Perrin


Re: Application design patterns

2003-07-24 Thread Perrin Harkins
On Thu, 2003-07-24 at 09:20, Frank Wiles wrote:
   I too would like to would like to have a better understanding of how
   MVC can be applied to mod_perl.  Maybe even HelloWorld sized example
   showing how all of the different components interact? 

There's one of those in my original article.  I'm not really sure what
to add to it beyond what's there.  You can also read previous
discussions on this from the mailing list archives and the docs for
CGI::Application, Apache::PageKit and OpenInteract which all talk about
it to some degree.

If you can ask something more specific, I'll try to answer.

- Perrin


Re: [MP2] Placing Apache::RequestRec Apache::RequestIO APR::Table use statements in startup.pl

2003-07-24 Thread Perrin Harkins
On Thu, 2003-07-24 at 04:32, Jamie Krasnoo wrote:
 Will placing Apache::RequestRec  Apache::RequestIO  APR::Table in
 startup.pl to load them up for multiple handlers have any bad side
 effects? I noticed that when I load them via startup.pl the handlers
 that use them don't complain that they don't have the use statements
 within the module code and still work as normal.

I like to put use() statements for all required modules in each module
that needs them.  It's good documentation.  When you tune your system
for performance, you will put all of these in startup.pl to improve
shared memory, but there's no need to take them out of the other
modules: use() staments for modules that have already been loaded simply
skip the require() part and run the import().

- Perrin


Re: Application design patterns

2003-07-24 Thread Eric Sammer
Aaron Ross wrote:
Hi Eric,

class. What I'd like is to have my model (as in MVC) objects reuse the 
process or maybe even server shared objects without doing any of these:

1. Using a singleton utility class
2. Needing to pass objects to model objects' new() in teh controllers
3. Instantiating the objects in the model classes themselves
I'm not sure if this violates 3 (the models classes have to know what
resources they need, so i am not sure what wouldn't), but could you use
a singleton for the resource and a factory to access it? The model
classes call a static factory method that handles the configuration,
cache, etc...
This is what I'm thinking I'll do. It seems to be the most natural in 
this case. I was reading this paper by Andy Wardly 
http://www.template-toolkit.org/tpc5/camelot/index.html which has a 
collection of resource classes that seem to act in a similar method at 
some level (providing a resource with a class that could be implemented 
as a singleton).

This solves the problem of having configuration and resource allocation
code in your model objects. It does mean that you have to write factory
classes for your resources, but they ought to be quite simple. 
Writing factory methods compared to littering code with instantiation of 
objects all objects are going to need lends itself to an easy and 
obvious first choice. ...For me, at least. ;)

I've done a fair amount of Objective-C (Mac OS X Cocoa and Openstep) and 
there's a number of classes that work in a similar fashion - simple, 
clean, and functional. The reason I like it is because I don't need to 
worry about passing stuff around - just get a static instance and go to 
town. (For those interested or in the know, I'm talking about 
NSNotificationCenter, NSFileManager, and other similar classes).

Thanks for the input!

--
Eric Sammer
[EMAIL PROTECTED]
http://www.ineoconcepts.com


Re: Application design patterns

2003-07-24 Thread Perrin Harkins
On Thu, 2003-07-24 at 02:18, Eric Sammer wrote:
 where did you (Perrin) keep 
 objects like your database handle (assuming DBI, but please correct 
 otherwise) and any objects that could be reused (TT, XML parser objects, 
 et al)?

People seem to ask about this frequently, but I don't think we did
anything especially interesting there.  We just had a simple class full
of accessors for these resources that would call factory methods the
first time and then cache the result as appropriate.

For example, to get a DBI handle you would call something like this:

sub get_dbh {
my $r = Apache-request();
my $dbh = $r-pnotes('ESF_DBH');
if (!$dbh) {
$dbh = ESF::Service::DB-new();
$r-pnotes('ESF_DBH', $dbh);
}
return $dbh;
}

This caches the database handle for the rest of the request (one
Apache::DBI ping per request should be enough).

For the Template Toolkit object we want to cache it for the life of the
process, so it would be something like this:

use vars qw($Cached_Template_Object);

sub get_template {
if (!defined $Cached_Template_Object) {
$Cached_Template_Object = Template-new();
}
return $Cached_Template_Object;
}

We also did things in there like setting the include path for the
current request, but you get the idea.  These are all class methods in
the ESF::Util class.

 I see a reference to a utility style class (ESR::Util, IIRC), but after 
 rereading a number of articles and design pattern books, I'm reluctant 
 to go with a handle holder object as I've done in the past.

Gang of Four got you spooked?  If you have something that works and
doesn't cause problems elsewhere in your code, don't fret about it.

 What I'd like is to have my model (as in MVC) objects reuse the 
 process or maybe even server shared objects without doing any of these:
 
 1. Using a singleton utility class
 2. Needing to pass objects to model objects' new() in teh controllers
 3. Instantiating the objects in the model classes themselves

All of those sound legit to me, as long as you don't duplicate code
between the objects.  I would choose #1, personally.

 I guess I could use a class to just act as a namespace to hold the 
 objects and create them at server startup time and use a module like 
 IPC::MM, File::Cache, or Cache::Mmap but that feels kludgy and offers no 
 encapsulation for the objects themselves.

No, you can't share things like this between processes.  Things with XS
code, open sockets, filehandles, etc. are not shareable.

I think the way we did it in the above code (don't fetch it until it's
asked for and then cache it as long as you safely can) is a good
approach, but you could refine it by having it set up some things in the
child init hook.

 Perrin - Have you ever considered revealing more about the Etoys project 
 or just the concepts as you applied them? It would be nice to peek at 
 some of the details. Or, is this an NDA situation or some such thing? 

Well, I don't have permission to go posting big chunks of code, but in
terms of the generally applicable ideas, I think the article covered
most of it.  The rest has to do with database work and patterns for
building model objects, and I hope to cover that in the article version
of the talk I gave about object-relational mapping tools at this year's
Perl Conference.

The biggest thing the article didn't cover is the ideas used by the guys
coding the more interactive parts of the application to express the
state machine implemented by each of their modules in a declarative data
structure.  This was largely invented by Adam Sussman, who is at
TicketMaster now.  It was similar to what you see in CGI::Application
and some of the other frameworks.

- Perrin


Advice sought for learning mod_perl (2 or 1)

2003-07-24 Thread Robert Lee
Hi everyone,

 I am new to Apache/mod_perl and everything else. I bought a fairly good 
book on Apache/mysql/mod_perl. Unfortunately, it is based on the Apache 1 
server and mod_perl1. In doing so, it is using the Apache::Request module 
which has not been ported to mod_perl2 yet.

 Several questions come to mind:

 Q1: Is there a similar module to Apache::Request? Similar to syntax that 
is.

 Q2: Any real benefits to working on the latest and greatest? Or should I 
go to the older versions?

Yes, I realize that for Q2, I may want to simply go with the more stable 
versions of the Apache server and mod_perl as I am just learning, but I 
would like to hear some opinions. Thanks.

Robert

FYI: OS - RH v8.0
 Apache - v2.45
 mod_perl - 1.99.09
 perl - v5.8
_
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.  
http://join.msn.com/?page=features/virus



Re: Application design patterns

2003-07-24 Thread Eric Sammer
Perrin Harkins wrote:
On Thu, 2003-07-24 at 02:18, Eric Sammer wrote:

where did you (Perrin) keep 
objects like your database handle (assuming DBI, but please correct 
otherwise) and any objects that could be reused (TT, XML parser objects, 
et al)?
People seem to ask about this frequently, but I don't think we did
anything especially interesting there.  We just had a simple class full
of accessors for these resources that would call factory methods the
first time and then cache the result as appropriate.
Sorry to be so cliche / predictable. ;)

This is what I'm sure will wind up happening. I think what I'm looking 
for will require this kind of framework.

This caches the database handle for the rest of the request (one
Apache::DBI ping per request should be enough).
Maybe a stupid question, but what would be the functional difference 
between dumping the object after each request like you say and using the 
same method as you describe for the TT object below? I ask because I'm 
currently treating both objects the same way in two or three of my 
larger applications. I would assume this is to catch premature database 
shutdown or network trouble between an app server and database (cluster) 
on a request by request basis? Is this a performance related choice or 
an Apache::DBI best practices thing?

For the Template Toolkit object we want to cache it for the life of the
process, so it would be something like this:
Right. This is what I currently do.

I see a reference to a utility style class (ESR::Util, IIRC), but after 
rereading a number of articles and design pattern books, I'm reluctant 
to go with a handle holder object as I've done in the past.
Gang of Four got you spooked?  If you have something that works and
doesn't cause problems elsewhere in your code, don't fret about it.
Quite true. I think when starting any new large application, as I am 
now, I like to reevaluate my current design methods and look at anything 
I might have been able to do better and do it - a bad (or good) habit.

He who feels he got it right in the past never looks for a better way to 
do it in the future and, thus, stunts all learning and growth... or some 
 such idealistic babble. ;)

That said, I think what I'm learning here is that the uncomfortability 
with this design method is more in my head than tangible.

What I'd like is to have my model (as in MVC) objects reuse the 
process or maybe even server shared objects without doing any of these:

1. Using a singleton utility class
2. Needing to pass objects to model objects' new() in teh controllers
3. Instantiating the objects in the model classes themselves
All of those sound legit to me, as long as you don't duplicate code
between the objects.  I would choose #1, personally.
Yea... that seems to be the ticket, so to speak.

I guess I could use a class to just act as a namespace to hold the 
objects and create them at server startup time and use a module like 
IPC::MM, File::Cache, or Cache::Mmap but that feels kludgy and offers no 
encapsulation for the objects themselves.
No, you can't share things like this between processes.  Things with XS
code, open sockets, filehandles, etc. are not shareable.
And now that you mention it, it seems so obvious. $Deity only knows what 
I was thinking...

Perrin - Have you ever considered revealing more about the Etoys project 
or just the concepts as you applied them? It would be nice to peek at 
some of the details. Or, is this an NDA situation or some such thing? 
Well, I don't have permission to go posting big chunks of code, but in
terms of the generally applicable ideas, I think the article covered
most of it.  The rest has to do with database work and patterns for
building model objects, and I hope to cover that in the article version
of the talk I gave about object-relational mapping tools at this year's
Perl Conference.
Is this past tense and if so, is the article up somewhere? Just curious...

The biggest thing the article didn't cover is the ideas used by the guys
coding the more interactive parts of the application to express the
state machine implemented by each of their modules in a declarative data
structure.  This was largely invented by Adam Sussman, who is at
TicketMaster now.  It was similar to what you see in CGI::Application
and some of the other frameworks.
Hm... that is interesting as well. I've been poking at the internals of 
  a lot of the frameworks out there and there are some fantastic 
concepts (Chris Winters' OI comes to mind). Or, there is the distinct 
possibility that I'm overly obsessed with architecture; that shouldn't 
be dismissed either... ;)

Thanks for all your input and the great article(s).
--
Eric Sammer
[EMAIL PROTECTED]
http://www.ineoconcepts.com


Re: Advice sought for learning mod_perl (2 or 1)

2003-07-24 Thread Ged Haywood
Hello there,

On Thu, 24 Jul 2003, Robert Lee wrote:

 I am new to Apache/mod_perl and everything else.

We're all still learning...

 I bought a fairly good  book on Apache/mysql/mod_perl.

There are others, see the mod_perl web site:

http://perl.apache.org

 Unfortunately, it is based on the Apache 1 server and mod_perl1.

That's not too bad, there are lots of similarities.

   Q1: Is there a similar module to Apache::Request?

Depends what you want to do, but not really.  Care to try porting it?

   Q2: Any real benefits to working on the latest and greatest? Or
 should I go to the older versions?

Depends what you want to do... :)  If you are interested in learning
about it and you don't have a project that you have to put on a live
Webserver in a couple of months' time, I'd say stay with mp2 and watch
it evolve.  Maybe get involved in some of the development.  I wouldn't
consider mp2 for production use yet because of that evolution process
if for no other reason, but if you don't have the commercial pressures
then it doesn't matter so much and there's no point your spending a
lot of time learning about something if it's going to be more-or-less
history by the time you need to use it seriously.

 I realize that for Q2, I may want to simply go with the more stable 
 versions of the Apache server and mod_perl as I am just learning

For your education it's probably worth your while learning how to get
the latest CVS versions, at least of mod_perl.  The latest versions of
Apache2 and mod_perl2 will be quite stable enough for you to use to
learn about them.  Now your browsers on the other hand...

73,
Ged.



Test unexpectedly succeeded during make test

2003-07-24 Thread Laus, Ryan J.
Hello everyone,

Hopefully someone can help me out, I am having problems during the make
test when trying to compile mod_perl-1.99_09.  Even though a make
install will work fine without any errors, I am not sure if it is a
good idea to install if the make test fails.

Here is my system background info.
OS: AIX 4.3.3 w/the latest maintenance level
Perl: 5.8.0,  via Binary installation
Apache: 2.0.47
GCC: 3.3

During the make test I receive the following error:

modperl/request_rec_tie_apiok
1/3 unexpectedly succeeded
modperl/sameinterp.ok
modperl/setauthok
modperl/subenv.ok
modperl/taint..ok
modules/cgiskipped
all skipped: cannot find module 'LWP'
modules/cgiupload..skipped
all skipped: cannot find module 'LWP'
modules/includeok
modules/include2...ok
preconnection/note.ok
protocol/echo..ok
protocol/echo_filter...ok
Failed Test Stat Wstat Total Fail  Failed  List of Failed

---
filter/in_bbs_msg.t  255 65280??   ??   %  ??
 (1 subtest UNEXPECTEDLY SUCCEEDED), 7 tests skipped.
*** server localhost:8529 shutdown
!!! error running tests (please examine t/logs/error_log)
make: *** [run_tests] Error 1



Here is the contents of my error_log:

Script command is started on Thu Jul 24 15:58:30 CDT 2003.# cat
error_log
END in modperl_extra.pl, pid=10926
[Thu Jul 24 14:54:26 2003] [notice] Apache/2.0.47 (Unix)
mod_perl/1.99_09 Perl/v5.8.0 configured -- resuming normal operations
[Thu Jul 24 14:54:26 2003] [info] Server built: Jul 14 2003 15:48:58
[Thu Jul 24 14:54:26 2003] [debug] prefork.c(1037): AcceptMutex: pthread
(default: pthread)
[Thu Jul 24 14:54:27 2003] [error] server reached MaxClients setting,
consider raising the MaxClients setting
[Thu Jul 24 14:54:41 2003] [info] [client 127.0.0.1] TestAPI::aplog test
in progress
[Thu Jul 24 14:54:41 2003] [debug]
/usr/local/tmp/mod_perl-1.99_09/t/response/TestAPI/aplog.pm(43):
log_serror test ok
[Thu Jul 24 14:54:41 2003] [debug]
/usr/local/tmp/mod_perl-1.99_09/t/response/TestAPI/aplog.pm(46):
(20007)No time was provided and one was required.: log_serror test 2 ok
[Thu Jul 24 14:54:41 2003] [debug]
/usr/local/tmp/mod_perl-1.99_09/t/response/TestAPI/aplog.pm(49): [client
127.0.0.1] (20007)No time was provided and one was required.: log_rerror
test ok
[Thu Jul 24 14:54:41 2003] [error] $r-log_error test ok
[Thu Jul 24 14:54:41 2003] [error] $s-log_error test ok
[Thu Jul 24 14:54:41 2003] [debug]
/usr/local/tmp/mod_perl-1.99_09/t/response/TestAPI/aplog.pm(63):
TestAPI::aplog test done
[Thu Jul 24 14:54:41 2003] [warn] ApacheApache-warn test ok
[Thu Jul 24 14:54:41 2003] [warn] $s-warn test ok
[Thu Jul 24 14:55:06 2003] [error] Apache::log_error test ok

*** The following error entry is expected and it is harmless ***
[Thu Jul 24 14:55:29 2003] [error] [client 127.0.0.1] Undefined
subroutine TestError::runtime::no_such_func called at
/usr/local/tmp/mod_perl-1.99_09/t/response/TestError/runtime.pm line 19.


*** The following error entry is expected and it is harmless ***
[Thu Jul 24 14:55:30 2003] [error] failed to resolve handler
`TestError::syntax'
[Thu Jul 24 14:55:30 2003] [error] [client 127.0.0.1] syntax error at
/usr/local/tmp/mod_perl-1.99_09/t/response/TestError/syntax.pm line 22,
near \;
Compilation failed in require at (eval 115) line 3.

[echo_filter] get_brigade: Error 0
[Thu Jul 24 14:55:34 2003] [error] [client 127.0.0.1] File does not
exist: /usr/local/tmp/mod_perl-1.99_09/t/htdocs/input_filter.html

*** The following error entry is expected and it is harmless ***
[Thu Jul 24 14:56:01 2003] [error] [client 127.0.0.1] File does not
exist: /usr/local/tmp/mod_perl-1.99_09/t/htdocs/nope

*** The following error entry is expected and it is harmless ***
[Thu Jul 24 14:56:18 2003] [error] [client 127.0.0.1] need AuthName:
/TestModperl__setauth
[Thu Jul 24 14:56:27 2003] [info] Child process pid=10928 is exiting
[Thu Jul 24 14:56:27 2003] [info] removed PID file
/usr/local/tmp/mod_perl-1.99_09/t/logs/httpd.pid (pid=11248)
[Thu Jul 24 14:56:27 2003] [notice] caught SIGTERM, shutting down
END in modperl_extra.pl, pid=11248


Thanks in advance!

Ryan Laus



reverse proxy in depth tutorial?

2003-07-24 Thread Garrett Goebel
Title: reverse proxy in depth tutorial?





This is slightly off-topic, but as it hits on Mason, optimizing mod_perl for performance, and is covered in passing in the practical and mod_perl cookbook books, I figured I'd ask here first.

Can anyone point me toward a good in depth article or documentation on using reverse proxying with apache? And no, I'm sorry but the apache reference docs on modules and directives is too spartan. I'm looking to minimize memory utilization and maximize performance, and am slowly working through the tips from the books and available online documentation. 

Most everything I'm stumbled upon has been short on detail and examples. For instance, I never found an example of how to just reverse proxy everything for a given backend server. All the examples I saw showed how to proxy something like http://foo/bar but not http://foo. Eventually I came up with the following:

[Reverse Proxy]
...
Listen 192.168.1.1:80
RewriteEngine on
RewriteRule ^/?(.*) http://127.0.0.1:80/$1 [P]
ProxyPassReverse / http://127.0.0.1:80/
...


[Backend Server]
...
Listen 127.0.0.1:80
...


Is this kosher? 


Is there a better way to do this? 


A way to do it without mod_rewrite using only mod_proxy directives?


Are there any strong arguments against using a mod_proxy/mod_rewrite httpd accelerator? Or preferred alternatives?


Using the loopback for the backend has the security advantage of completely isolating the backend from any direct communication with external hosts. How do I keep the backend on 127.0.0.1 _and_ handle name based virtual hosts?

What are the issues with regard to virtual hosting and ssl?


Any tips on keeping the config files maintainable?


For instance if I'm doing a mason site with co-branding through multiple component roots... What would minimal configurations for proxy and backend servers look like in order to redirect an externally exposed ip address on the proxy to a backend on 127.0.0.1 and still preserve the name based virtual hosts? It that possible? What are the variations, tradeoffs, and issues scaling it out to multiple physical servers? etc.

--
Garrett Goebel
IS Development Specialist


ScriptPro Direct: 913.403.5261
5828 Reeds Road Main: 913.384.1008
Mission, KS 66202 Fax: 913.384.2180
www.scriptpro.com garrett at scriptpro dot com





Re: Application design patterns

2003-07-24 Thread Perrin Harkins
On Thu, 2003-07-24 at 15:17, Eric Sammer wrote:
 Maybe a stupid question, but what would be the functional difference 
 between dumping the object after each request like you say and using the 
 same method as you describe for the TT object below? I ask because I'm 
 currently treating both objects the same way in two or three of my 
 larger applications. I would assume this is to catch premature database 
 shutdown or network trouble between an app server and database (cluster) 
 on a request by request basis? Is this a performance related choice or 
 an Apache::DBI best practices thing?

Apache::DBI already caches it.  It will ping the handle to make sure
it's active and then hand it back to you.  This extra level just skips
the ping if we've already done it on the current request.  If you simply
put the handle in a global, it will not get ping-ed on each requests and
you'll have all kinds of problems when connections time out.

Another approach to the same issue is to use the setPingTimeOut() method
of Apache::DBI.

  The rest has to do with database work and patterns for
  building model objects, and I hope to cover that in the article version
  of the talk I gave about object-relational mapping tools at this year's
  Perl Conference.
 
 Is this past tense and if so, is the article up somewhere? Just curious...

I already gave the talk, but have not completed the article yet.

- Perrin


RE: Mixing Apache::Filter with other mods like mod_php

2003-07-24 Thread Crispin Bivans
Thanks. I took the route of running a double pipe to a php command to send it the php 
text and read the results of it after processing.

That was helpful.

 -Original Message-
From:   Perrin Harkins [mailto:[EMAIL PROTECTED] 
Sent:   Thursday, July 24, 2003 8:57 AM
To: Crispin Bivans
Cc: [EMAIL PROTECTED]
Subject:Re: Mixing Apache::Filter with other mods like mod_php

On Thu, 2003-07-24 at 12:48, Crispin Bivans wrote:
 Situation: I have a custom templating package that will lookup translation texts 
 based off of keywords so we can use 1 html file for all 8-9 languages. I've made it 
 part of an Apache::Filter list that also run's Apache::SSI so that any server side 
 includes in the html file will also get run. There is also some mod_php code (a php 
 require line that pulls in a different page graphic everytime they refresh the page) 
 that I need to also 'run' as part of the web page.
[...]
 How can I make this work?

You can't in apache 1.x.  In apache 2.x there is the ability to filter
content in this way, but the filtering done in 1.x by Apache::Filter is
really just at the mod_perl level so it can't deal with additional
apache modules.  The only way to actually get the PHP code to run is to
make a separate request with something like LWP back to the server to
run a PHP page, or maybe run it through the separate PHP executable with
a system call.

- Perrin




Re: Application design patterns

2003-07-24 Thread Garrett Goebel
Title: Re: Application design patterns





Perrin Harkins wrote:
 
 The biggest thing the article didn't cover is the ideas
 used by the guys coding the more interactive parts of the
 application to express the state machine implemented by
 each of their modules in a declarative data structure.
 This was largely invented by Adam Sussman, who is at
 TicketMaster now. It was similar to what you see in
 CGI::Application and some of the other frameworks.


Has anyone written an article on it?


Or is this still in the domain of: go read the CGI::Application code and sort it out for yourself?


This is a topic I've been wondering about recently. I don't have a background in CS. So, I always wonder when tempted to head off into the books... whether or not the return-on-investment will justify the time I could have spent kludging something together that's good enough.

I've noted a few FSM modules on CPAN:


DFA::Command
DFA::Simple
DFA::Kleene
POE::NFA
Bio::Tools::StateMachine::AbstractStateMachine


After sifting through google searches I turned up the following article:


Essay on Web State Machines by Charles Stross
http://www.antipope.org/charlie/attic/webbook/essays/statemach.html


Interactive Web Applications Based on Finite State Machines
http://www.math.luc.edu/~laufer/papers/isas95.pdf


--
Garrett Goebel
IS Development Specialist


ScriptPro Direct: 913.403.5261
5828 Reeds Road Main: 913.384.1008
Mission, KS 66202 Fax: 913.384.2180
www.scriptpro.com garrett at scriptpro dot com





Re: Application design patterns

2003-07-24 Thread Perrin Harkins
On Thu, 2003-07-24 at 17:22, Garrett Goebel wrote:
 Perrin Harkins wrote:
  
  The biggest thing the article didn't cover is the ideas
  used by the guys coding the more interactive parts of the
  application to express the state machine implemented by
  each of their modules in a declarative data structure.
  This was largely invented by Adam Sussman, who is at
  TicketMaster now.  It was similar to what you see in
  CGI::Application and some of the other frameworks.
 
 Has anyone written an article on it?

On state machines as a model for web apps?  Probably.  And there is this
article about CGI::Application:
http://www.perl.com/pub/a/2001/06/05/cgi.html

You can also read the fairly extensive docs for CGI::Application,
Apache::PageKit, OpenInteract, CGI::MxScreen, and others.  None of these
require you to read code.

Essentially, people have looked at the core concepts of web applications
-- screens, transitions between screens, expected input on each screen
-- and come up with various ways to define them with a data structure
instead of with code.  Whether or not this is a good idea depends partly
on what your application does.  Apps that do lots of browsing/publishing
don't gain as much from this as ones that have lots of interactivity and
forms.

 I don't have a background in CS.

Welcome to the club.  This isn't rocket science.

 After sifting through google searches I turned up the following
 article:
 
 Essay on Web State Machines by Charles Stross
 http://www.antipope.org/charlie/attic/webbook/essays/statemach.html

That one seems to be about managing persistent data, which is a
different topic.

 Interactive Web Applications Based on Finite State Machines
 http://www.math.luc.edu/~laufer/papers/isas95.pdf

That's more like it.

- Perrin


Re: Test unexpectedly succeeded during make test

2003-07-24 Thread Stas Bekman
First of all, when reporting problems please following the guidelines:
http://perl.apache.org/docs/2.0/user/help/help.html#Reporting_Problems
OS: AIX 4.3.3 w/the latest maintenance level

modperl/request_rec_tie_apiok
1/3 unexpectedly succeeded
The test t/response/TestModperl/request_rec_tie_api.pm goes as:

require Apache::Build;
my @todo;
push @todo, 1 if Apache::Build::AIX();
plan $r, tests = 3, todo = [EMAIL PROTECTED];
# XXX: on AIX 4.3.3 we get:
# STDIN STDOUT STDERR
# perl:   0  1  2
# mod_perl:   0  0  2
my $fileno = fileno STDOUT;
ok $fileno;
t_debug fileno STDOUT: $fileno;
the problem is that on the AIX that I was testing I was receiving STDOUT as 0 
under mod_perl. I don't remember which perl it was :( but this is not a problem.

This is the test that really fails:

 filter/in_bbs_msg.t  255 65280??   ??   %  ??

please run this test separately and post the error_log file and the output of 
the run:

rm t/logs/error_log
t/TEST -v filter/in_bbs_msg.t
Next you also want to install LWP, otherwise many of the tests aren't running:

all skipped: cannot find module 'LWP'


__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Advice sought for learning mod_perl (2 or 1)

2003-07-24 Thread Stas Bekman
Ged Haywood wrote:

 Q1: Is there a similar module to Apache::Request?


Depends what you want to do, but not really.  Care to try porting it?
No no. Apache::Request 2 port is in works and it'll be available RSN thanks to 
Joe Schaefer and Randy Kobes who do an extraordinary job. Though it'll be 
released sooner if more people help with testing and polishing it. For more 
information see:
http://httpd.apache.org/apreq/

__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: [mp1] Safe segfaults with mp1

2003-07-24 Thread Stas Bekman
Joel Palmius wrote:
Ah, well, after a five hours of experimentation I thought up a working
workaround anyway.
This works with an unpatched version of mp1 ($substr is any perl code 
fetched from external source):

  my(@ops) = split(/\x0a/,$substr);
  my($cell,$reval);
  foreach $cell (@ops)
  {
$cell =~ s/^[\x09\ ]+//g;
$cell =~ s/^print\ /\$output\ \.\=\ /;
if($cell)
{
  $reval .= $cell . \n;
}
  }
  my($output);

  $reval .= \$output;\n;

  my($compartment) = new Safe(Tempo);
  $compartment-permit(qw(:browse));
  $output = $compartment-reval($reval);
  if($@)
  {
$self-{ERROR} = gettext(Security exception:  . $@);
$self-{ERRORCODE} = 99;
  }
  print $output;

I just replace all print statements with $output .= , and then make 
sure that the reval results in the final contents of $output, which I then 
print outside the reval().

Works fine now. So far nothing else has crashed, although I'm somewhat
suspicious of a number of rather random events in the code. I'm almost
certain this is me having messed up something else though.
Neat. I expect it to work as long as you do simple things, it's going to be 
much harder to make it working with more complex code. However I was trying to 
simplify your logic and use IO::String to catch the output:

  print Content-type: text/plain\n\n;
  use warnings;
  use strict;
  use Safe;

  our $output = '';
  my($cmpt) = new Safe 'MyRoot';
  $cmpt-share('$output');
  $cmpt-permit(qw(leaveeval entereval caller require :browse ));
  $cmpt-reval('EOI');

  # redirect prints to a buffer
  use IO::String;
  my $str_fh = IO::String-new($output);
  select $str_fh;
  # put the normal code here
  print gnu\n;
EOI
  if($@)
  {
die $@;
  }
  select STDOUT;
  print $output;

However, if I'm not supposed to use Safe in conjunction with mp, what *am* 
I supposed to use? 
I didn't say that. I just said that if it doesn't work for you... but as you 
have just shown that TIMTOWTDI ;)

I might be possible to convince to write a version of Safe specifically
for mp1, although I expect I shall have to experience more problems with
the existing Safe code to be bothered. :-)
You can always give it a try.

__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


RE: mod_perl installation problem...

2003-07-24 Thread Randy Kobes
On Wed, 23 Jul 2003, Jim Morrison [Mailing-Lists] wrote:
[ .. ]
 Make appeared to be successful yes (afaik)... I did wonder
 about the permissions thing but I tried as root to no avail..

Some people have had problems running the tests as root ... You
might want to try unpacking, building, and testing as some user
other than root, and only su to root when installing.

-- 
best regards,
randy


mp2: multiple include paths accross virtual servers?

2003-07-24 Thread Carl Brewer


I'm running into something that may be a feature(!) of
my misunderstanding of how mp works.
I've got this defined in a VirtualHost directive:

PerlRequire /data/www/foo/secure/etc/startup.pl

For a number of different virtual servers.

Is it possible for mp2 (or mp in general) to keep state seperate
between virtual servers?  Ie: if I have a different
include path set in a couple of different startup.pl scripts,
will the different virtual servers keep them seperate, or
can I only have the one across a particular httpd instance?
I'm fearing that I'll need seperate httpd's for each
seperate site?
Carl





Re: mp2: multiple include paths accross virtual servers?

2003-07-24 Thread Stas Bekman
Carl Brewer wrote:


I'm running into something that may be a feature(!) of
my misunderstanding of how mp works.
I've got this defined in a VirtualHost directive:

PerlRequire /data/www/foo/secure/etc/startup.pl

For a number of different virtual servers.

Is it possible for mp2 (or mp in general) to keep state seperate
between virtual servers?  Ie: if I have a different
include path set in a couple of different startup.pl scripts,
will the different virtual servers keep them seperate, or
can I only have the one across a particular httpd instance?
I'm fearing that I'll need seperate httpd's for each
seperate site?
You need to add:

  PerlOptions +Parent

See:

http://perl.apache.org/docs/2.0/user/config/config.html#C_Parent_

__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com