Hide Show 12 lines of Pod
require
5.6.0;
use
base (
"Class::Accessor"
,
"Class::Data::Inheritable"
);
Hide Show 13 lines of Pod
__PACKAGE__->mk_classdata(
'attribute_map'
=> {});
__PACKAGE__->mk_classdata(
'openapi_types'
=> {});
__PACKAGE__->mk_classdata(
'method_documentation'
=> {});
__PACKAGE__->mk_classdata(
'class_documentation'
=> {});
__PACKAGE__->mk_classdata(
'openapi_nullable'
=> {});
sub
new {
my
(
$class
,
%args
) =
@_
;
my
$self
=
bless
{},
$class
;
$self
->init(
%args
);
return
$self
;
}
sub
init
{
my
(
$self
,
%args
) =
@_
;
foreach
my
$attribute
(
keys
%{
$self
->attribute_map}) {
my
$args_key
=
$self
->attribute_map->{
$attribute
};
$self
->
$attribute
(
$args
{
$args_key
} );
}
}
sub
to_hash {
my
$self
=
shift
;
my
$_hash
= decode_json(JSON()->new->allow_blessed->convert_blessed->encode(
$self
));
return
$_hash
;
}
sub
TO_JSON {
my
$self
=
shift
;
my
$_data
= {};
foreach
my
$_key
(
keys
%{
$self
->attribute_map}) {
$_data
->{
$self
->attribute_map->{
$_key
}} =
$self
->{
$_key
};
}
return
$_data
;
}
sub
from_hash {
my
(
$self
,
$hash
) =
@_
;
while
(
my
(
$_key
,
$_type
) =
each
%{
$self
->openapi_types} ) {
my
$_json_attribute
=
$self
->attribute_map->{
$_key
};
my
$_is_nullable
= (
$self
->openapi_nullable->{
$_key
} ||
'false'
) eq
'true'
;
if
(
$_type
=~ /^array\[(.+)\]$/i) {
my
$_subclass
= $1;
my
@_array
= ();
foreach
my
$_element
(@{
$hash
->{
$_json_attribute
}}) {
push
@_array
,
$self
->_deserialize(
$_subclass
,
$_element
,
$_is_nullable
);
}
$self
->{
$_key
} = \
@_array
;
}
elsif
(
$_type
=~ /^hash\[string,(.+)\]$/i) {
my
$_subclass
= $1;
my
%_hash
= ();
while
(
my
(
$_key
,
$_element
) =
each
%{
$hash
->{
$_json_attribute
}}) {
$_hash
{
$_key
} =
$self
->_deserialize(
$_subclass
,
$_element
,
$_is_nullable
);
}
$self
->{
$_key
} = \
%_hash
;
}
elsif
(
exists
$hash
->{
$_json_attribute
}) {
$self
->{
$_key
} =
$self
->_deserialize(
$_type
,
$hash
->{
$_json_attribute
},
$_is_nullable
);
}
else
{
$log
->debugf(
"Warning: %s (%s) does not exist in input hash\n"
,
$_key
,
$_json_attribute
);
}
}
return
$self
;
}
sub
_deserialize {
my
(
$self
,
$type
,
$data
,
$is_nullable
) =
@_
;
$log
->debugf(
"deserializing %s with %s"
,Dumper(
$data
),
$type
);
if
(!(
defined
$data
) &&
$is_nullable
) {
return
undef
;
}
if
(
$type
eq
'DateTime'
) {
return
DateTime->from_epoch(
epoch
=> str2time(
$data
));
}
elsif
(
grep
( /^
$type
$/, (
'int'
,
'double'
,
'string'
,
'boolean'
))) {
return
$data
;
}
else
{
my
$_instance
=
eval
"WebService::Fastly::Object::$type->new()"
;
return
$_instance
->from_hash(
$data
);
}
}
__PACKAGE__->class_documentation({
description
=>
''
,
class
=>
'Header'
,
required
=> [],
} );
__PACKAGE__->method_documentation({
'action'
=> {
datatype
=>
'string'
,
base_name
=>
'action'
,
description
=>
'Accepts a string value.'
,
format
=>
''
,
read_only
=>
'false'
,
},
'cache_condition'
=> {
datatype
=>
'string'
,
base_name
=>
'cache_condition'
,
description
=>
'Name of the cache condition controlling when this configuration applies.'
,
format
=>
''
,
read_only
=>
'false'
,
},
'dst'
=> {
datatype
=>
'string'
,
base_name
=>
'dst'
,
description
=>
'Header to set.'
,
format
=>
''
,
read_only
=>
'false'
,
},
'name'
=> {
datatype
=>
'string'
,
base_name
=>
'name'
,
description
=>
'A handle to refer to this Header object.'
,
format
=>
''
,
read_only
=>
'false'
,
},
'regex'
=> {
datatype
=>
'string'
,
base_name
=>
'regex'
,
description
=>
'Regular expression to use. Only applies to `regex` and `regex_repeat` actions.'
,
format
=>
''
,
read_only
=>
'false'
,
},
'request_condition'
=> {
datatype
=>
'string'
,
base_name
=>
'request_condition'
,
description
=>
'Condition which, if met, will select this configuration during a request. Optional.'
,
format
=>
''
,
read_only
=>
'false'
,
},
'response_condition'
=> {
datatype
=>
'string'
,
base_name
=>
'response_condition'
,
description
=>
'Optional name of a response condition to apply.'
,
format
=>
''
,
read_only
=>
'false'
,
},
'src'
=> {
datatype
=>
'string'
,
base_name
=>
'src'
,
description
=>
'Variable to be used as a source for the header content. Does not apply to `delete` action.'
,
format
=>
''
,
read_only
=>
'false'
,
},
'substitution'
=> {
datatype
=>
'string'
,
base_name
=>
'substitution'
,
description
=>
'Value to substitute in place of regular expression. Only applies to `regex` and `regex_repeat` actions.'
,
format
=>
''
,
read_only
=>
'false'
,
},
'type'
=> {
datatype
=>
'string'
,
base_name
=>
'type'
,
description
=>
'Accepts a string value.'
,
format
=>
''
,
read_only
=>
'false'
,
},
});
__PACKAGE__->openapi_types( {
'action'
=>
'string'
,
'cache_condition'
=>
'string'
,
'dst'
=>
'string'
,
'name'
=>
'string'
,
'regex'
=>
'string'
,
'request_condition'
=>
'string'
,
'response_condition'
=>
'string'
,
'src'
=>
'string'
,
'substitution'
=>
'string'
,
'type'
=>
'string'
} );
__PACKAGE__->attribute_map( {
'action'
=>
'action'
,
'cache_condition'
=>
'cache_condition'
,
'dst'
=>
'dst'
,
'name'
=>
'name'
,
'regex'
=>
'regex'
,
'request_condition'
=>
'request_condition'
,
'response_condition'
=>
'response_condition'
,
'src'
=>
'src'
,
'substitution'
=>
'substitution'
,
'type'
=>
'type'
} );
__PACKAGE__->mk_accessors(
keys
%{__PACKAGE__->attribute_map});
__PACKAGE__->openapi_nullable( {
'cache_condition'
=>
'true'
,
'regex'
=>
'true'
,
'request_condition'
=>
'true'
,
'response_condition'
=>
'true'
,
'src'
=>
'true'
,
'substitution'
=>
'true'
,
} );
1;