File Coverage

blib/lib/OpenERP/OOM/Class.pm
Criterion Covered Total %
statement 10 13 76.9
branch n/a
condition n/a
subroutine 4 6 66.6
pod 2 2 100.0
total 16 21 76.1


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