Re: Apache::MP3 requires PerlSetupEnv on, patch to convert to Apache::Request

2002-03-04 Thread Stas Bekman

Eric Hammond wrote:
 Lincoln:
 
 After a day of adding debug statements into Apache::MP3 and CGI.pm
 I finally tracked down why my streaming was not working.  I had
 listened to http://perl.apache.org/guide/performance.html#PerlSetupEnv_Off
 which caused $ENV{QUERY_STRING} to not be set which broke CGI.pm.

The guide does say:

Scripts using the CGI.pm module require PerlSetupEnv On
because that module relies on a properly populated CGI
environment table.

But I realize that a user of Apache::MP3 may not realize that the latter 
uses CGI.pm under the hood.

Can CGI.pm detect that 'PerlSetupEnv Off' is in effect and die if that's 
the case? for example by testing some env var that most likely should be 
set with 'PerlSetupEnv On'? e.g.:

   #check that we aren't running under PerlSetupEnv Off
   if ($ENV{MOD_PERL}  !ENV{SCRIPT_FILENAME}) {
   die CGI.pm cannot run under 'PerlSetupEnv Off' setting;
   }



 To save others the agony, you might want to add a note to the Apache::MP3
 docs that it requires PerlSetupEnv on
 
 Alternatively, you might consider rewriting Apache::MP3 to use 
 Apache::Request instead of CGI.pm (though I understand you may have 
 a fondness for the latter).
 
 I've included a patch to convert Apache::MP3 to use Apache::Request
 for parameters.  More work would be required to convert the other uses 
 of CGI.pm, but if you'd like, I'd be willing to tackle that, too, as 
 it would be nice to not require the large size of CGI.pm.
 

_
Stas Bekman JAm_pH  --   Just Another mod_perl Hacker
http://stason.org/  mod_perl Guide   http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/




Apache::MP3 requires PerlSetupEnv on, patch to convert to Apache::Request

2002-03-03 Thread Eric Hammond

Lincoln:

After a day of adding debug statements into Apache::MP3 and CGI.pm
I finally tracked down why my streaming was not working.  I had
listened to http://perl.apache.org/guide/performance.html#PerlSetupEnv_Off
which caused $ENV{QUERY_STRING} to not be set which broke CGI.pm.

To save others the agony, you might want to add a note to the Apache::MP3
docs that it requires PerlSetupEnv on

Alternatively, you might consider rewriting Apache::MP3 to use 
Apache::Request instead of CGI.pm (though I understand you may have 
a fondness for the latter).

I've included a patch to convert Apache::MP3 to use Apache::Request
for parameters.  More work would be required to convert the other uses 
of CGI.pm, but if you'd like, I'd be willing to tackle that, too, as 
it would be nice to not require the large size of CGI.pm.

Thanks
--
Eric Hammond
[EMAIL PROTECTED]

--- Apache/MP3.pm.orig  Sat Mar  2 18:00:37 2002
+++ Apache/MP3.pm   Sun Mar  3 10:14:23 2002
@@ -67,7 +67,7 @@
 
 sub new {
   my $class = shift;
-  unshift @_,'r' if @_ == 1;
+  @_ = ('r' = Apache::Request-new(shift)) if @_ == 1;
   return bless { @_ },$class;
 }
 
@@ -82,35 +82,35 @@
 if -d $r-filename;  # should be $r-finfo, but STILL problems with this
 
   #simple download of file
-  return $self-download_file($r-filename) unless param;
+  return $self-download_file($r-filename) unless $r-param;
 
   # this is called to stream a file
-  return $self-stream if param('stream');
+  return $self-stream if $r-param('stream');
 
   # this is called to generate a playlist on the current directory
   return $self-send_playlist($self-find_mp3s)
-if param('Play All');
+if $r-param('Play All');
 
   # this is called to generate a playlist on the current directory
   # and everything beneath
   return $self-send_playlist($self-find_mp3s('recursive')) 
-if param('Play All Recursive') ;
+if $r-param('Play All Recursive') ;
 
   # this is called to generate a shuffled playlist of current directory
   return $self-send_playlist($self-find_mp3s,'shuffle')
-if param('Shuffle');
+if $r-param('Shuffle');
 
   # this is called to generate a shuffled playlist of current directory
   return $self-send_playlist($self-find_mp3s,'shuffle')
-if param('Shuffle All');
+if $r-param('Shuffle All');
 
   # this is called to generate a shuffled playlist of current directory
   # and everything beneath
   return $self-send_playlist($self-find_mp3s('recursive'),'shuffle')
-if param('Shuffle All Recursive');
+if $r-param('Shuffle All Recursive');
 
   # this is called to generate a playlist for one file
-  if (param('play')) {
+  if ($r-param('play')) {
 my $dot3 = '.m3u|.pls';
 my($basename) = $r-uri =~ m!([^/]+?)($dot3)?$!;
 $basename = quotemeta($basename);
@@ -137,8 +137,8 @@
   }
 
   # this is called to generate a playlist for selected files
-  if (param('Play Selected')) {
-return HTTP_NO_CONTENT unless my @files = param('file');
+  if ($r-param('Play Selected')) {
+return HTTP_NO_CONTENT unless my @files = $r-param('file');
 my $uri = dirname($r-uri);
 $self-send_playlist([map { $uri/$_ } @files]);
 return OK;