File Coverage

blib/lib/Elive/Entity.pm
Criterion Covered Total %
statement 56 74 75.6
branch 23 34 67.6
condition 7 15 46.6
subroutine 7 10 70.0
pod 3 3 100.0
total 96 136 70.5


line stmt bran cond sub pod time code
1             package Elive::Entity;
2 36     36   39045 use warnings; use strict;
  36     36   72  
  36         1146  
  36         185  
  36         71  
  36         1332  
3              
4 36     36   33657 use Mouse;
  36         1346747  
  36         217  
5 36     36   20092 use Carp;
  36         88  
  36         38443  
6              
7             extends 'Elive::DAO';
8              
9             our $VERSION = '0.07';
10              
11             =head1 NAME
12              
13             Elive::Entity - Base class for Elive Entities
14              
15             =head1 DESCRIPTION
16              
17             This is the base class for Elluminate C Command Toolkit entity
18             specific classes.
19              
20             =cut
21              
22             =head2 data_classes
23              
24             returns a list of all entity instance classes
25              
26             =cut
27              
28             sub data_classes {
29 0     0 1 0 my $class = shift;
30 0         0 return qw(
31             Elive::Entity::Group
32             Elive::Entity::MeetingParameters
33             Elive::Entity::Meeting
34             Elive::Entity::ParticipantList
35             Elive::Entity::Preload
36             Elive::Entity::Recording
37             Elive::Entity::Report
38             Elive::Entity::ServerDetails
39             Elive::Entity::ServerParameters
40             Elive::View::Session
41             Elive::Entity::User
42             );
43             }
44              
45             =head2 connect
46              
47             Elive::Entity->connect('https://myServer.com/test', some_user => 'some_pass');
48             my $connection = Elive::Entity->connection;
49              
50             Connects to an Elluminate server instance. Dies if the connection could not
51             be established. If, for example, the SOAP connection or user login failed.
52              
53             The login user must either be an Elluminate I system administrator
54             account, or a user that has been configured to access the Command Toolkit
55             via web services.
56              
57             =cut
58              
59             sub connect {
60 0     0 1 0 my ($class, $url, $login_name, $pass, %opts) = @_;
61              
62 0 0 0     0 Carp::croak("usage: ${class}->connect(url, [login_name] [, pass])")
63             unless ($class && $url);
64              
65 0         0 require Elive::Connection::SDK;
66              
67 0         0 my $connection = Elive::Connection::SDK->connect(
68             $url,
69             $login_name => $pass,
70             debug => $class->debug,
71             %opts,
72             );
73              
74 0         0 $class->_connection($connection);
75              
76 0         0 return $connection;
77             }
78              
79             #
80             # Normalise our data and reconstruct arrays.
81             #
82             # See t/dao-unpack.t for examples and further explanation.
83             #
84              
85             sub _get_results {
86 0     0   0 my $class = shift;
87 0         0 my $som = shift;
88 0         0 my $connection = shift;
89              
90 0         0 $connection->_check_for_errors($som);
91              
92 0         0 my $results_list = $class->_unpack_as_list($som->result);
93              
94 0         0 return $results_list;
95             }
96              
97             sub _unpack_as_list {
98 7     7   2241 my $class = shift;
99 7         11 my $result = shift;
100              
101 7         17 $result = $class->_unpack_results($result);
102              
103 7         20 my $reftype = Elive::Util::_reftype($result);
104              
105 7         52 my $results_list;
106              
107 7 100       23 if ($reftype eq 'HASH') {
    50          
    0          
108              
109 4         8 $results_list = [ $result ];
110              
111             }
112             elsif ($reftype eq 'ARRAY') {
113              
114 3         4 $results_list = $result;
115              
116             }
117             elsif ($reftype) {
118 0         0 Carp::croak "unknown type in result set: $reftype";
119             }
120             else {
121              
122 0 0 0     0 $results_list = defined($result) && $result ne ''
123             ? [ $result ]
124             : [];
125              
126             }
127              
128 7 50       37 warn "$class result: ".YAML::Syck::Dump($result)
129             if ($class->debug >= 2);
130              
131 7         20 return $results_list;
132             }
133              
134             sub _unpack_results {
135 83     83   98 my $class = shift;
136 83         96 my $results = shift;
137              
138 83         187 my $results_type = Elive::Util::_reftype($results);
139              
140 83 100       235 if (!$results_type) {
    100          
    50          
141 47         157 return $results;
142             }
143             elsif ($results_type eq 'ARRAY') {
144 5         15 return [map {$class->_unpack_results($_)} @$results];
  8         24  
145             }
146             elsif ($results_type eq 'HASH') {
147             #
148             # Convert some SOAP/XML constructs to their perl equivalents
149             #
150 31         79 foreach my $key (keys %$results) {
151 68         102 my $value = $results->{$key};
152              
153 68 100       159 if ($key eq 'Collection') {
    100          
154              
155 5 100 66     15 if (Elive::Util::_reftype($value) eq 'HASH'
156             && exists ($value->{Entry})) {
157 4         7 $value = $value->{Entry};
158              
159 4         15 my %parent = %$results;
160 4         10 delete $parent{Collection};
161 4 100       28 if (keys %parent) {
162             #
163             # merge in with the parent
164             #
165 1         4 $parent{Entry} = $value;
166 1         3 $value = \%parent;
167             }
168             }
169             else {
170 1         4 $value = [];
171             }
172             #
173             # Throw away our parse of this struct. It only exists to
174             # house this collection
175             #
176 5         19 return $class->_unpack_results($value);
177             }
178             elsif ($key eq 'Map') {
179              
180 2 50       6 if (Elive::Util::_reftype($value) eq 'HASH') {
181              
182 2 50       7 if (exists ($value->{Entry})) {
183              
184 2         4 $value = $value->{Entry};
185             #
186             # Looks like we've got Key, Value pairs.
187             # Throw array the key and reference the value,
188             # that's all we're interested in.
189             #
190 2 100       54 if (Elive::Util::_reftype ($value) eq 'ARRAY') {
191            
192 1         3 $value = [map {$_->{Value}} @$value];
  1         5  
193             }
194             else {
195 1         3 $value = $value->{Value};
196             }
197             }
198             }
199             else {
200 0         0 $value = [];
201             }
202             #
203             # Throw away our parse of this struct it only exists to
204             # house this collection
205             #
206 2         7 return $class->_unpack_results($value);
207             }
208              
209 61         139 $results->{$key} = $class->_unpack_results($value);
210             }
211            
212             }
213             else {
214 0         0 die "Unhandled type in response body: $results_type";
215             }
216              
217 24         97 return $results;
218             }
219              
220             =head2 quote
221              
222             This is a utility method for quoting literal arguments to C filter
223             expressions:
224              
225             my $users = Elive::Entity::User->list(
226             filter => "surname=".Elive::Entity::User->quote("O'Reilly"),
227             );
228              
229             =cut
230              
231             sub quote {
232 5     5 1 48 my $class = shift;
233 5         9 my $str = shift;
234              
235 5 100 66     64 return $str
      100        
236             if !defined $str
237             or $str eq ''
238             or $str =~ m{^ \w+ $}x;
239              
240 3         9 $str =~ s{'}{''}g;
241              
242 3         21 return "'$str'";
243             }
244              
245             =head1 SEE ALSO
246              
247             =head2 Ancestor Classes
248              
249             =over 4
250              
251             =item L - base class
252              
253             =item L - Middle-weight L like class system
254              
255             =back
256              
257             =head2 Derived Classes
258              
259             =over 4
260              
261             =item Elive::Entity::Group
262              
263             =item Elive::Entity::MeetingParameters
264              
265             =item Elive::Entity::Meeting
266              
267             =item Elive::Entity::ParticipantList
268              
269             =item Elive::Entity::Preload
270              
271             =item Elive::Entity::Recording
272              
273             =item Elive::Entity::Report
274              
275             =item Elive::Entity::ServerDetails
276              
277             =item Elive::Entity::ServerParameters
278              
279             =item Elive::Entity::Session
280              
281             =item Elive::View::Session
282              
283             =item Elive::Entity::User
284              
285             =back
286              
287             =cut
288              
289             1;