Subject: | [PATCH] Handle literal SQL default values |
Date: | Wed, 26 Jan 2011 16:06:30 +0000 |
To: | bug-DBICx-AutoDoc [...] rt.cpan.org |
From: | Dagfinn Ilmari Mannsåker <ilmari [...] ilmari.org> |
If the default value is a scalar reference, show it without quotes in
column_info.tt2
---
lib/DBICx/AutoDoc.pm | 3 +++
t/lib/ExampleDB/Result/Person.pm | 4 ++++
t/lib/ExampleDB/Result/PhoneNumber.pm | 1 +
templates/column_info.tt2 | 2 +-
4 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/lib/DBICx/AutoDoc.pm b/lib/DBICx/AutoDoc.pm
index 93e4ea6..6f8cabc 100644
--- a/lib/DBICx/AutoDoc.pm
+++ b/lib/DBICx/AutoDoc.pm
@@ -147,6 +147,9 @@ sub get_columns_for {
# COLUMNS
for ( $class->columns ) {
my $col = $class->column_info( $_ );
+ $col->{ 'default_value' } = ref($col->{ 'default_value' }) eq "SCALAR"
+ ? ${$col->{ 'default_value' }} : "'$col->{ 'default_value' }'"
+ if exists $col->{ 'default_value' };
$col->{ 'name' } = $_;
$col->{ 'is_inflated' } = delete $col->{ '_inflate_info' } ? 1 : 0;
$cols{ $_ } = $col;
diff --git a/t/lib/ExampleDB/Result/Person.pm b/t/lib/ExampleDB/Result/Person.pm
index e36b7ae..ec2df96 100644
--- a/t/lib/ExampleDB/Result/Person.pm
+++ b/t/lib/ExampleDB/Result/Person.pm
@@ -27,6 +27,10 @@ __PACKAGE__->add_columns(
birthdate => {
data_type => 'date',
},
+ registered => {
+ data_type => 'datetime',
+ default_value => \'CURRENT_TIMESTAMP',
+ },
);
__PACKAGE__->set_primary_key( 'id' );
__PACKAGE__->add_unique_constraint( [ qw( username ) ] );
diff --git a/t/lib/ExampleDB/Result/PhoneNumber.pm b/t/lib/ExampleDB/Result/PhoneNumber.pm
index 0516414..d7da3b4 100644
--- a/t/lib/ExampleDB/Result/PhoneNumber.pm
+++ b/t/lib/ExampleDB/Result/PhoneNumber.pm
@@ -23,6 +23,7 @@ __PACKAGE__->add_columns(
data_type => 'varchar',
size => 64,
is_nullable => 0,
+ default_value => 'Home',
comment => 'Home, work, etc',
},
phone_number => {
diff --git a/templates/column_info.tt2 b/templates/column_info.tt2
index 3e3b77b..96f9cff 100644
--- a/templates/column_info.tt2
+++ b/templates/column_info.tt2
@@ -1,7 +1,7 @@
[%- FILTER collapse %][% FILTER remove('\s*,\s*$') %]
[% UNLESS col.is_nullable %]NOT NULL,[% END %]
[% IF col.is_primary %]PRIMARY KEY,[% END %]
- [% IF col.default_value %]DEFAULT VALUE '[% col.default_value %]',[% END %]
+ [% IF col.default_value %]DEFAULT VALUE [% col.default_value %],[% END %]
[% IF col.is_auto_increment %]AUTO_INCREMENT,[% END %]
[% IF col.is_inflated %]INFLATED,[% END %]
[% IF col.is_foreign_key %]FOREIGN KEY,[% END %]
--
1.7.1