diff --git a/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache b/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache index 5d5dc0cdb968..79528dad23b4 100644 --- a/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/APIClient.mustache @@ -17,6 +17,8 @@ use Log::Any qw($log); use Carp; use Module::Runtime qw(use_module); +use WWW::{{invokerPackage}}::Configuration; + sub new { my $class = shift; diff --git a/modules/swagger-codegen/src/main/resources/perl/Configuration.mustache b/modules/swagger-codegen/src/main/resources/perl/Configuration.mustache index 0967dc136c32..07ff9b87785a 100644 --- a/modules/swagger-codegen/src/main/resources/perl/Configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/Configuration.mustache @@ -7,10 +7,12 @@ use utf8; use Log::Any qw($log); use Carp; +use WWW::{{invokerPackage}}::APIClient; + # class/static variables -my $api_client = WWW::SwaggerClient::APIClient->new; -my $http_timeout = 180; -my $http_user_agent = 'Perl-Swagger'; +our $api_client; +our $http_timeout = 180; +our $http_user_agent = 'Perl-Swagger'; 1; diff --git a/modules/swagger-codegen/src/main/resources/perl/api.mustache b/modules/swagger-codegen/src/main/resources/perl/api.mustache index 4996534c35e6..54647ca4b8f0 100644 --- a/modules/swagger-codegen/src/main/resources/perl/api.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/api.mustache @@ -27,11 +27,10 @@ use Exporter; use Carp qw( croak ); use Log::Any qw($log); +use WWW::{{invokerPackage}}::APIClient; +use WWW::{{invokerPackage}}::Configuration; {{#operations}} - -use WWW::{{invokerPackage}}::APIClient; - our @EXPORT_OK = qw( {{#operation}}{{{nickname}}} {{/operation}} @@ -39,7 +38,7 @@ our @EXPORT_OK = qw( sub new { my $class = shift; - my $default_api_client = WWW::{{invokerPackage}}::APIClient->new; + my $default_api_client = $WWW::{{invokerPackage}}::Configuration::api_client ? $WWW::{{invokerPackage}}::Configuration::api_client : WWW::{{invokerPackage}}::APIClient->new; my (%self) = ( 'api_client' => $default_api_client, @_ diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm index cf4ec0db4f39..3f6aaf9ff87f 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/APIClient.pm @@ -17,6 +17,8 @@ use Log::Any qw($log); use Carp; use Module::Runtime qw(use_module); +use WWW::SwaggerClient::Configuration; + sub new { my $class = shift; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Configuration.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Configuration.pm index b8c57e668436..e3da7f3332d5 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Configuration.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Configuration.pm @@ -7,10 +7,12 @@ use utf8; use Log::Any qw($log); use Carp; +use WWW::SwaggerClient::APIClient; + # class/static variables -my $api_client = WWW::SwaggerClient::APIClient->new; -my $http_timeout = 180; -my $http_user_agent = 'Perl-Swagger'; +our $api_client; +our $http_timeout = 180; +our $http_user_agent = 'Perl-Swagger'; 1; diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm index e796022bad1a..077e7cbc45f0 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/PetApi.pm @@ -27,9 +27,8 @@ use Exporter; use Carp qw( croak ); use Log::Any qw($log); - - use WWW::SwaggerClient::APIClient; +use WWW::SwaggerClient::Configuration; our @EXPORT_OK = qw( update_pet @@ -45,7 +44,7 @@ our @EXPORT_OK = qw( sub new { my $class = shift; - my $default_api_client = WWW::SwaggerClient::APIClient->new; + 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, @_ diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm index e457c99cac28..0c2d25d02361 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/StoreApi.pm @@ -27,9 +27,8 @@ use Exporter; use Carp qw( croak ); use Log::Any qw($log); - - use WWW::SwaggerClient::APIClient; +use WWW::SwaggerClient::Configuration; our @EXPORT_OK = qw( get_inventory @@ -41,7 +40,7 @@ our @EXPORT_OK = qw( sub new { my $class = shift; - my $default_api_client = WWW::SwaggerClient::APIClient->new; + 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, @_ diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm index ece7f3e544b4..ecdd8eab9c28 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/UserApi.pm @@ -27,9 +27,8 @@ use Exporter; use Carp qw( croak ); use Log::Any qw($log); - - use WWW::SwaggerClient::APIClient; +use WWW::SwaggerClient::Configuration; our @EXPORT_OK = qw( create_user @@ -45,7 +44,7 @@ our @EXPORT_OK = qw( sub new { my $class = shift; - my $default_api_client = WWW::SwaggerClient::APIClient->new; + 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, @_ diff --git a/samples/client/petstore/perl/test.pl b/samples/client/petstore/perl/test.pl index eb06f786f98e..f1e819be5ced 100755 --- a/samples/client/petstore/perl/test.pl +++ b/samples/client/petstore/perl/test.pl @@ -6,6 +6,7 @@ use strict; use warnings; use WWW::SwaggerClient::PetApi; use WWW::SwaggerClient::APIClient; +use WWW::SwaggerClient::Configuration; use WWW::SwaggerClient::Object::Pet; use WWW::SwaggerClient::Object::Tag; use WWW::SwaggerClient::Object::Category; @@ -13,6 +14,8 @@ use JSON; use Data::Dumper; use DateTime; +$WWW::SwaggerClient::Configuration::http_user_agent = 'Perl-Swagger-Test'; + my $api = WWW::SwaggerClient::PetApi->new(); my $pet_id = 10008;