File Coverage

blib/lib/Net/OpenXchange.pm
Criterion Covered Total %
statement 5 7 71.4
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 8 10 80.0


line stmt bran cond sub pod time code
1 1     1   38537 use Modern::Perl;
  1         3  
  1         8  
2              
3             package Net::OpenXchange;
4             BEGIN {
5 1     1   218 $Net::OpenXchange::VERSION = '0.001';
6             }
7              
8 1     1   422 use Moose;
  0            
  0            
9             use namespace::autoclean;
10              
11             # ABSTRACT: Object-oriented interface to OpenXchange groupware
12              
13             use Carp;
14             use Net::OpenXchange::Connection;
15              
16             # Create attributes and builder methods for modules
17             BEGIN {
18             require Module::Pluggable;
19             Module::Pluggable->import(
20             sub_name => '_modules',
21             search_path => ['Net::OpenXchange::Module'],
22             require => 1,
23             );
24             foreach my $module (__PACKAGE__->_modules) {
25             my $attr;
26             if ($module =~ /^.+::(.+?)$/) {
27             $attr = lc $1;
28             }
29             else {
30             # perlcritic suggested to only use match variables in conditional
31             # blocks
32             confess "Module::Pluggable returned wrong module name: $module";
33             }
34              
35             __PACKAGE__->meta->add_attribute(
36             $attr,
37             is => 'ro',
38             isa => $module,
39             init_arg => undef,
40             lazy => 1,
41             builder => "_build_$attr",
42             );
43             __PACKAGE__->meta->add_method(
44             "_build_$attr" => sub {
45             my ($self) = @_;
46             return $module->new(conn => $self->conn);
47             }
48             );
49             }
50             }
51              
52             has uri => (
53             is => 'ro',
54             isa => 'Str',
55             required => 1,
56             );
57              
58             has login => (
59             is => 'ro',
60             isa => 'Str',
61             required => 1,
62             );
63              
64             has password => (
65             is => 'ro',
66             isa => 'Str',
67             required => 1,
68             );
69              
70             has conn => (
71             is => 'ro',
72             isa => 'Net::OpenXchange::Connection',
73             init_arg => undef,
74             lazy => 1,
75             builder => '_build_conn',
76             );
77              
78             sub _build_conn {
79             my ($self) = @_;
80             return Net::OpenXchange::Connection->new(
81             uri => $self->uri,
82             login => $self->login,
83             password => $self->password,
84             );
85             }
86              
87             sub BUILD {
88             my ($self) = @_;
89             $self->conn; # force connection
90             return;
91             }
92              
93             __PACKAGE__->meta->make_immutable;
94             1;
95              
96              
97             __END__
98             =pod
99              
100             =head1 NAME
101              
102             Net::OpenXchange - Object-oriented interface to OpenXchange groupware
103              
104             =head1 VERSION
105              
106             version 0.001
107              
108             =head1 SYNOPSIS
109              
110             Net::OpenXchange is new and very unfinished code. Its coverage of the OX API
111             actions, objects and attributes is limited. However it already proved useful,
112             so I decided to release this early experimental version. If you choose to use
113             it, I would really appreciate bug reports, with or without attached patches :-)
114             I'd also welcome help adding support for more parts of the OpenXchange API.
115              
116             Net::OpenXchange is the frontend to all packages of Net::OpenXchange.
117              
118             use Modern::Perl;
119             use Net::OpenXchange;
120             use DateTime::Format::Mail;
121              
122             my $ox = Net::OpenXchange->new(
123             uri => 'https://ox.example.org/ajax',
124             login => 'myuser',
125             password => 'mypassword',
126             );
127              
128             my $folder = $ox->folder->resolve_path('Public folders', 'Calendar');
129             my @appointments = $ox->calendar->all(
130             folder => $folder,
131             start => DateTime->new(year => 2010, month => 1, day => 1),
132             end => DateTime->new(year => 2010, month => 12, day => 31),
133             );
134              
135             foreach (@appointments) {
136             say 'Start: ', DateTime::Format::Mail->format_datetime($_->start_date);
137             say 'End: ', DateTime::Format::Mail->format_datetime($_->end_date);
138             say 'Title: ', $_->title;
139             say '';
140             }
141              
142             Net::OpenXchange connects to the server when creating an object instance and
143             disconnects on object destruction. All errors are raised as exceptions.
144              
145             All Net::OpenXchange::Module::* packages are available as attributes on this
146             class - for example
147             L<Net::OpenXchange::Module::Folder|Net::OpenXchange::Module::Folder> becomes
148             $ox->folder. See the documentation for these packages.
149              
150             =head1 ATTRIBUTES
151              
152             =head2 uri
153              
154             Required constructor argument. URI to the HTTP API of your OpenXchange server. Please note you have
155             to add the /ajax manually.
156              
157             =head2 login
158              
159             Required constructor argument. Username to log into OpenXchange.
160              
161             =head2 password
162              
163             Required constructor argument. Password to log into OpenXchange.
164              
165             =head2 conn
166              
167             Read-only. An instance of L<Net::OpenXchange::Connection|Net::OpenXchange::Connection>. You will not have to use this directly.
168              
169             =head2 calendar
170              
171             Read-only. An instance of L<Net::OpenXchange::Module::Calendar|Net::OpenXchange::Module::Calendar>. See its documentation for provided methods.
172              
173             =head2 contact
174              
175             Read-only. An instance of L<Net::OpenXchange::Module::Contact|Net::OpenXchange::Module::Contact>. See its documentation for provided methods.
176              
177             =head2 folder
178              
179             Read-only. An instance of L<Net::OpenXchange::Module::Folder|Net::OpenXchange::Module::Folder>. See its documentation for provided methods.
180              
181             =head2 user
182              
183             Read-only. An instance of L<Net::OpenXchange::Module::User|Net::OpenXchange::Module::User>. See its documentation for provided methods.
184              
185             =head1 METHODS
186              
187             =head2 new
188              
189             my $ox = Net::OpenXchange->new(
190             uri => "https://ox.example.com/ajax",
191             login => $username,
192             password => $password,
193             );
194              
195             Connect to OpenXchange server.
196              
197             =for Pod::Coverage BUILD
198              
199             =head1 AUTHOR
200              
201             Maximilian Gass <maximilian.gass@credativ.de>
202              
203             =head1 COPYRIGHT AND LICENSE
204              
205             This software is copyright (c) 2011 by Maximilian Gass.
206              
207             This is free software; you can redistribute it and/or modify it under
208             the same terms as the Perl 5 programming language system itself.
209              
210             =cut
211