From 1b3dff5d27236327a7fb5f2a025e0b236f97153a Mon Sep 17 00:00:00 2001 From: Jay Allen Date: Tue, 25 Jan 2011 15:35:11 -0800 Subject: [PATCH] [#691] `%MT::Captcha_Providers` is now lexically scoped within a closure and cannot be accessed/changed directly. Please use the `MT::captcha_provider()` and `MT::captcha_providers()` methods exclusively for accessing the variable. No mutator has been provided because the variable is populated by the `MT::init_captcha_providers()` method which is called by both accessors. --- lib/MT.pm | 60 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/lib/MT.pm b/lib/MT.pm index 2aa56a82d..c0988970c 100644 --- a/lib/MT.pm +++ b/lib/MT.pm @@ -3221,26 +3221,6 @@ HATENA }; } ## end sub core_commenter_authenticators -our %Captcha_Providers; - -sub captcha_provider { - my $self = shift; - my ($key) = @_; - $self->init_captcha_providers() unless %Captcha_Providers; - return $Captcha_Providers{$key}; -} - -sub captcha_providers { - my $self = shift; - $self->init_captcha_providers() unless %Captcha_Providers; - my $def = delete $Captcha_Providers{'mt_default'}; - my @vals = values %Captcha_Providers; - if ( defined($def) && $def->{condition}->() ) { - unshift @vals, $def; - } - @vals; -} - sub core_captcha_providers { return { 'mt_default' => { @@ -3257,16 +3237,38 @@ sub core_captcha_providers { }; } -sub init_captcha_providers { - my $self = shift; - my $providers = $self->registry("captcha_providers") || {}; - foreach my $provider ( keys %$providers ) { - delete $providers->{$provider} - if exists( $providers->{$provider}->{condition} ) - && !( $providers->{$provider}->{condition}->() ); +{ + our %Captcha_Providers; + + sub captcha_provider { + my $self = shift; + my ($key) = @_; + $self->init_captcha_providers() unless %Captcha_Providers; + return $Captcha_Providers{$key}; + } + + sub captcha_providers { + my $self = shift; + $self->init_captcha_providers() unless %Captcha_Providers; + my $def = delete $Captcha_Providers{'mt_default'}; + my @vals = values %Captcha_Providers; + if ( defined($def) && $def->{condition}->() ) { + unshift @vals, $def; + } + @vals; + } + + sub init_captcha_providers { + my $self = shift; + my $providers = $self->registry("captcha_providers") || {}; + foreach my $provider ( keys %$providers ) { + delete $providers->{$provider} + if exists( $providers->{$provider}->{condition} ) + && !( $providers->{$provider}->{condition}->() ); + } + %Captcha_Providers = %$providers; + $Captcha_Providers{$_}{key} ||= $_ for keys %Captcha_Providers; } - %Captcha_Providers = %$providers; - $Captcha_Providers{$_}{key} ||= $_ for keys %Captcha_Providers; } sub effective_captcha_provider {