Moved object classes' constructor into base class

This commit is contained in:
Dave Baird 2015-11-04 21:42:27 +01:00
parent 4264b74e40
commit f521680c0f
9 changed files with 77 additions and 235 deletions

View File

@ -11,7 +11,7 @@ use Log::Any qw($log);
use Date::Parse;
use DateTime;
use base "Class::Accessor";
use base ("Class::Accessor", "Class::Data::Inheritable");
#
@ -20,6 +20,22 @@ use base "Class::Accessor";
#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
#
__PACKAGE__->mk_classdata('attribute_map');
__PACKAGE__->mk_classdata('swagger_types');
# new object
sub new {
my ($class, %args) = @_;
my $self = bless {}, $class;
foreach my $attribute (keys %{$class->attribute_map}) {
my $args_key = $class->attribute_map->{$attribute};
$self->$attribute( $args{ $args_key } );
}
return $self;
}
# return perl hash
sub to_hash {
@ -30,9 +46,9 @@ sub to_hash {
sub TO_JSON {
my $self = shift;
my $_data = {};
foreach my $_key (keys %{$self->get_attribute_map}) {
foreach my $_key (keys %{$self->attribute_map}) {
if (defined $self->{$_key}) {
$_data->{$self->get_attribute_map->{$_key}} = $self->{$_key};
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
}
}
return $_data;
@ -43,8 +59,8 @@ sub from_hash {
my ($self, $hash) = @_;
# loop through attributes and use swagger_types to deserialize the data
while ( my ($_key, $_type) = each %{$self->get_swagger_types} ) {
my $_json_attribute = $self->get_attribute_map->{$_key};
while ( my ($_key, $_type) = each %{$self->swagger_types} ) {
my $_json_attribute = $self->attribute_map->{$_key};
if ($_type =~ /^array\[/i) { # array
my $_subclass = substr($_type, 6, -1);
my @_array = ();

View File

@ -21,39 +21,17 @@ use base "WWW::{{moduleName}}::Object::BaseObject";
#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
#
my $swagger_types = {
__PACKAGE__->swagger_types( {
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
};
} );
my $attribute_map = {
__PACKAGE__->attribute_map( {
{{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
};
} );
__PACKAGE__->mk_accessors(keys %$attribute_map);
# new object
sub new {
my ($class, %args) = @_;
my $self = {
{{#vars}}#{{#description}}{{{description}}}{{/description}}
'{{name}}' => $args{'{{baseName}}'}{{#hasMore}},
{{/hasMore}}{{/vars}}
};
return bless $self, $class;
}
# get swagger type of the attribute
sub get_swagger_types {
return $swagger_types;
}
# get attribute mappping
sub get_attribute_map {
return $attribute_map;
}
__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map});
1;
{{/model}}

View File

@ -19,43 +19,18 @@ use base "WWW::SwaggerClient::Object::BaseObject";
#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
#
my $swagger_types = {
__PACKAGE__->swagger_types( {
'code' => 'int',
'type' => 'string',
'message' => 'string'
};
} );
my $attribute_map = {
__PACKAGE__->attribute_map( {
'code' => 'code',
'type' => 'type',
'message' => 'message'
};
} );
__PACKAGE__->mk_accessors(keys %$attribute_map);
# new object
sub new {
my ($class, %args) = @_;
my $self = {
#
'code' => $args{'code'},
#
'type' => $args{'type'},
#
'message' => $args{'message'}
};
return bless $self, $class;
}
# get swagger type of the attribute
sub get_swagger_types {
return $swagger_types;
}
# get attribute mappping
sub get_attribute_map {
return $attribute_map;
}
__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map});
1;

View File

@ -11,7 +11,7 @@ use Log::Any qw($log);
use Date::Parse;
use DateTime;
use base "Class::Accessor";
use base ("Class::Accessor", "Class::Data::Inheritable");
#
@ -20,6 +20,22 @@ use base "Class::Accessor";
#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
#
__PACKAGE__->mk_classdata('attribute_map');
__PACKAGE__->mk_classdata('swagger_types');
# new object
sub new {
my ($class, %args) = @_;
my $self = bless {}, $class;
foreach my $attribute (keys %{$class->attribute_map}) {
my $args_key = $class->attribute_map->{$attribute};
$self->$attribute( $args{ $args_key } );
}
return $self;
}
# return perl hash
sub to_hash {
@ -30,9 +46,9 @@ sub to_hash {
sub TO_JSON {
my $self = shift;
my $_data = {};
foreach my $_key (keys %{$self->get_attribute_map}) {
foreach my $_key (keys %{$self->attribute_map}) {
if (defined $self->{$_key}) {
$_data->{$self->get_attribute_map->{$_key}} = $self->{$_key};
$_data->{$self->attribute_map->{$_key}} = $self->{$_key};
}
}
return $_data;
@ -43,8 +59,8 @@ sub from_hash {
my ($self, $hash) = @_;
# loop through attributes and use swagger_types to deserialize the data
while ( my ($_key, $_type) = each %{$self->get_swagger_types} ) {
my $_json_attribute = $self->get_attribute_map->{$_key};
while ( my ($_key, $_type) = each %{$self->swagger_types} ) {
my $_json_attribute = $self->attribute_map->{$_key};
if ($_type =~ /^array\[/i) { # array
my $_subclass = substr($_type, 6, -1);
my @_array = ();

View File

@ -19,39 +19,16 @@ use base "WWW::SwaggerClient::Object::BaseObject";
#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
#
my $swagger_types = {
__PACKAGE__->swagger_types( {
'id' => 'int',
'name' => 'string'
};
} );
my $attribute_map = {
__PACKAGE__->attribute_map( {
'id' => 'id',
'name' => 'name'
};
} );
__PACKAGE__->mk_accessors(keys %$attribute_map);
# new object
sub new {
my ($class, %args) = @_;
my $self = {
#
'id' => $args{'id'},
#
'name' => $args{'name'}
};
return bless $self, $class;
}
# get swagger type of the attribute
sub get_swagger_types {
return $swagger_types;
}
# get attribute mappping
sub get_attribute_map {
return $attribute_map;
}
__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map});
1;

View File

@ -19,55 +19,24 @@ use base "WWW::SwaggerClient::Object::BaseObject";
#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
#
my $swagger_types = {
__PACKAGE__->swagger_types( {
'id' => 'int',
'pet_id' => 'int',
'quantity' => 'int',
'ship_date' => 'DateTime',
'status' => 'string',
'complete' => 'boolean'
};
} );
my $attribute_map = {
__PACKAGE__->attribute_map( {
'id' => 'id',
'pet_id' => 'petId',
'quantity' => 'quantity',
'ship_date' => 'shipDate',
'status' => 'status',
'complete' => 'complete'
};
} );
__PACKAGE__->mk_accessors(keys %$attribute_map);
# new object
sub new {
my ($class, %args) = @_;
my $self = {
#
'id' => $args{'id'},
#
'pet_id' => $args{'petId'},
#
'quantity' => $args{'quantity'},
#
'ship_date' => $args{'shipDate'},
#Order Status
'status' => $args{'status'},
#
'complete' => $args{'complete'}
};
return bless $self, $class;
}
# get swagger type of the attribute
sub get_swagger_types {
return $swagger_types;
}
# get attribute mappping
sub get_attribute_map {
return $attribute_map;
}
__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map});
1;

View File

@ -19,55 +19,24 @@ use base "WWW::SwaggerClient::Object::BaseObject";
#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
#
my $swagger_types = {
__PACKAGE__->swagger_types( {
'id' => 'int',
'category' => 'Category',
'name' => 'string',
'photo_urls' => 'ARRAY[string]',
'tags' => 'ARRAY[Tag]',
'status' => 'string'
};
} );
my $attribute_map = {
__PACKAGE__->attribute_map( {
'id' => 'id',
'category' => 'category',
'name' => 'name',
'photo_urls' => 'photoUrls',
'tags' => 'tags',
'status' => 'status'
};
} );
__PACKAGE__->mk_accessors(keys %$attribute_map);
# new object
sub new {
my ($class, %args) = @_;
my $self = {
#
'id' => $args{'id'},
#
'category' => $args{'category'},
#
'name' => $args{'name'},
#
'photo_urls' => $args{'photoUrls'},
#
'tags' => $args{'tags'},
#pet status in the store
'status' => $args{'status'}
};
return bless $self, $class;
}
# get swagger type of the attribute
sub get_swagger_types {
return $swagger_types;
}
# get attribute mappping
sub get_attribute_map {
return $attribute_map;
}
__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map});
1;

View File

@ -19,39 +19,16 @@ use base "WWW::SwaggerClient::Object::BaseObject";
#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
#
my $swagger_types = {
__PACKAGE__->swagger_types( {
'id' => 'int',
'name' => 'string'
};
} );
my $attribute_map = {
__PACKAGE__->attribute_map( {
'id' => 'id',
'name' => 'name'
};
} );
__PACKAGE__->mk_accessors(keys %$attribute_map);
# new object
sub new {
my ($class, %args) = @_;
my $self = {
#
'id' => $args{'id'},
#
'name' => $args{'name'}
};
return bless $self, $class;
}
# get swagger type of the attribute
sub get_swagger_types {
return $swagger_types;
}
# get attribute mappping
sub get_attribute_map {
return $attribute_map;
}
__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map});
1;

View File

@ -19,7 +19,7 @@ use base "WWW::SwaggerClient::Object::BaseObject";
#NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
#
my $swagger_types = {
__PACKAGE__->swagger_types( {
'id' => 'int',
'username' => 'string',
'first_name' => 'string',
@ -28,9 +28,9 @@ my $swagger_types = {
'password' => 'string',
'phone' => 'string',
'user_status' => 'int'
};
} );
my $attribute_map = {
__PACKAGE__->attribute_map( {
'id' => 'id',
'username' => 'username',
'first_name' => 'firstName',
@ -39,43 +39,8 @@ my $attribute_map = {
'password' => 'password',
'phone' => 'phone',
'user_status' => 'userStatus'
};
} );
__PACKAGE__->mk_accessors(keys %$attribute_map);
# new object
sub new {
my ($class, %args) = @_;
my $self = {
#
'id' => $args{'id'},
#
'username' => $args{'username'},
#
'first_name' => $args{'firstName'},
#
'last_name' => $args{'lastName'},
#
'email' => $args{'email'},
#
'password' => $args{'password'},
#
'phone' => $args{'phone'},
#User Status
'user_status' => $args{'userStatus'}
};
return bless $self, $class;
}
# get swagger type of the attribute
sub get_swagger_types {
return $swagger_types;
}
# get attribute mappping
sub get_attribute_map {
return $attribute_map;
}
__PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map});
1;