| 1 | package Net::Simplify::Domain; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Net::Simplify::Domain - Simplify Commerce domain object base class | ||
| 6 | |||
| 7 | =head1 DESCRIPTION | ||
| 8 | |||
| 9 | Base class for all Simplify Commerce domain object classes. Each domain object is represented | ||
| 10 | as a hierarchy of hash maps. | ||
| 11 | |||
| 12 | =head2 METHODS | ||
| 13 | |||
| 14 | =head3 C<merge($hash)> | ||
| 15 | |||
| 16 | Merges the hash map C<$hash> into the hash map of the object overwriting existing key mappings. | ||
| 17 | |||
| 18 | =head3 C<clear()> | ||
| 19 | |||
| 20 | Removes all entries from the object's hash map. | ||
| 21 | |||
| 22 | =head1 SEE ALSO | ||
| 23 | |||
| 24 | L<Net::Simplify>, | ||
| 25 | L<http://www.simplify.com> | ||
| 26 | |||
| 27 | =head1 VERSION | ||
| 28 | |||
| 29 | 1.6.0 | ||
| 30 | |||
| 31 | =head1 LICENSE | ||
| 32 | |||
| 33 | Copyright (c) 2013 - 2022 MasterCard International Incorporated | ||
| 34 | All rights reserved. | ||
| 35 | |||
| 36 | Redistribution and use in source and binary forms, with or without modification, are | ||
| 37 | permitted provided that the following conditions are met: | ||
| 38 | |||
| 39 | Redistributions of source code must retain the above copyright notice, this list of | ||
| 40 | conditions and the following disclaimer. | ||
| 41 | Redistributions in binary form must reproduce the above copyright notice, this list of | ||
| 42 | conditions and the following disclaimer in the documentation and/or other materials | ||
| 43 | provided with the distribution. | ||
| 44 | Neither the name of the MasterCard International Incorporated nor the names of its | ||
| 45 | contributors may be used to endorse or promote products derived from this software | ||
| 46 | without specific prior written permission. | ||
| 47 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
| 48 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 49 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
| 50 | SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 51 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
| 52 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| 53 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
| 54 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
| 55 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 56 | SUCH DAMAGE. | ||
| 57 | |||
| 58 | =cut | ||
| 59 | |||
| 60 | use 5.006; | ||
| 61 | use strict; | ||
| 62 | use warnings FATAL => 'all'; | ||
| 63 | |||
| 64 | sub new { | ||
| 65 | |||
| 66 | my ($class, $params, $auth) = @_; | ||
| 67 | |||
| 68 | $params->{_authentication} = $auth; | ||
| 69 | |||
| 70 | bless $params, $class | ||
| 71 | } | ||
| 72 | |||
| 73 | |||
| 74 | sub merge { | ||
| 75 | my ($self, $hash) = @_; | ||
| 76 | |||
| 77 | for my $k (keys %$hash) { | ||
| 78 | if (ref $hash->{$k} eq 'HASH') { | ||
| 79 | if (!defined $self->{$k}) { | ||
| 80 | $self->{$k} = $hash->{$k}; | ||
| 81 | } else { | ||
| 82 | if (ref $self->{$k} ne 'HASH') { | ||
| 83 | $self->{$k} = {}; | ||
| 84 | } | ||
| 85 | merge($self->{$k}, $hash->{$k}); | ||
| 86 | } | ||
| 87 | } else { | ||
| 88 | $self->{$k} = $hash->{$k}; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | sub clear { | ||
| 94 | my ($self) = @_; | ||
| 95 | |||
| 96 | foreach my $k (keys %{$self}) { | ||
| 97 | delete $self->{$k}; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | 1; | ||
| 102 |