Newer Older
62 lines | 1.053kb
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
1
package DBIx::Custom::Model;
2

            
3
use strict;
4
use warnings;
5

            
6
use base 'Object::Simple';
7

            
8
use Carp 'croak';
9
use DBIx::Custom::Table;
10

            
11
__PACKAGE__->attr(dbi => sub { DBIx::Custom->new });
12

            
13
sub table {
14
    my ($self, $table) = @_;
15
      
16
    $self->{tables}{$table}
17
        = DBIx::Custom::Table->new(name => $table, dbi => $self->dbi)
18
      unless defined $self->{tables}{$table};
19
    
20
    return $self->{tables}{$table};
21
}
22

            
23
1;
24

            
25
=head1 NAME
26

            
27
DBIx::Custom::Model - Table class(experimental)
28

            
29
=head1 SYNOPSIS
30

            
31
use MyModel;
32

            
33
use base 'DBIx::Custom::Model';
34

            
35
sub new {
36
    my $self = shift->SUPER::new(@_);
37
    
38
    $self->table('books')->helper(
39
        insert_multi => sub {
40
            my $self = shift;
41
            
42
            my $dbi = $self->dbi;
43
            
44
            # ...
45
            
46
        }
47
    );
48
    
49
    return $self;
50
}
51

            
52
=head1 METHODS
53

            
54
L<DBIx::Custom> inherits all methods from L<Object::Simple>
55
and implements the following new ones.
56

            
57
=head2 C<table>
58

            
59
    my $table = $model->table('books');
60

            
61
Create a table object if not exists or get it.
62