You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Will Fould <wi...@gmail.com> on 2006/03/27 07:43:24 UTC

syntax vs. style

Hi,

I afraid this is a naive question but here it goes:

I've fixed a lot of old CGI scripts over the past year and all new stuff to
work in our MP2 environment and everything seems to be running excellent --
I mean GREAT, really.

We now use:

        <Location /scripts/>
                SetHandler perl-script
                PerlResponseHandler ModPerl::Registry
                PerlOptions +ParseHeaders
                Options +ExecCGI
        </Location>

My question is this:

Instead of using MP2 syntax, etc, we're still using:

    print "Content-type: $type\n\n";
    print "blah";

and in sending redirects, we use stuff like:

    print "Location: $url\n\n";


Is this a problem or is it just bad style?

What reasons are there to continue our port to use  the correct response
handler syntax, etc?


This is an excellent group - Thanks a lot for all the help.

Re: syntax vs. style

Posted by Will Fould <wi...@gmail.com>.
Thanks guys - this is helpful.

In reality, and running the ways things are, I already need to restart (or
::Reload) to introduce changes (moved to that paradigm last year) -- but I
guess that beyond the efficiencies you point out here in using proper API
(for handler, print, etc) and the rationale here, I'm trying to prioritize
and scope my next effort if any, (for this project, at least), and then best
approach the next project. Basically, I have packages that print headers for
everything, and others that "print $foo;exit;" for everything.  Ideally,
I'll alter each of those to do it right, and get better mileage. And from
there, I'll work on creating proper mod_perl handlers.

Cheers,


On 3/27/06, Frank Wiles <fr...@wiles.org> wrote:
>
> On Mon, 27 Mar 2006 14:08:38 +0100
> "Carl Johnstone" <mo...@fadetoblack.me.uk> wrote:
>
> > The next step from there is not using Apache::Registry at all, but
> > putting mod_perl handlers into their own modules/packages. However
> > there's more of a change here to other ways of working - for example
> > you need to restart server to introduce code changes.
>
>   Overall great advice in this thread, but I wanted to point out
>   that with Apache2::Reload this isn't strictly the case.  You can
>   set it to reload certain modules or all without a server restart,
>   however I personally wouldn't use it in production as there is very
>   little benefit.
>
> ---------------------------------
>    Frank Wiles <fr...@wiles.org>
>    http://www.wiles.org
> ---------------------------------
>
>

Re: syntax vs. style

Posted by Carl Johnstone <mo...@fadetoblack.me.uk>.
> But having said that, I find Apache2::Reload very handy for easy and quick 
> development.

Me too!

Although I find that occasionally I have to restart apache on the 
development box before it'll work correctly. Hence I wouldn't run it on a 
production server.

Carl 


Re: syntax vs. style

Posted by Jonathan Vanasco <mo...@2xlp.com>.
On Mar 27, 2006, at 10:06 PM, Foo Ji-Haw wrote:

>
>> Apache::Reload doesn't always work too.  two scenarios
> ...
> I use Apache2::Reload myself for my development box. There's an  
> extra scenario you missed out:
> 1. If you change the inheritance of the package, you'll get an  
> error too.
>
> But having said that, I find Apache2::Reload very handy for easy  
> and quick development.

i couldn't develop or test without it.  its a great module and i find  
it indispensable with my own work.   i just don't think its a good  
option for a production environment.  others might disagree. 
  

Re: syntax vs. style

Posted by Foo Ji-Haw <jh...@extracktor.com>.
> Apache::Reload doesn't always work too.  two scenarios
...
I use Apache2::Reload myself for my development box. There's an extra 
scenario you missed out:
1. If you change the inheritance of the package, you'll get an error too.

But having said that, I find Apache2::Reload very handy for easy and 
quick development.

Re: syntax vs. style

Posted by Jonathan Vanasco <mo...@2xlp.com>.
On Mar 27, 2006, at 9:42 AM, Frank Wiles wrote:
>   Overall great advice in this thread, but I wanted to point out
>   that with Apache2::Reload this isn't strictly the case.  You can
>   set it to reload certain modules or all without a server restart,
>   however I personally wouldn't use it in production as there is very
>   little benefit.

Apache::Reload doesn't always work too.  two scenarios

a_ if you have stuff that happens in a BEGIN block, or stuff that  
references something in a begin block (example: module a: has a begin  
block that pulls config info from a DB.  module b: on startup (after  
begin) parses that config info into a specific datastructure --  
apache:restart won't help you if you have to modify a or b.  )

b_	In the past , if you needed to make 20 changes to a file on your  
dev box to trace soemthing down, after 10 or so changes you could see  
a bunch of namespace issues come up.  I *think* thats fixed now  
though.  but it might not be.



| - - - - - - - - - - - - - - - - - - - -
| RoadSound.com / Indie-Rock.net
| Collaborative Online Management And Syndication Tools
| Launching March 2006
| - - - - - - - - - - - - - - - - - - - -





Re: syntax vs. style

Posted by Frank Wiles <fr...@wiles.org>.
On Mon, 27 Mar 2006 14:08:38 +0100
"Carl Johnstone" <mo...@fadetoblack.me.uk> wrote:

> The next step from there is not using Apache::Registry at all, but
> putting mod_perl handlers into their own modules/packages. However
> there's more of a change here to other ways of working - for example
> you need to restart server to introduce code changes.

  Overall great advice in this thread, but I wanted to point out
  that with Apache2::Reload this isn't strictly the case.  You can
  set it to reload certain modules or all without a server restart,
  however I personally wouldn't use it in production as there is very
  little benefit. 

 ---------------------------------
   Frank Wiles <fr...@wiles.org>
   http://www.wiles.org
 ---------------------------------


Re: syntax vs. style

Posted by Carl Johnstone <mo...@fadetoblack.me.uk>.
>>>>>
Instead of using MP2 syntax, etc, we're still using:

    print "Content-type: $type\n\n";
    print "blah";

and in sending redirects, we use stuff like:

    print "Location: $url\n\n";


Is this a problem or is it just bad style?

What reasons are there to continue our port to use  the correct response
handler syntax, etc?
<<<<<

It's slightly slower. Effectively those headers have to be re-parsed by 
Apache::Registry. Another example is that $r->print is faster than a plain 
print.

Although Apache::Registry gives a good speed boost by itself, you need to 
make use of the mod_perl API to actually get the best out of it.

The next step from there is not using Apache::Registry at all, but putting 
mod_perl handlers into their own modules/packages. However there's more of a 
change here to other ways of working - for example you need to restart 
server to introduce code changes.

Carl


Re: syntax vs. style

Posted by Foo Ji-Haw <jh...@extracktor.com>.
> I've fixed a lot of old CGI scripts over the past year and all new 
> stuff to work in our MP2 environment and everything seems to be 
> running excellent -- I mean GREAT, really.
Yes. I've never looked back myself. :)

If you're going all the way into modperl (arguably depending on your 
needs), you may want to use packages instead of a file-per-uri method. 
That means you use the following registration:

<Location /scripts/>
                SetHandler perl-script
                PerlResponseHandler Your::Package::Here
</Location>

Check out perl.apache.org for a sample package that uses this model.

And using this model, you can use the following to set your content handler:
$r->content_type('text/html');
>
> Is this a problem or is it just bad style?
I don't think it's bad style. But if you're just using modperl to 
accelerate your perl applets, you should try this method instead for 
setting content type:

$q->header(-type => 'text/html');

Where $q is an instance of CGI (check out perldoc for details).