File Coverage

blib/lib/WebService/Xero/Organisation.pm
Criterion Covered Total %
statement 19 24 79.1
branch 3 6 50.0
condition 2 6 33.3
subroutine 6 7 85.7
pod 3 3 100.0
total 33 46 71.7


line stmt bran cond sub pod time code
1             package WebService::Xero::Organisation;
2              
3 4     4   82665 use 5.006;
  4         12  
4 4     4   18 use strict;
  4         6  
  4         68  
5 4     4   13 use warnings;
  4         7  
  4         82  
6 4     4   14 use Carp;
  4         5  
  4         1568  
7              
8             =head1 NAME
9              
10             WebService::Xero::Organisation - Object encapulates Organisation data returned by API
11              
12             =head1 VERSION
13              
14             Version 0.11
15              
16             =cut
17              
18             our $VERSION = '0.11';
19              
20             our @PROPERTIES = qw/APIKey Name LegalName PaysTax Version BaseCurrency CountryCode IsDemoCompany OrganisationStatus
21             RegistrationNumber TaxNumber FinancialYearEndDay FinancialYearEndMonth
22             SalesTaxBasis SalesTaxPeriod DefaultSalesTax DefaultPurchasesTax PeriodLockDate EndOfYearLockDate
23             CreatedDateUTC OrganisationEntityType OrganisationType Timezone ShortCode LineOfBusiness
24             Addresses Phones ExternalLinks PaymentTerms
25             /;
26              
27             ## ValidationErrors Warnings
28              
29             =head1 SYNOPSIS
30              
31             Object to describe an Organisation record as specified by Xero API and the associated DTD at
32             L.
33              
34             Perhaps a little code snippet.
35              
36             use WebService::Xero::Organisation;
37              
38             my $org = WebService::Xero::Organisation->new();
39            
40             or
41              
42             my $org = $xero_agent->api_account_organisation();
43              
44              
45             =head1 METHODS
46              
47             =head2 new()
48              
49             =cut
50              
51             sub new
52             {
53 1     1 1 727 my ( $class, %params ) = @_;
54              
55             my $self = bless
56             {
57             API_URL => 'https://api.xero.com/api.xro/2.0/organisation',
58             debug => $params{debug} ## NOT REALLY USED YET
59 1         3 }, $class;
60 1         2 foreach my $key (@PROPERTIES) {
61             ## $self->{$key} = $params{$key} || ''
62 29 50       56 $self->{$key} = defined $params{$key} ? $params{$key} : ''; ## thanks to https://metacpan.org/author/STEVEB
63             }
64              
65 1         6 return $self; #->_validate_agent(); ## derived classes will validate this
66              
67             }
68              
69              
70             =head2 new_from_api_data()
71              
72             creates a new instance from the data provided by querying the API organisation end point
73             ( typically handled by WebService::Xero::Agent->api_account_organisation() which calls this method )
74              
75             =cut
76              
77             sub new_from_api_data
78             {
79 0     0 1 0 my ( $self, $data ) = @_;
80 0 0 0     0 return $self->new( %{$data->{Organisations}[0]} ) if ( ref($data->{Organisations}) eq 'ARRAY' and scalar(@{$data->{Organisations}})==1 );
  0         0  
  0         0  
81 0         0 return $self->new( debug=> $data );
82              
83             }
84              
85             =head2 as_text()
86              
87             Returns a string with Carriage returns of each unique( non hash or array )
88             property - useful for debugging. NB - doesn't include Array or Hash properties
89              
90             =cut
91              
92              
93             sub as_text
94             {
95 1     1 1 2 my ( $self ) = @_;
96              
97              
98             # return join("\n", map { "$_ : $self->{$_}" if (defined $self->{$_} and $_ !~ /Addresses|Phones|ExternalLinks|PaymentTerms/m ) } @PROPERTIES); ## this works ok
99 1 100 66     2 return "Organisation:\n" . join("\n", map { "$_ : $self->{$_}" if (defined $self->{$_} and ref($self->{$_}) !~ /ARRAY|HASH/m ) } @PROPERTIES); ## this looks a little better?
  29         189  
100             }
101              
102              
103              
104             =head1 TODO
105              
106             consider inclusion of Locale modules - Locale::Currency and Locale::Country
107              
108              
109             =head1 AUTHOR
110              
111             Peter Scott, C<< >>
112              
113              
114             =head1 REFERENCE
115              
116              
117             =head1 BUGS
118              
119             Please report any bugs or feature requests to C, or through
120             the web interface at L. I will be notified, and then you'll
121             automatically be notified of progress on your bug as I make changes.
122              
123              
124              
125              
126             =head1 SUPPORT
127              
128             You can find documentation for this module with the perldoc command.
129              
130             perldoc WebService::Xero::Organisation
131              
132              
133             You can also look for information at:
134              
135             =over 4
136              
137             =item * Xero Developer API Docs
138              
139             L
140              
141             =item * Xero API Schemas
142              
143             L
144              
145             =item * Xero API Schema Organisation
146              
147             L
148              
149             =back
150              
151              
152             =head1 ACKNOWLEDGEMENTS
153              
154              
155             =head1 LICENSE AND COPYRIGHT
156              
157             Copyright 2016 Peter Scott.
158              
159             This program is free software; you can redistribute it and/or modify it
160             under the terms of the the Artistic License (2.0). You may obtain a
161             copy of the full license at:
162              
163             L
164              
165             Any use, modification, and distribution of the Standard or Modified
166             Versions is governed by this Artistic License. By using, modifying or
167             distributing the Package, you accept this license. Do not use, modify,
168             or distribute the Package, if you do not accept this license.
169              
170             If your Modified Version has been derived from a Modified Version made
171             by someone other than you, you are nevertheless required to ensure that
172             your Modified Version complies with the requirements of this license.
173              
174             This license does not grant you the right to use any trademark, service
175             mark, tradename, or logo of the Copyright Holder.
176              
177             This license includes the non-exclusive, worldwide, free-of-charge
178             patent license to make, have made, use, offer to sell, sell, import and
179             otherwise transfer the Package with respect to any patent claims
180             licensable by the Copyright Holder that are necessarily infringed by the
181             Package. If you institute patent litigation (including a cross-claim or
182             counterclaim) against any party alleging that the Package constitutes
183             direct or contributory patent infringement, then this Artistic License
184             to you shall terminate on the date that such litigation is filed.
185              
186             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
187             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
188             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
189             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
190             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
191             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
192             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
193             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
194              
195              
196             =cut
197              
198             1; # End of WebService::Xero