| 1 | package OpenERP::OOM::Class; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | OpenERP::OOM::Class | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | package Package::OpenERP::Class::Account; | ||
| 10 | |||
| 11 | use 5.010; | ||
| 12 | use OpenERP::OOM::Class; | ||
| 13 | |||
| 14 | object_type 'Package::OpenERP::Object::Account'; | ||
| 15 | |||
| 16 | around 'create' => sub { | ||
| 17 | my ($orig, $self, $object) = @_; | ||
| 18 | |||
| 19 | # Make sure active is set to 1 | ||
| 20 | $object->{active} = 1; | ||
| 21 | |||
| 22 | # Create the object | ||
| 23 | return $self->$orig($object); | ||
| 24 | }; | ||
| 25 | |||
| 26 | sub account_by_code | ||
| 27 | { | ||
| 28 | my $self = shift; | ||
| 29 | my $code = shift; | ||
| 30 | return $self->find([ 'code', '=', $code ]); | ||
| 31 | } | ||
| 32 | |||
| 33 | 1; | ||
| 34 | |||
| 35 | =head1 DESCRIPTION | ||
| 36 | |||
| 37 | Use this module to create the 'classes' for your modules. It also implicitly loads | ||
| 38 | Moose too. In addition to the Moose bindings it also ties up the class with a | ||
| 39 | corresponding class for your individual objects using the object_type property. | ||
| 40 | |||
| 41 | =head1 METHODS | ||
| 42 | |||
| 43 | =head2 init_meta | ||
| 44 | |||
| 45 | This is in internal method that hooks up your class to inherit the class C<OpenERP::OOM::Class::Base>. | ||
| 46 | |||
| 47 | See the C<OpenERP::OOM::Class::Base> class for the methods your objects that use | ||
| 48 | this class will automatically have available. | ||
| 49 | |||
| 50 | =head2 object_type | ||
| 51 | |||
| 52 | This links the class to the object class. When you create a new object using create | ||
| 53 | or you are returned objects after doing a find or search they will be of the type | ||
| 54 | specified. | ||
| 55 | |||
| 56 | =head1 COPYRIGHT & LICENSE | ||
| 57 | |||
| 58 | Copyright (C) 2011 OpusVL | ||
| 59 | |||
| 60 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||
| 61 | |||
| 62 | =cut | ||
| 63 | |||
| 64 | 2 | ▶ | use 5.010; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 65 | 2 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 66 | 2 | ▶ | use Moose::Exporter; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 67 | |||
| 68 | 2 | Moose::Exporter->setup_import_methods( | |
| 69 | with_meta => ['object_type'], | ||
| 70 | also => 'Moose', | ||
| 71 | ); | ||
| 72 | |||
| 73 | 1 | ▶ | sub init_meta { |
|
Subroutine
init_meta: called CC=1 SCAR=0.0
Pod
documented
| |||
| 74 | 1 | shift; | |
| 75 | 1 | return Moose->init_meta( @_, base_class => 'OpenERP::OOM::Class::Base' ); | |
| 76 | } | ||
| 77 | |||
| 78 | 0 | ▶ | sub object_type { |
|
Subroutine
object_type: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 79 | 0 | my ($meta, $name, %options) = @_; | |
| 80 | |||
| 81 | $meta->add_attribute( | ||
| 82 | 'object', | ||
| 83 | isa => 'Str', | ||
| 84 | is => 'ro', | ||
| 85 | 0 | ▶ | default => sub {$name}, |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 86 | 0 | ); | |
| 87 | } | ||
| 88 | |||
| 89 | 2 | 1; | |