Created
November 16, 2012 01:41
-
-
Save TristinDavis/4083155 to your computer and use it in GitHub Desktop.
DBIx::Class::Candy +MoreSugar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Application::Model::Sugar; | |
# common sugar routines | |
sub serial { | |
my %chngs = @_; | |
my %attrs = ('data_type', 'integer', 'is_auto_increment', 1, null() ); | |
$attrs{$_} = $chngs{$_} for keys %chngs; | |
return %chngs; | |
} | |
sub datetime { | |
my %chngs = @_; | |
my %attrs = ( 'data_type', 'datetime', 'datetime_undef_if_invalid', 1 ); | |
$attrs{$_} = $chngs{$_} for keys %chngs; | |
return %chngs; | |
} | |
sub string { | |
my %chngs = @_; | |
my %attrs = ('data_type', 'varchar', 'size', 255, 'is_nullable', 0 ); | |
$attrs{$_} = $chngs{$_} for keys %chngs; | |
return %chngs; | |
} | |
sub number { | |
my %chngs = @_; | |
my %attrs = ('data_type', 'integer', 'size', 11, 'is_nullable', 0 ); | |
$attrs{$_} = $chngs{$_} for keys %chngs; | |
return %chngs; | |
} | |
sub null { | |
return ('default', undef, 'is_nullable', 1); | |
} | |
eval { | |
require 'DBIx::Class::Candy::Exports'; | |
DBIx::Class::Candy::Exports->import; | |
DBIx::Class::Candy::Exports::export_methods( | |
[qw/serial datetime string number null/] ); | |
}; | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment