| 1 | package Net::Simplify::DomainList; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Net::Simplify::DomainList - Simplify Commerce class representing a list of domain objects | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use Net::Simplify; | ||
| 10 | |||
| 11 | $Net::Simplify::public_key = 'YOUR PUBLIC KEY'; | ||
| 12 | $Net::Simplify::private_key = 'YOUR PRIVATE KEY'; | ||
| 13 | |||
| 14 | my $ret = Net::Simplify::Payment->list({}); | ||
| 15 | |||
| 16 | printf "Total: %d\n", $ret->total; | ||
| 17 | foreach my $o ($ret->list) { | ||
| 18 | printf " %s\n", $o->{id}; | ||
| 19 | } | ||
| 20 | |||
| 21 | =head1 DESCRIPTION | ||
| 22 | |||
| 23 | Class for holding results from a list method on a domain class. | ||
| 24 | |||
| 25 | =head1 METHODS | ||
| 26 | |||
| 27 | =head3 total() | ||
| 28 | |||
| 29 | The total number of domain objects matching the search criteria used to generate the list. | ||
| 30 | |||
| 31 | =head3 size() | ||
| 32 | |||
| 33 | The number of domain objects in the list. | ||
| 34 | |||
| 35 | =head3 list() | ||
| 36 | |||
| 37 | The list of domain objects. | ||
| 38 | |||
| 39 | =head1 SEE ALSO | ||
| 40 | |||
| 41 | L<Net::Simplify>, | ||
| 42 | L<Net::Simplify::Domain>, | ||
| 43 | L<http://www.simplify.com> | ||
| 44 | |||
| 45 | =head1 VERSION | ||
| 46 | |||
| 47 | 1.6.0 | ||
| 48 | |||
| 49 | =head1 LICENSE | ||
| 50 | |||
| 51 | Copyright (c) 2013 - 2022 MasterCard International Incorporated | ||
| 52 | All rights reserved. | ||
| 53 | |||
| 54 | Redistribution and use in source and binary forms, with or without modification, are | ||
| 55 | permitted provided that the following conditions are met: | ||
| 56 | |||
| 57 | Redistributions of source code must retain the above copyright notice, this list of | ||
| 58 | conditions and the following disclaimer. | ||
| 59 | Redistributions in binary form must reproduce the above copyright notice, this list of | ||
| 60 | conditions and the following disclaimer in the documentation and/or other materials | ||
| 61 | provided with the distribution. | ||
| 62 | Neither the name of the MasterCard International Incorporated nor the names of its | ||
| 63 | contributors may be used to endorse or promote products derived from this software | ||
| 64 | without specific prior written permission. | ||
| 65 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
| 66 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 67 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
| 68 | SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 69 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
| 70 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| 71 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
| 72 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
| 73 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 74 | SUCH DAMAGE. | ||
| 75 | |||
| 76 | =cut | ||
| 77 | |||
| 78 | use 5.006; | ||
| 79 | use strict; | ||
| 80 | use warnings FATAL => 'all'; | ||
| 81 | |||
| 82 | sub new { | ||
| 83 | |||
| 84 | my ($class, $params, $domain_class, $auth) = @_; | ||
| 85 | |||
| 86 | my $self = { | ||
| 87 | total => $params->{total}, | ||
| 88 | max => $params->{max}, | ||
| 89 | offset => $params->{offset}, | ||
| 90 | filter => $params->{filter}, | ||
| 91 | sorting => $params->{sorting}, | ||
| 92 | list => [] | ||
| 93 | }; | ||
| 94 | |||
| 95 | foreach my $obj (@{$params->{list}}) { | ||
| 96 | my $domain = $domain_class->new($obj, $auth); | ||
| 97 | push(@{$self->{list}}, $domain); | ||
| 98 | } | ||
| 99 | |||
| 100 | bless $self, $class; | ||
| 101 | } | ||
| 102 | |||
| 103 | sub total { | ||
| 104 | my ($self) = @_; | ||
| 105 | |||
| 106 | $self->{total}; | ||
| 107 | } | ||
| 108 | |||
| 109 | sub list { | ||
| 110 | my ($self) = @_; | ||
| 111 | |||
| 112 | @{$self->{list}}; | ||
| 113 | } | ||
| 114 | |||
| 115 | sub size { | ||
| 116 | my ($self) = @_; | ||
| 117 | |||
| 118 | my @list = @{$self->{list}}; | ||
| 119 | |||
| 120 | my $size = @list; | ||
| 121 | |||
| 122 | $size; | ||
| 123 | } | ||
| 124 | |||
| 125 | 1; | ||
| 126 |