Avoid using each(): it tries to delete key

This commit is contained in:
Xavier Guimard 2016-02-13 10:06:48 +00:00
parent b86a321aac
commit 8c1bd8efeb
10 changed files with 29 additions and 21 deletions

View File

@ -59,8 +59,8 @@ sub initializeFromConfHash {
return 0 unless $hash; return 0 unless $hash;
while ( my ( $k, $v ) = each(%$hash) ) { foreach my $k ( keys %$hash ) {
$self->{$k} = $v; $self->{$k} = $hash->{$k};
} }
return 1; return 1;
@ -98,8 +98,8 @@ sub initializeFromXML {
# Store data in Metadata object # Store data in Metadata object
if ($data) { if ($data) {
while ( my ( $k, $v ) = each( %{$data} ) ) { foreach my $k ( keys %{$data} ) {
$self->{$k} = $v; $self->{$k} = $data->{$k};
} }
return 1; return 1;
} }

View File

@ -68,7 +68,8 @@ sub serialize {
my $fields; my $fields;
# Parse configuration # Parse configuration
while ( my ( $k, $v ) = each(%$conf) ) { foreach my $k (keys %$conf ) {
my $v = $conf->{$k};
# 1.Hash ref # 1.Hash ref
if ( ref($v) ) { if ( ref($v) ) {

View File

@ -302,8 +302,8 @@ sub _store {
# Store values as {key}value # Store values as {key}value
my @notifValues; my @notifValues;
while ( my ( $k, $v ) = each(%$fields) ) { foreach my $k ( keys %$fields ) {
$v = encodeLdapValue($v); my $v = encodeLdapValue( $fields->{$k} );
push @notifValues, "{$k}$v"; push @notifValues, "{$k}$v";
} }

View File

@ -662,8 +662,8 @@ sub postJavascript {
my $form = $formParams->{formSelector} || "form"; my $form = $formParams->{formSelector} || "form";
my $filler; my $filler;
while ( my ( $name, $value ) = each(%$data) ) { foreach my $name ( keys %$data ) {
$value = "x" x length($value); my $value = "x" x length( $data->{$name} );
$filler .= $filler .=
"form.find('input[name=$name], select[name=$name], textarea[name=$name]').val('$value')\n"; "form.find('input[name=$name], select[name=$name], textarea[name=$name]').val('$value')\n";
} }

View File

@ -172,7 +172,8 @@ sub portalInit {
sub locationRulesInit { sub locationRulesInit {
my ( $class, $conf, $tsv ) = @_; my ( $class, $conf, $tsv ) = @_;
while ( my ( $vhost, $rules ) = each( %{ $conf->{locationRules} } ) ) { foreach my $vhost ( keys %{ $conf->{locationRules} } ) {
my $rules = $conf->{locationRules}->{$vhost};
foreach my $url ( sort keys %{$rules} ) { foreach my $url ( sort keys %{$rules} ) {
my ( $cond, $prot ) = $class->conditionSub( $rules->{$url}, $tsv ); my ( $cond, $prot ) = $class->conditionSub( $rules->{$url}, $tsv );
@ -271,7 +272,8 @@ sub postUrlInit {
foreach my $vhost ( keys %{ $conf->{post} } ) { foreach my $vhost ( keys %{ $conf->{post} } ) {
# Browse all POST URI # Browse all POST URI
while ( my ( $url, $d ) = each( %{ $conf->{post}->{$vhost} } ) ) { foreach my $url ( keys %{ $conf->{post}->{$vhost} } ) {
my $d = $conf->{post}->{$vhost}->{$url};
Lemonldap::NG::Handler::Main::Logger->lmLog( Lemonldap::NG::Handler::Main::Logger->lmLog(
"Compiling POST data for $url", 'debug' ); "Compiling POST data for $url", 'debug' );
@ -281,8 +283,8 @@ sub postUrlInit {
$postUrl ||= $url; $postUrl ||= $url;
my $sub; my $sub;
while ( my ( $input, $value ) = each( %{ $d->{expr} } ) ) { foreach my $input ( keys %{ $d->{expr} } ) {
my $val = $class->substitute($value); my $val = $class->substitute( $d->{expr}->{$input} );
$sub .= "'$input' => $val,"; $sub .= "'$input' => $val,";
} }
$tsv->{inputPostData}->{$vhost}->{$postUrl} = $tsv->{inputPostData}->{$vhost}->{$postUrl} =

View File

@ -174,7 +174,8 @@ sub run {
&head; &head;
my ( $c, $m, $u ); my ( $c, $m, $u );
while ( my ( $user, $v ) = each( %{ $status->{user} } ) ) { foreach my $user ( keys %{ $status->{user} } ) {
my $v = $status->{user}->{$user};
$u++ unless ( $user =~ /^\d+\.\d+\.\d+\.\d+$/ ); $u++ unless ( $user =~ /^\d+\.\d+\.\d+\.\d+$/ );
# Total requests # Total requests

View File

@ -939,7 +939,8 @@ sub _globalTest {
hdebug('# _globalTest()'); hdebug('# _globalTest()');
my $result = 1; my $result = 1;
my $tests = &Lemonldap::NG::Manager::Conf::Tests::tests( $self->newConf ); my $tests = &Lemonldap::NG::Manager::Conf::Tests::tests( $self->newConf );
while ( my ( $name, $sub ) = each %$tests ) { foreach my $name ( keys %$tests ) {
my $sub = $tests->{$name};
my ( $res, $msg ); my ( $res, $msg );
eval { eval {
( $res, $msg ) = $sub->(); ( $res, $msg ) = $sub->();

View File

@ -137,7 +137,8 @@ sub tests {
checkUserDBGoogleAXParams => sub { checkUserDBGoogleAXParams => sub {
my @tmp; my @tmp;
if ( $conf->{userDB} =~ /^Google$/ ) { if ( $conf->{userDB} =~ /^Google$/ ) {
while ( my ( $k, $v ) = each %{ $conf->{exportedVars} } ) { foreach my $k ( keys %{ $conf->{exportedVars} } ) {
my $v = $conf->{exportedVars}->{$k};
if ( $v !~ Lemonldap::NG::Common::Regexp::GOOGLEAXATTR() ) { if ( $v !~ Lemonldap::NG::Common::Regexp::GOOGLEAXATTR() ) {
push @tmp, $v; push @tmp, $v;
} }
@ -159,7 +160,8 @@ sub tests {
checkUserDBOpenIDParams => sub { checkUserDBOpenIDParams => sub {
my @tmp; my @tmp;
if ( $conf->{userDB} =~ /^OpenID$/ ) { if ( $conf->{userDB} =~ /^OpenID$/ ) {
while ( my ( $k, $v ) = each %{ $conf->{exportedVars} } ) { foreach my $k ( keys %{ $conf->{exportedVars} } ) {
my $v = $conf->{exportedVars}->{$k};
if ( $v !~ Lemonldap::NG::Common::Regexp::OPENIDSREGATTR() ) if ( $v !~ Lemonldap::NG::Common::Regexp::OPENIDSREGATTR() )
{ {
push @tmp, $v; push @tmp, $v;

View File

@ -165,7 +165,8 @@ sub sessions {
my %r; my %r;
# 2.4.1 Store user IP addresses in %r # 2.4.1 Store user IP addresses in %r
while ( my ( $id, $entry ) = each %$res ) { foreach my $id ( keys %$res ) {
my $entry = $res->{$id};
next if ( $entry->{_httpSessionType} ); next if ( $entry->{_httpSessionType} );
$r{ $entry->{ $tsv->{whatToTrace} } } $r{ $entry->{ $tsv->{whatToTrace} } }
->{ $entry->{ $self->{ipField} } }++; ->{ $entry->{ $self->{ipField} } }++;

View File

@ -85,8 +85,8 @@ sub checkGoogleSession {
unless ( $self->{_AXNS} ) { unless ( $self->{_AXNS} ) {
if ( $pSession->data ) { if ( $pSession->data ) {
$self->{user} = $pSession->data->{email}; $self->{user} = $pSession->data->{email};
while ( my ( $k, $v ) = each %{ $pSession->data } ) { foreach my $k ( keys %{ $pSession->data } ) {
$gs->{$k} = $v; $gs->{$k} = $pSession->data->{$k};
} }
} }
} }
@ -214,7 +214,7 @@ sub extractFormInfo {
# b) if UserDB is Google, ask for exported variables # b) if UserDB is Google, ask for exported variables
if ( $self->get_module('user') eq 'Google' ) { if ( $self->get_module('user') eq 'Google' ) {
my $u; my $u;
while ( my ( $v, $k ) = each %{ $self->{exportedVars} } ) { foreach my $k ( values %{ $self->{exportedVars} } ) {
next if ( $k eq 'email' ); next if ( $k eq 'email' );
# Check if wanted attribute is known by Google # Check if wanted attribute is known by Google