line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenERP::OOM::Schema; |
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
OpenERP::OOM::Schema |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSYS |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 DESCRIPTION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 METHODS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head2 class |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Provides the OpenERP::OOM::Class class object requested. This will |
15
|
|
|
|
|
|
|
load the class into memory. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $accounts = $schema->class('Accounts'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 timeout |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Set the timeout - passes through to the $self->client->openerp_rpc->timeout() method underneath. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 PROPERTIES |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 openerp_connect |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This should be populated with a hash of the OpenERP connection details. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
<openerp_connect> |
30
|
|
|
|
|
|
|
username admin |
31
|
|
|
|
|
|
|
password admin |
32
|
|
|
|
|
|
|
dbname company-database |
33
|
|
|
|
|
|
|
host openerp-server |
34
|
|
|
|
|
|
|
</openerp_connect> |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 link_provider |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Out of the box the links to the external database are generated each time the |
39
|
|
|
|
|
|
|
link is followed. It's generally a good idea to provide your own provider that |
40
|
|
|
|
|
|
|
provides a cached connection for the link. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
NOTE: this could do with more detail to explain it better. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 link_config |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This is the configuration for the externals links. Typcially it is setup with |
47
|
|
|
|
|
|
|
the connection information if the default link provider is used. If another link |
48
|
|
|
|
|
|
|
provider is provided this won't be necessary. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 client |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
The XMLRPC client that talks to OpenERP. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 link |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Provides a link to another part of the database. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$schema->link('DBIC') |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 provide_link |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
A default implementation of a link provider that loads up an OpenERP::OOM::Link::$class |
63
|
|
|
|
|
|
|
on the fly. This is slow so you normally don't want to use this. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Copyright (C) 2011 OpusVL |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
2
|
|
3735
|
use 5.010; |
|
2
|
|
|
|
|
6
|
|
74
|
2
|
|
|
2
|
|
22
|
use Moose; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
13
|
|
75
|
2
|
|
|
2
|
|
13103
|
use OpenERP::XMLRPC::Client; |
|
2
|
|
|
|
|
2482973
|
|
|
2
|
|
|
|
|
880
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
with 'OpenERP::OOM::DynamicUtils'; |
78
|
|
|
|
|
|
|
with 'OpenERP::OOM::Link::Provider'; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
has 'openerp_connect' => ( |
81
|
|
|
|
|
|
|
isa => 'HashRef', |
82
|
|
|
|
|
|
|
is => 'ro', |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
has 'link_config' => ( |
86
|
|
|
|
|
|
|
isa => 'HashRef', |
87
|
|
|
|
|
|
|
is => 'ro', |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
has link_provider => ( |
91
|
|
|
|
|
|
|
isa => 'OpenERP::OOM::Link::Provider', |
92
|
|
|
|
|
|
|
is => 'ro', |
93
|
|
|
|
|
|
|
lazy_build => 1, |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
has 'client' => ( |
97
|
|
|
|
|
|
|
isa => 'OpenERP::XMLRPC::Client', |
98
|
|
|
|
|
|
|
is => 'ro', |
99
|
|
|
|
|
|
|
lazy => 1, |
100
|
|
|
|
|
|
|
builder => '_build_client', |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
has lang => ( |
104
|
|
|
|
|
|
|
isa => 'Str', |
105
|
|
|
|
|
|
|
is => 'ro', |
106
|
|
|
|
|
|
|
default => 'en_GB', |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _build_link_provider |
110
|
|
|
|
|
|
|
{ |
111
|
|
|
|
|
|
|
# we are also a link provider |
112
|
|
|
|
|
|
|
# so use that if one isn't provided. |
113
|
0
|
|
|
0
|
|
|
my $self = shift; |
114
|
0
|
|
|
|
|
|
return $self; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _build_client { |
120
|
0
|
|
|
0
|
|
|
my $self = shift; |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
die 'Your config file has not been loaded or wired up correctly.' unless $self->openerp_connect; |
123
|
0
|
|
|
|
|
|
return OpenERP::XMLRPC::Client->new(%{$self->openerp_connect}); |
|
0
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
has _class_cache => (is => 'ro', isa => 'HashRef', default => sub { {} } ); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub class { |
132
|
0
|
|
|
0
|
1
|
|
my ($self, $class) = @_; |
133
|
|
|
|
|
|
|
|
134
|
0
|
0
|
|
|
|
|
if(exists $self->_class_cache->{$class}) |
135
|
|
|
|
|
|
|
{ |
136
|
0
|
|
|
|
|
|
return $self->_class_cache->{$class}; |
137
|
|
|
|
|
|
|
} |
138
|
0
|
|
|
|
|
|
my $package = $self->meta->name . "::Class::$class"; |
139
|
0
|
|
|
|
|
|
my $object_package = $self->meta->name . "::Object::$class"; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
$self->ensure_class_loaded($package); |
142
|
0
|
|
|
|
|
|
$self->ensure_class_loaded($object_package); |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
$self->_class_cache->{$class} = $package->new( |
145
|
|
|
|
|
|
|
schema => $self, |
146
|
|
|
|
|
|
|
); |
147
|
0
|
|
|
|
|
|
return $self->_class_cache->{$class}; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub link |
154
|
|
|
|
|
|
|
{ |
155
|
0
|
|
|
0
|
1
|
|
my ($self, $class) = @_; |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
return $self->link_provider->provide_link($class); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub provide_link { |
161
|
0
|
|
|
0
|
1
|
|
my ($self, $class) = @_; |
162
|
|
|
|
|
|
|
|
163
|
0
|
0
|
|
|
|
|
my $package = ($class =~ /^\+/) ? $class : "OpenERP::OOM::Link::$class"; |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
$self->ensure_class_loaded($package); |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
return $package->new( |
168
|
|
|
|
|
|
|
schema => $self, |
169
|
0
|
|
|
|
|
|
config => $self->link_config->{$class}, |
170
|
|
|
|
|
|
|
); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub timeout { |
174
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
175
|
0
|
|
|
|
|
|
return $self->client->openerp_rpc->timeout(@_); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1; |