Pourquoi dois-je & # 8220; redéfinir & # 8221; avertissements avec & # 8220; utiliser une constante & # 8221; sous mod_perl?

StackOverflow https://stackoverflow.com/questions/1205116

  •  05-07-2019
  •  | 
  •  

Question

J'exécute le script CGI avec apache2 et j'ai les lignes d'avertissement dans error.log ( j'ai supprimé toutes les lignes similaires de la sortie ):

[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::UPLOAD_DIR redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::BUFFER_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)
[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::BUFFER_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_FILE_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)
[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_FILE_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_DIR_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)
[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_DIR_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_OPEN_TRIES redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)
[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_OPEN_TRIES redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Subroutine dir_size redefined at /home/stanislav/cgi/perl/upload.pl line 79,
     line 133 (#2)
[Thu Jul 30 09:39:37 2009] upload.pl: Subroutine dir_size redefined at /home/stanislav/cgi/perl/upload.pl line 79,  line 133.
Subroutine error redefined at /home/stanislav/cgi/perl/upload.pl line 90,
     line 133 (#2)
[Thu Jul 30 09:39:37 2009] upload.pl: Subroutine error redefined at /home/stanislav/cgi/perl/upload.pl line 90,  line 133.
Argument "" isn't numeric in numeric ge (>=) at
    /home/stanislav/cgi/perl/upload.pl line 62 (#4)
[Thu Jul 30 09:39:37 2009] -e: Argument "" isn't numeric in numeric ge (>=) at /home/stanislav/cgi/perl/upload.pl line 62.
Filehandle OUTPUT opened only for input at /home/stanislav/cgi/perl/upload.pl
    line 69 (#5)
[Thu Jul 30 09:39:37 2009] -e: Filehandle OUTPUT opened only for input at /home/stanislav/cgi/perl/upload.pl line 69.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::UPLOAD_DIR redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)

Pourquoi ces lignes existent-elles et existe-t-il un moyen de les arrêter?

Code qui fait ces avertissements (tiré du livre "Programmation CGI avec Perl", avec quelques bugs corrigés):



#!/usr/bin/perl
use strict;
use warnings;


use CGI;
use CGI::Carp;
#use diagnostics qw/-verbose/;

use Fcntl qw( :DEFAULT :flock );
use constant UPLOAD_DIR     => "/tmp/test_upload/";
use constant BUFFER_SIZE    => 16_384;
use constant MAX_FILE_SIZE  => 1_048_576;       # Limit each upload to 1 MB
use constant MAX_DIR_SIZE   => 100 * 1_048_576; # Limit total uploads to 100 MB
use constant MAX_OPEN_TRIES => 100;

$CGI::DISABLE_UPLOADS   = 0;
$CGI::POST_MAX          = MAX_FILE_SIZE;
my $q = new CGI;
$q->cgi_error and error( $q, "Error transferring file: " . $q->cgi_error );
my $file      = $q->param( "file" )     || error( $q, "No file received." );
my $filename  = $q->param( "filename" ) || error( $q, "No filename entered." );
my $fh        = $q->upload( "file" )     || error( $q, "Something is wrong with file handle." );
#my $fh        = $q->upload( $file );
my $buffer    = "";
if ( dir_size( UPLOAD_DIR ) + $ENV{CONTENT_LENGTH} > MAX_DIR_SIZE ) {
    error( $q, "Upload directory is full." );
}
# Allow letters, digits, periods, underscores, dashes
# Convert anything else to an underscore
$filename =~ s/[^\w.-]/_/g;
if ( $filename =~ /^(\w[\w.-]*)/ ) {
    $filename = $1;
}
else {
    error( $q, "Invalid file name; files must start with a letter or number." );
}
# Open output file, making sure the name is unique
until ( sysopen OUTPUT, UPLOAD_DIR . $filename, O_CREAT | O_EXCL ) {
    $filename =~ s/(\d*)(\.\w+)$/($1||0) + 1 . $2/e;
    $1 >= MAX_OPEN_TRIES and error( $q, "Unable to save your file." );
}
# This is necessary for non-Unix systems; does nothing on Unix
binmode $fh;
binmode OUTPUT;
# Write contents to output file
while ( read( $fh, $buffer, BUFFER_SIZE ) ) {
    print OUTPUT $buffer;
}
close OUTPUT;

if ( -T $fh ) {
    print $q->header("text/plain");
    seek $fh, 0, 0;
    map { print } ;
}

sub dir_size {
    my $dir = shift;
    my $dir_size = 0;

    # Loop through files and sum the sizes; doesn't descend down subdirs
    opendir DIR, $dir or die "Unable to open $dir: $!";
    while ( 

J'exécute le script CGI avec apache2 et j'ai les lignes d'avertissement dans error.log ( j'ai supprimé toutes les lignes similaires de la sortie ):

[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::UPLOAD_DIR redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::BUFFER_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)
[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::BUFFER_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_FILE_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)
[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_FILE_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_DIR_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)
[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_DIR_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_OPEN_TRIES redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)
[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_OPEN_TRIES redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Subroutine dir_size redefined at /home/stanislav/cgi/perl/upload.pl line 79,
     line 133 (#2)
[Thu Jul 30 09:39:37 2009] upload.pl: Subroutine dir_size redefined at /home/stanislav/cgi/perl/upload.pl line 79,  line 133.
Subroutine error redefined at /home/stanislav/cgi/perl/upload.pl line 90,
     line 133 (#2)
[Thu Jul 30 09:39:37 2009] upload.pl: Subroutine error redefined at /home/stanislav/cgi/perl/upload.pl line 90,  line 133.
Argument "" isn't numeric in numeric ge (>=) at
    /home/stanislav/cgi/perl/upload.pl line 62 (#4)
[Thu Jul 30 09:39:37 2009] -e: Argument "" isn't numeric in numeric ge (>=) at /home/stanislav/cgi/perl/upload.pl line 62.
Filehandle OUTPUT opened only for input at /home/stanislav/cgi/perl/upload.pl
    line 69 (#5)
[Thu Jul 30 09:39:37 2009] -e: Filehandle OUTPUT opened only for input at /home/stanislav/cgi/perl/upload.pl line 69.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::UPLOAD_DIR redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)

Pourquoi ces lignes existent-elles et existe-t-il un moyen de les arrêter?

Code qui fait ces avertissements (tiré du livre "Programmation CGI avec Perl", avec quelques bugs corrigés):

Constant subroutine main::FOO redefined at -e line 1.

Ce code a une sortie similaire: $ perl -e 'sous FOO () {1} BEGIN {* FOO = sub () {2}; } print FOO; '

<*>

Je n'ai mis aucun avertissement qw / redefine / mais cela n'a pas aidé.

= readdir DIR ) { $dir_size += -s "$dir/

J'exécute le script CGI avec apache2 et j'ai les lignes d'avertissement dans error.log ( j'ai supprimé toutes les lignes similaires de la sortie ):

[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::UPLOAD_DIR redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::BUFFER_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)
[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::BUFFER_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_FILE_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)
[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_FILE_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_DIR_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)
[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_DIR_SIZE redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_OPEN_TRIES redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)
[Thu Jul 30 09:39:37 2009] upload.pl: Constant subroutine ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::MAX_OPEN_TRIES redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133.
Subroutine dir_size redefined at /home/stanislav/cgi/perl/upload.pl line 79,
     line 133 (#2)
[Thu Jul 30 09:39:37 2009] upload.pl: Subroutine dir_size redefined at /home/stanislav/cgi/perl/upload.pl line 79,  line 133.
Subroutine error redefined at /home/stanislav/cgi/perl/upload.pl line 90,
     line 133 (#2)
[Thu Jul 30 09:39:37 2009] upload.pl: Subroutine error redefined at /home/stanislav/cgi/perl/upload.pl line 90,  line 133.
Argument "" isn't numeric in numeric ge (>=) at
    /home/stanislav/cgi/perl/upload.pl line 62 (#4)
[Thu Jul 30 09:39:37 2009] -e: Argument "" isn't numeric in numeric ge (>=) at /home/stanislav/cgi/perl/upload.pl line 62.
Filehandle OUTPUT opened only for input at /home/stanislav/cgi/perl/upload.pl
    line 69 (#5)
[Thu Jul 30 09:39:37 2009] -e: Filehandle OUTPUT opened only for input at /home/stanislav/cgi/perl/upload.pl line 69.
Constant subroutine
    ModPerl::ROOT::ModPerl::Registry::home_stanislav_cgi_perl_upload_2epl::UPLOAD_DIR redefined at /usr/share/perl/5.10/constant.pm line 115,  line 133 (#1)

Pourquoi ces lignes existent-elles et existe-t-il un moyen de les arrêter?

Code qui fait ces avertissements (tiré du livre "Programmation CGI avec Perl", avec quelques bugs corrigés):

<*>

Ce code a une sortie similaire: $ perl -e 'sous FOO () {1} BEGIN {* FOO = sub () {2}; } print FOO; '

<*>

Je n'ai mis aucun avertissement qw / redefine / mais cela n'a pas aidé.

"; } return $dir_size; } sub error { my( $q, $reason ) = @_; print $q->header( "text/html" ), $q->start_html( "Error" ), $q->h1( "Error" ), $q->p( "Your upload was not procesed because the following error ", "occured: " ), $q->p( $q->i( $reason ) ), $q->end_html; exit; }

Ce code a une sortie similaire: $ perl -e 'sous FOO () {1} BEGIN {* FOO = sub () {2}; } print FOO; '

<*>

Je n'ai mis aucun avertissement qw / redefine / mais cela n'a pas aidé.

Était-ce utile?

La solution

Si je comprends bien, vous ne recevez ces avertissements que lorsque vous modifiez votre script. Le script est ensuite recompilé par mod_perl pour les sous-routines éligibles à l’inline. Lorsque le sous-programme est recompilé, si la valeur renvoyée change, cette nouvelle valeur ne sera pas reflétée aux endroits où elle était précédemment insérée.

Si vous modifiez la valeur de, par exemple, BUFFER_SIZE , vous devez redémarrer apache .

Je pense également que les mod_perl / Apache :: registres de fermeture accidentelle du registre sont pertinents pour votre script.

Autres conseils

À première vue, la première définition de FOO est optimisée. Définissez-le avec une déclaration dans le corps et je pense que vous constaterez que l'erreur disparaît.

$ perl -e 'sous FOO () {print 1; } BEGIN {* FOO = sub () {2}; } print FOO; '

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top