OOM/Schema.pm

filter: Statementstmt 41.4% 17 / 41 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 30.0% 3 / 10 Podpod 100% 4 / 4 totaltotal 39.3% 24 / 61 CC 4 SCAR 12.7
CC
4
Cov
36%
_build_client
6.0
class
6.0
provide_link
6.0
CRAP 3.5
« OOM/Roles/Attribute.pm ↑ Summary OOM/Link/DBIC.pm »
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 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 2 ▶use OpenERP::XMLRPC::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
76  
77 2 with 'OpenERP::OOM::DynamicUtils';
78 2 with 'OpenERP::OOM::Link::Provider';
79  
80 2 has 'openerp_connect' => (
81 isa => 'HashRef',
82 is => 'ro',
83 );
84  
85 2 has 'link_config' => (
86 isa => 'HashRef',
87 is => 'ro',
88 );
89  
90 2 has link_provider => (
91 isa => 'OpenERP::OOM::Link::Provider',
92 is => 'ro',
93 lazy_build => 1,
94 );
95  
96 2 has 'client' => (
97 isa => 'OpenERP::XMLRPC::Client',
98 is => 'ro',
99 lazy => 1,
100 builder => '_build_client',
101 );
102  
103 2 has lang => (
104 isa => 'Str',
105 is => 'ro',
106 default => 'en_GB',
107 );
108  
109 sub _build_link_provider
110 0 ▶{
Subroutine _build_link_provider: not called CC=1 SCAR=6.9
111 # we are also a link provider
112 # so use that if one isn't provided.
113 0 my $self = shift;
114 0 return $self;
115 }
116  
117 #-------------------------------------------------------------------------------
118  
119 0 ▶sub _build_client {
Subroutine _build_client: not called CC=2 SCAR=17.9
120 0 my $self = shift;
121
122 0 ▶ die 'Your config file has not been loaded or wired up correctly.' unless $self->openerp_connect;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->openerp_connect 0 0 0
123 0 return OpenERP::XMLRPC::Client->new(%{$self->openerp_connect});
124 }
125  
126  
127 #-------------------------------------------------------------------------------
128  
129 0 ▶has _class_cache => (is => 'ro', isa => 'HashRef', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
130  
131 0 ▶sub class {
Subroutine class: not called CC=2 SCAR=17.9
Pod documented
132 0 my ($self, $class) = @_;
133
134 0 ▶ if(exists $self->_class_cache->{$class})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->_class_cache->{$class}) 0 0 0
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 0 ▶{
Subroutine link: not called CC=1 SCAR=6.9
Pod documented
155 0 my ($self, $class) = @_;
156  
157 0 return $self->link_provider->provide_link($class);
158 }
159  
160 0 ▶sub provide_link {
Subroutine provide_link: not called CC=2 SCAR=17.9
Pod documented
161 0 my ($self, $class) = @_;
162
163 0 ▶ my $package = ($class =~ /^\+/) ? $class : "OpenERP::OOM::Link::$class";
Branch: 1 branch
BranchTrueFalseTotal
$class =~ /^\+/ ? : 0 0 0
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 0 ▶sub timeout {
Subroutine timeout: not called CC=1 SCAR=6.9
Pod documented
174 0 my $self = shift;
175 0 return $self->client->openerp_rpc->timeout(@_);
176 }
177  
178 2 1;
« OOM/Roles/Attribute.pm ↑ Summary OOM/Link/DBIC.pm »