File: Master.pm

package info (click to toggle)
libhtml-formfu-model-dbic-perl 0.09002-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,064 kB
  • sloc: perl: 2,270; makefile: 2
file content (95 lines) | stat: -rw-r--r-- 2,312 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package MySchema::Master;
use strict;
use warnings;

use base 'DBIx::Class';

__PACKAGE__->load_components(qw/ 
    InflateColumn::DateTime Core
/);

__PACKAGE__->table("master");

__PACKAGE__->add_columns(
    id             => {
        data_type => "INTEGER",
        is_nullable => 0,
    },
    text_col       => { data_type => "TEXT", is_nullable => 1 },
    password_col   => { data_type => "TEXT", is_nullable => 1 },
    checkbox_col   => {
        data_type => "BOOLEAN",
        default_value => 1,
        is_nullable   => 0,
    },
    select_col     => { data_type => "TEXT", is_nullable => 1 },
    combobox_col   => { data_type => "TEXT", is_nullable => 1 },
    radio_col      => { data_type => "TEXT", is_nullable => 1 },
    radiogroup_col => { data_type => "TEXT", is_nullable => 1 },
    array_col      => { data_type => "TEXT", is_nullable => 1, is_array => 1 },
    date_col       => { data_type => "DATETIME", is_nullable => 1 },
    type_id        => { data_type => "INTEGER", is_nullable => 1 },
    type2_id       => { data_type => "INTEGER", is_nullable => 1 },
    not_in_form    => { data_type => "TEXT", is_nullable => 1 },
);

__PACKAGE__->set_primary_key("id");

__PACKAGE__->might_have( note => 'MySchema::Note', 'master' );

__PACKAGE__->has_one( user => 'MySchema::User', 'master' );

__PACKAGE__->has_many( schedules => 'MySchema::Schedule', 'master' );

__PACKAGE__->belongs_to(
    type => 'MySchema::Type',
    { 'foreign.id' => 'self.type_id' } );

__PACKAGE__->belongs_to(
    type2 => 'MySchema::Type2',
    { 'foreign.id' => 'self.type2_id' } );

__PACKAGE__->inflate_column('array_col', {	# {key=>val}
        inflate => __PACKAGE__->inflate_column_list_comma,
        deflate => __PACKAGE__->deflate_column_list_comma,
    });

sub method_test {
    my $self = shift;
    if (@_) {
        $self->text_col(@_);
    }

    return $self->text_col;
}

sub method_select_test {
    my $self = shift;
    if (@_) {
        $self->select_col(@_);
    }

    return $self->select_col;
}

sub method_checkbox_test {
    my $self = shift;
    if (@_) {
        $self->checkbox_col(@_);
    }
    return $self->checkbox_col;
}

sub inflate_column_list_comma {
  sub { 
	[split(/,/,  shift )];
  }
}
sub deflate_column_list_comma {
  sub { 
	join(',', @{(shift)} );
  }
}

1;