| 1 | package OpenERP::OOM::Link::DBIC; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | OpenERP::OOM::Link::DBIC | ||||||||||
| 6 | |||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||
| 8 | |||||||||||
| 9 | Class used to link OpenERP data with data in DBIC. | ||||||||||
| 10 | |||||||||||
| 11 | =head1 PROPERTIES | ||||||||||
| 12 | |||||||||||
| 13 | =head2 dbic_schema | ||||||||||
| 14 | |||||||||||
| 15 | This is the DBIC Schema object. If you need a generic DBIC schema object | ||||||||||
| 16 | this is normally the simplest way to access it. | ||||||||||
| 17 | |||||||||||
| 18 | =head1 METHODS | ||||||||||
| 19 | |||||||||||
| 20 | These methods are not normally called directly. | ||||||||||
| 21 | |||||||||||
| 22 | =head2 create | ||||||||||
| 23 | |||||||||||
| 24 | Returns the new ID of a row it creates in a table using DBIC. | ||||||||||
| 25 | |||||||||||
| 26 | my $id = $link->create({ class => 'RSName' }, $object_data); | ||||||||||
| 27 | |||||||||||
| 28 | =head2 retrieve | ||||||||||
| 29 | |||||||||||
| 30 | This is equivalent to doing a find on a ResultSet. | ||||||||||
| 31 | |||||||||||
| 32 | my $object = $link->retrieve({ class => 'RSName' }, $id); | ||||||||||
| 33 | |||||||||||
| 34 | =head2 search | ||||||||||
| 35 | |||||||||||
| 36 | This is equivalent to doing a search on a ResultSet and then returning a list | ||||||||||
| 37 | of all the id fields. | ||||||||||
| 38 | |||||||||||
| 39 | my @ids = $link->search({ class => 'RSName' }, $search, $options); | ||||||||||
| 40 | |||||||||||
| 41 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 42 | |||||||||||
| 43 | Copyright (C) 2011 OpusVL | ||||||||||
| 44 | |||||||||||
| 45 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||
| 46 | |||||||||||
| 47 | =cut | ||||||||||
| 48 | |||||||||||
| 49 | 2 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 51 | 2 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 52 | 2 | extends 'OpenERP::OOM::Link'; | |||||||||
| 53 | 2 | with 'OpenERP::OOM::DynamicUtils'; | |||||||||
| 54 | |||||||||||
| 55 | 2 | has 'dbic_schema' => ( | |||||||||
| 56 | is => 'ro', | ||||||||||
| 57 | lazy => 1, | ||||||||||
| 58 | builder => '_build_dbic_schema', | ||||||||||
| 59 | ); | ||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | sub _build_dbic_schema { | ||||||||
|
Subroutine
_build_dbic_schema: not called CC=1 SCAR=6.9
| |||||||||||
| 62 | 0 | my $self = shift; | |||||||||
| 63 | |||||||||||
| 64 | 0 | $self->ensure_class_loaded($self->config->{schema_class}); | |||||||||
| 65 | |||||||||||
| 66 | 0 | return $self->config->{schema_class}->connect(@{$self->config->{connect_info}}); | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | |||||||||||
| 70 | #------------------------------------------------------------------------------- | ||||||||||
| 71 | |||||||||||
| 72 | 0 | ▶ | sub create { | ||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 73 | 0 | my ($self, $args, $data) = @_; | |||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | try { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 76 | 0 | my $object = $self->dbic_schema->resultset($args->{class})->create($data); | |||||||||
| 77 | ### Created linked object with ID $object->id | ||||||||||
| 78 | 0 | return $object->id; | |||||||||
| 79 | 0 | ▶ | } catch { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 80 | 0 | die "Could not create linked object: $_"; | |||||||||
| 81 | 0 | }; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | #------------------------------------------------------------------------------- | ||||||||||
| 86 | |||||||||||
| 87 | 0 | ▶ | sub retrieve { | ||||||||
|
Subroutine
retrieve: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 88 | 0 | my ($self, $args, $id) = @_; | |||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | if (my $object = $self->dbic_schema->resultset($args->{class})->find($id)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | return $object; | |||||||||
| 92 | } | ||||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | |||||||||||
| 96 | #------------------------------------------------------------------------------- | ||||||||||
| 97 | |||||||||||
| 98 | 0 | ▶ | sub search { | ||||||||
|
Subroutine
search: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 99 | 0 | my ($self, $args, $search, $options) = @_; | |||||||||
| 100 | |||||||||||
| 101 | # FIXME - Foreign primary key column is hard-coded to "id" | ||||||||||
| 102 | 0 | return map {$_->id} $self->dbic_schema->resultset($args->{class})->search($search, $options)->all; | |||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | |||||||||||
| 106 | #------------------------------------------------------------------------------- | ||||||||||
| 107 | |||||||||||
| 108 | 2 | 1; | |||||||||