forked from loafle/openapi-generator-original
Apply the singleton pattern to ApiClient
- make the api_client a singleton - remove it from the configuration namespace
This commit is contained in:
@@ -20,7 +20,9 @@ use Module::Runtime qw(use_module);
|
||||
|
||||
use WWW::SwaggerClient::Configuration;
|
||||
|
||||
sub new
|
||||
use base 'Class::Singleton';
|
||||
|
||||
sub _new_instance
|
||||
{
|
||||
my $class = shift;
|
||||
my (%args) = (
|
||||
|
||||
@@ -65,7 +65,7 @@ my %_apis = map { $_ =~ /^WWW::SwaggerClient::(.*)$/; $1 => $_ }
|
||||
|
||||
sub new {
|
||||
my ($class, %p) = (shift, @_);
|
||||
$p{api_client} = WWW::SwaggerClient::ApiClient->new(%p);
|
||||
$p{api_client} = WWW::SwaggerClient::ApiClient->instance(%p);
|
||||
return bless \%p, $class;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ use Carp;
|
||||
use constant VERSION => '1.0.0';
|
||||
|
||||
# class/static variables
|
||||
our $api_client;
|
||||
our $http_timeout = 180;
|
||||
our $http_user_agent = 'Perl-Swagger';
|
||||
|
||||
|
||||
@@ -38,9 +38,8 @@ __PACKAGE__->mk_classdata('class_documentation' => {}); # TODO
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $default_api_client = $WWW::SwaggerClient::Configuration::api_client ? $WWW::SwaggerClient::Configuration::api_client : WWW::SwaggerClient::ApiClient->new;
|
||||
my (%self) = (
|
||||
'api_client' => $default_api_client,
|
||||
'api_client' => WWW::SwaggerClient::ApiClient->instance,
|
||||
@_
|
||||
);
|
||||
|
||||
|
||||
@@ -38,9 +38,8 @@ __PACKAGE__->mk_classdata('class_documentation' => {}); # TODO
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $default_api_client = $WWW::SwaggerClient::Configuration::api_client ? $WWW::SwaggerClient::Configuration::api_client : WWW::SwaggerClient::ApiClient->new;
|
||||
my (%self) = (
|
||||
'api_client' => $default_api_client,
|
||||
'api_client' => WWW::SwaggerClient::ApiClient->instance,
|
||||
@_
|
||||
);
|
||||
|
||||
|
||||
@@ -38,9 +38,8 @@ __PACKAGE__->mk_classdata('class_documentation' => {}); # TODO
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $default_api_client = $WWW::SwaggerClient::Configuration::api_client ? $WWW::SwaggerClient::Configuration::api_client : WWW::SwaggerClient::ApiClient->new;
|
||||
my (%self) = (
|
||||
'api_client' => $default_api_client,
|
||||
'api_client' => WWW::SwaggerClient::ApiClient->instance,
|
||||
@_
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user