| 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 | =head1 PROPERTIES | ||||||||||
| 20 | |||||||||||
| 21 | =head2 openerp_connect | ||||||||||
| 22 | |||||||||||
| 23 | This should be populated with a hash of the OpenERP connection details. | ||||||||||
| 24 | |||||||||||
| 25 | <openerp_connect> | ||||||||||
| 26 | username admin | ||||||||||
| 27 | password admin | ||||||||||
| 28 | dbname company-database | ||||||||||
| 29 | host openerp-server | ||||||||||
| 30 | </openerp_connect> | ||||||||||
| 31 | |||||||||||
| 32 | =head2 link_provider | ||||||||||
| 33 | |||||||||||
| 34 | Out of the box the links to the external database are generated each time the | ||||||||||
| 35 | link is followed. It's generally a good idea to provide your own provider that | ||||||||||
| 36 | provides a cached connection for the link. | ||||||||||
| 37 | |||||||||||
| 38 | NOTE: this could do with more detail to explain it better. | ||||||||||
| 39 | |||||||||||
| 40 | =head2 link_config | ||||||||||
| 41 | |||||||||||
| 42 | This is the configuration for the externals links. Typcially it is setup with | ||||||||||
| 43 | the connection information if the default link provider is used. If another link | ||||||||||
| 44 | provider is provided this won't be necessary. | ||||||||||
| 45 | |||||||||||
| 46 | =head2 client | ||||||||||
| 47 | |||||||||||
| 48 | The XMLRPC client that talks to OpenERP. | ||||||||||
| 49 | |||||||||||
| 50 | =head2 link | ||||||||||
| 51 | |||||||||||
| 52 | Provides a link to another part of the database. | ||||||||||
| 53 | |||||||||||
| 54 | $schema->link('DBIC') | ||||||||||
| 55 | |||||||||||
| 56 | =head2 provide_link | ||||||||||
| 57 | |||||||||||
| 58 | A default implementation of a link provider that loads up an OpenERP::OOM::Link::$class | ||||||||||
| 59 | on the fly. This is slow so you normally don't want to use this. | ||||||||||
| 60 | |||||||||||
| 61 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 62 | |||||||||||
| 63 | Copyright (C) 2011 OpusVL | ||||||||||
| 64 | |||||||||||
| 65 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | 2 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 70 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 71 | 2 | ▶ | use OpenERP::XMLRPC::Client; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 72 | |||||||||||
| 73 | 2 | with 'OpenERP::OOM::DynamicUtils'; | |||||||||
| 74 | 2 | with 'OpenERP::OOM::Link::Provider'; | |||||||||
| 75 | |||||||||||
| 76 | 2 | has 'openerp_connect' => ( | |||||||||
| 77 | isa => 'HashRef', | ||||||||||
| 78 | is => 'ro', | ||||||||||
| 79 | ); | ||||||||||
| 80 | |||||||||||
| 81 | 2 | has 'link_config' => ( | |||||||||
| 82 | isa => 'HashRef', | ||||||||||
| 83 | is => 'ro', | ||||||||||
| 84 | ); | ||||||||||
| 85 | |||||||||||
| 86 | 2 | has link_provider => ( | |||||||||
| 87 | isa => 'OpenERP::OOM::Link::Provider', | ||||||||||
| 88 | is => 'ro', | ||||||||||
| 89 | lazy_build => 1, | ||||||||||
| 90 | ); | ||||||||||
| 91 | |||||||||||
| 92 | 2 | has 'client' => ( | |||||||||
| 93 | isa => 'OpenERP::XMLRPC::Client', | ||||||||||
| 94 | is => 'ro', | ||||||||||
| 95 | lazy => 1, | ||||||||||
| 96 | builder => '_build_client', | ||||||||||
| 97 | ); | ||||||||||
| 98 | |||||||||||
| 99 | sub _build_link_provider | ||||||||||
| 100 | { | ||||||||||
| 101 | # we are also a link provider | ||||||||||
| 102 | # so use that if one isn't provided. | ||||||||||
| 103 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_link_provider: not called CC=1 SCAR=6.9
| |||||||||||
| 104 | 0 | return $self; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | #------------------------------------------------------------------------------- | ||||||||||
| 108 | |||||||||||
| 109 | sub _build_client { | ||||||||||
| 110 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_client: not called CC=1 SCAR=6.9
| |||||||||||
| 111 | |||||||||||
| 112 | 0 | return OpenERP::XMLRPC::Client->new(%{$self->openerp_connect}); | |||||||||
| 113 | } | ||||||||||
| 114 | |||||||||||
| 115 | |||||||||||
| 116 | #------------------------------------------------------------------------------- | ||||||||||
| 117 | |||||||||||
| 118 | sub class { | ||||||||||
| 119 | 0 | ▶ | my ($self, $class) = @_; | ||||||||
|
Subroutine
class: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 120 | |||||||||||
| 121 | 0 | my $package = $self->meta->name . "::Class::$class"; | |||||||||
| 122 | 0 | my $object_package = $self->meta->name . "::Object::$class"; | |||||||||
| 123 | |||||||||||
| 124 | 0 | $self->ensure_class_loaded($package); | |||||||||
| 125 | 0 | $self->ensure_class_loaded($object_package); | |||||||||
| 126 | |||||||||||
| 127 | 0 | return $package->new( | |||||||||
| 128 | schema => $self, | ||||||||||
| 129 | ); | ||||||||||
| 130 | } | ||||||||||
| 131 | |||||||||||
| 132 | |||||||||||
| 133 | #------------------------------------------------------------------------------- | ||||||||||
| 134 | |||||||||||
| 135 | sub link | ||||||||||
| 136 | { | ||||||||||
| 137 | 0 | ▶ | my ($self, $class) = @_; | ||||||||
|
Subroutine
link: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 138 | |||||||||||
| 139 | 0 | return $self->link_provider->provide_link($class); | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | sub provide_link { | ||||||||||
| 143 | 0 | ▶ | my ($self, $class) = @_; | ||||||||
|
Subroutine
provide_link: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 144 | |||||||||||
| 145 | 0 | ▶ | my $package = ($class =~ /^\+/) ? $class : "OpenERP::OOM::Link::$class"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | |||||||||||
| 147 | 0 | $self->ensure_class_loaded($package); | |||||||||
| 148 | |||||||||||
| 149 | return $package->new( | ||||||||||
| 150 | schema => $self, | ||||||||||
| 151 | 0 | config => $self->link_config->{$class}, | |||||||||
| 152 | ); | ||||||||||
| 153 | } | ||||||||||
| 154 | |||||||||||
| 155 | 2 | 1; | |||||||||