| 1 | =begin comment | ||
| 2 | |||
| 3 | Copyright (c) 2026 Aspose.Cells Cloud | ||
| 4 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 5 | of this software and associated documentation files (the "Software"), to deal | ||
| 6 | in the Software without restriction, including without limitation the rights | ||
| 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 8 | copies of the Software, and to permit persons to whom the Software is | ||
| 9 | furnished to do so, subject to the following conditions: | ||
| 10 | |||
| 11 | The above copyright notice and this permission notice shall be included in all | ||
| 12 | copies or substantial portions of the Software. | ||
| 13 | |||
| 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 20 | SOFTWARE. | ||
| 21 | |||
| 22 | =end comment | ||
| 23 | |||
| 24 | =cut | ||
| 25 | |||
| 26 | package AsposeCellsCloud::Object::CopyOptions; | ||
| 27 | |||
| 28 | require 5.6.0; | ||
| 29 | use strict; | ||
| 30 | use warnings; | ||
| 31 | use utf8; | ||
| 32 | use JSON qw(decode_json); | ||
| 33 | use Data::Dumper; | ||
| 34 | use Module::Runtime qw(use_module); | ||
| 35 | use Log::Any qw($log); | ||
| 36 | use Date::Parse; | ||
| 37 | use DateTime; | ||
| 38 | |||
| 39 | |||
| 40 | |||
| 41 | use base ("Class::Accessor", "Class::Data::Inheritable"); | ||
| 42 | |||
| 43 | |||
| 44 | |||
| 45 | __PACKAGE__->mk_classdata('attribute_map' => {}); | ||
| 46 | __PACKAGE__->mk_classdata('swagger_types' => {}); | ||
| 47 | __PACKAGE__->mk_classdata('method_documentation' => {}); | ||
| 48 | __PACKAGE__->mk_classdata('class_documentation' => {}); | ||
| 49 | |||
| 50 | # new object | ||
| 51 | sub new { | ||
| 52 | my ($class, %args) = @_; | ||
| 53 | |||
| 54 | my $self = bless {}, $class; | ||
| 55 | |||
| 56 | foreach my $attribute (keys %{$class->attribute_map}) { | ||
| 57 | my $args_key = $class->attribute_map->{$attribute}; | ||
| 58 | $self->$attribute( $args{ $args_key } ); | ||
| 59 | } | ||
| 60 | |||
| 61 | return $self; | ||
| 62 | } | ||
| 63 | |||
| 64 | # return perl hash | ||
| 65 | sub to_hash { | ||
| 66 | return decode_json(JSON->new->convert_blessed->encode( shift )); | ||
| 67 | } | ||
| 68 | |||
| 69 | # used by JSON for serialization | ||
| 70 | sub TO_JSON { | ||
| 71 | my $self = shift; | ||
| 72 | my $_data = {}; | ||
| 73 | foreach my $_key (keys %{$self->attribute_map}) { | ||
| 74 | if (defined $self->{$_key}) { | ||
| 75 | $_data->{$self->attribute_map->{$_key}} = $self->{$_key}; | ||
| 76 | } | ||
| 77 | } | ||
| 78 | return $_data; | ||
| 79 | } | ||
| 80 | |||
| 81 | # from Perl hashref | ||
| 82 | sub from_hash { | ||
| 83 | my ($self, $hash) = @_; | ||
| 84 | |||
| 85 | # loop through attributes and use swagger_types to deserialize the data | ||
| 86 | while ( my ($_key, $_type) = each %{$self->swagger_types} ) { | ||
| 87 | my $_json_attribute = $self->attribute_map->{$_key}; | ||
| 88 | if ($_type =~ /^array\[/i) { # array | ||
| 89 | my $_subclass = substr($_type, 6, -1); | ||
| 90 | my @_array = (); | ||
| 91 | foreach my $_element (@{$hash->{$_json_attribute}}) { | ||
| 92 | push @_array, $self->_deserialize($_subclass, $_element); | ||
| 93 | } | ||
| 94 | $self->{$_key} = \@_array; | ||
| 95 | } elsif (exists $hash->{$_json_attribute}) { #hash(model), primitive, datetime | ||
| 96 | $self->{$_key} = $self->_deserialize($_type, $hash->{$_json_attribute}); | ||
| 97 | } else { | ||
| 98 | $log->debugf("Warning: %s (%s) does not exist in input hash\n", $_key, $_json_attribute); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | return $self; | ||
| 103 | } | ||
| 104 | |||
| 105 | # deserialize non-array data | ||
| 106 | sub _deserialize { | ||
| 107 | my ($self, $type, $data) = @_; | ||
| 108 | $log->debugf("deserializing %s with %s",Dumper($data), $type); | ||
| 109 | |||
| 110 | if ($type eq 'DateTime') { | ||
| 111 | return DateTime->from_epoch(epoch => str2time($data)); | ||
| 112 | } elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) { | ||
| 113 | return $data; | ||
| 114 | } else { # hash(model) | ||
| 115 | my $_instance = eval "AsposeCellsCloud::Object::$type->new()"; | ||
| 116 | return $_instance->from_hash($data); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | |||
| 121 | __PACKAGE__->class_documentation({description => 'Represents the copy options.', | ||
| 122 | class => 'CopyOptions', | ||
| 123 | required => [], # TODO | ||
| 124 | } ); | ||
| 125 | |||
| 126 | |||
| 127 | __PACKAGE__->method_documentation({ | ||
| 128 | 'column_character_width' => { | ||
| 129 | datatype => 'boolean', | ||
| 130 | base_name => 'ColumnCharacterWidth', | ||
| 131 | description => 'Indicates whether copying column width in unit of characters. ', | ||
| 132 | format => '', | ||
| 133 | read_only => '', | ||
| 134 | }, | ||
| 135 | 'copy_invalid_formulas_as_values' => { | ||
| 136 | datatype => 'boolean', | ||
| 137 | base_name => 'CopyInvalidFormulasAsValues', | ||
| 138 | description => 'If the formula is not valid for the dest destination, only copy values. ', | ||
| 139 | format => '', | ||
| 140 | read_only => '', | ||
| 141 | }, | ||
| 142 | 'copy_names' => { | ||
| 143 | datatype => 'boolean', | ||
| 144 | base_name => 'CopyNames', | ||
| 145 | description => 'Indicates whether copying the names. ', | ||
| 146 | format => '', | ||
| 147 | read_only => '', | ||
| 148 | }, | ||
| 149 | 'extend_to_adjacent_range' => { | ||
| 150 | datatype => 'boolean', | ||
| 151 | base_name => 'ExtendToAdjacentRange', | ||
| 152 | description => 'Indicates whether extend ranges when copying the range to adjacent range. ', | ||
| 153 | format => '', | ||
| 154 | read_only => '', | ||
| 155 | }, | ||
| 156 | 'refer_to_destination_sheet' => { | ||
| 157 | datatype => 'boolean', | ||
| 158 | base_name => 'ReferToDestinationSheet', | ||
| 159 | description => 'When copying the range in the same file and the chart refers to the source sheet, False means the copied chart`s data source will not be changed. True means the copied chart`s data source refers to the destination sheet. ', | ||
| 160 | format => '', | ||
| 161 | read_only => '', | ||
| 162 | }, | ||
| 163 | 'refer_to_sheet_with_same_name' => { | ||
| 164 | datatype => 'boolean', | ||
| 165 | base_name => 'ReferToSheetWithSameName', | ||
| 166 | description => 'In ms excel, when copying formulas which refer to other worksheets while copying a worksheet to another one, the copied formulas should refer to source workbook. However, for some situations user may need the copied formulas refer to worksheets with the same name in the same workbook, such as when those worksheets have been copied before this copy operation, then this property should be kept as true. ', | ||
| 167 | format => '', | ||
| 168 | read_only => '', | ||
| 169 | }, | ||
| 170 | 'copy_theme' => { | ||
| 171 | datatype => 'boolean', | ||
| 172 | base_name => 'CopyTheme', | ||
| 173 | description => '', | ||
| 174 | format => '', | ||
| 175 | read_only => '', | ||
| 176 | }, | ||
| 177 | }); | ||
| 178 | |||
| 179 | __PACKAGE__->swagger_types( { | ||
| 180 | 'column_character_width' => 'boolean', | ||
| 181 | 'copy_invalid_formulas_as_values' => 'boolean', | ||
| 182 | 'copy_names' => 'boolean', | ||
| 183 | 'extend_to_adjacent_range' => 'boolean', | ||
| 184 | 'refer_to_destination_sheet' => 'boolean', | ||
| 185 | 'refer_to_sheet_with_same_name' => 'boolean', | ||
| 186 | 'copy_theme' => 'boolean' | ||
| 187 | } ); | ||
| 188 | |||
| 189 | __PACKAGE__->attribute_map( { | ||
| 190 | 'column_character_width' => 'ColumnCharacterWidth', | ||
| 191 | 'copy_invalid_formulas_as_values' => 'CopyInvalidFormulasAsValues', | ||
| 192 | 'copy_names' => 'CopyNames', | ||
| 193 | 'extend_to_adjacent_range' => 'ExtendToAdjacentRange', | ||
| 194 | 'refer_to_destination_sheet' => 'ReferToDestinationSheet', | ||
| 195 | 'refer_to_sheet_with_same_name' => 'ReferToSheetWithSameName', | ||
| 196 | 'copy_theme' => 'CopyTheme' | ||
| 197 | } ); | ||
| 198 | |||
| 199 | __PACKAGE__->mk_accessors(keys %{__PACKAGE__->attribute_map}); | ||
| 200 | |||
| 201 | |||
| 202 | 1; |