Newer Older
67 lines | 1.202kb
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
1
package DBIx::Custom::Table;
2

            
3
use strict;
4
use warnings;
5

            
6
use base 'Object::Simple';
7

            
8
use Carp 'croak';
9

            
10
__PACKAGE__->attr(['dbi', 'name']);
11

            
12
our $AUTOLOAD;
13

            
14
sub AUTOLOAD {
15
    my $self = shift;
16

            
17
    # Method
18
    my ($package, $method) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
19

            
20
    # Helper
21
    $self->{_helpers} ||= {};
22
    croak qq/Can't locate object method "$method" via "$package"/
23
      unless my $helper = $self->{_helpers}->{$method};
24

            
25
    # Run
26
    return $self->$helper(@_);
27
}
28

            
29
sub helper {
30
    my $self = shift;
31
    
32
    # Merge
33
    my $helpers = ref $_[0] eq 'HASH' ? $_[0] : {@_};
34
    $self->{_helpers} = {%{$self->{_helpers} || {}}, %$helpers};
35
    
36
    return $self;
37
}
38

            
39
sub DESTROY { }
40

            
41
1;
42

            
43
=head1 NAME
44

            
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
45
DBIx::Custom::Model - Table base class(experimental)
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
46

            
47
=head1 SYNOPSIS
48

            
49
use DBIx::Custom::Table;
50

            
51
my $table = DBIx::Custom::Table->new(name => 'books');
52

            
53
=head1 METHODS
54

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

            
58
=head2 C<helper>
59

            
60
    $table->helper(insert => sub {
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
61
        my $self = shift;
62
        
63
        return $self->dbi->insert(table => $self->name, @_);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
64
    });
65
    
simplified DBIx::Custom::Mod...
Yuki Kimoto authored on 2011-01-02
66
Add helper method to a L<DBIx::Custom::Table> object.
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-01
67