OOM/Tutorial/Schema.pm untested

filter: Statementstmt n/a Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a SCAR -
1 package OpenERP::OOM::Tutorial::Schema;
2  
3 =pod
4  
5 =head1 NAME
6  
7 OpenERP::OOM::Tutorial::Schema - Setting up an OpenERP::OOM Schema
8  
9 =head1 DESCRIPTION
10  
11 =head2 Object model
12  
13 OpenERP::OOM uses an object model consisting of a Schema, Classes, and Objects.
14 These are organised as shown below, with methods to traverse up and down the tree.
15  
16 +-------------------------------+
17 | Schema |
18 | e.g. MyApp |
19 +-------------------------------+
20 /|\ |
21 | class
22 schema |
23 | \|/
24 +-------------------------------+
25 | Class |
26 | e.g. MyApp::Class::Partner |
27 +-------------------------------+
28 /|\ |
29 | search
30 class retrieve
31 | create
32 | |
33 | \|/
34 +-------------------------------+
35 | Object |
36 | e.g. MyApp::Object::Partner |
37 +-------------------------------+
38 |
39 update
40 delete
41 |
42 \|/
43 +-------------------------------+
44 | OpenERP model |
45 | e.g res.partner |
46 +-------------------------------+
47  
48 =head2 Schema
49  
50 The schema class extends the OpenERP::OOM::Schema module, i.e.:
51  
52 package MyApp;
53
54 use Moose;
55 extends 'OpenERP::OOM::Schema';
56
57 1;
58  
59 To create a new instance of your schema, pass the OpenERP connection details in
60 the call to C<new()>.
61  
62 use MyApp;
63
64 my $schema = MyApp->new(
65 openerp_connect => {
66 host => 'localhost',
67 dbname => 'openerp_db',
68 username => 'admin',
69 password => 'admin',
70 }
71 );
72  
73 =head2 Classes
74  
75 A typical class definition is as follows:
76  
77 package MyApp::Class::Partner;
78 use OpenERP::OOM::Class;
79
80 object_type 'MyApp::Object::Company';
81
82 1;
83  
84 From your schema, you can then access classes.
85  
86 my $class = $schema->class('Partner');
87  
88 The class provides methods to search, retrieve, and create objects.
89  
90 =head2 Objects
91  
92 package MyApp::Object::Partner;
93 use OpenERP::OOM::Object;
94
95 openerp_model 'res.partner';
96
97 has 'name' => (isa=>'Str', is=>'rw');
98
99 1;
100  
101 Objects are created and retrieved from the class:
102  
103 my $partner = $schema->class('Partner')->create({
104 name => 'My Partner',
105 });
106  
107 foreach my $partner ($schema->class->('Partner')->search) {
108 say $partner->name;
109 }
110  
111 =head2 AUTHOR
112  
113 Jon Allen (JJ) <jj@opusvl.com>
114  
115 =head1 COPYRIGHT & LICENSE
116  
117 Copyright (C) 2012 OpusVL
118  
119 This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
120  
121 =cut
122  
123 __END__