Skip to content

Commit

Permalink
[#691] %MT::Captcha_Providers is now lexically scoped within a clos…
Browse files Browse the repository at this point in the history
…ure 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.
  • Loading branch information
jayallen committed Jan 25, 2011
1 parent 26f2324 commit 1b3dff5
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions lib/MT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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' => {
Expand All @@ -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 {
Expand Down

0 comments on commit 1b3dff5

Please sign in to comment.