Merge branch 'master' into custom_column_info
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / Base.pm
index e304c7c..4f57523 100644 (file)
@@ -55,6 +55,8 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/
                                 monikers
                                 dynamic
                                 naming
+                                datetime_timezone
+                                datetime_locale
 /);
 
 
@@ -418,6 +420,16 @@ Example:
 
 Add to all columns with type DATE the attribute timezone => "Europe/Berlin". 
 
+=head2 datetime_timezone
+
+Set timezone attribute for L<DBIx::Class::InflateColumn::DateTime> 
+to all columns with the type DATE.
+
+=head2 datetime_locale
+
+Set local attribute for L<DBIx::Class::InflateColumn::DateTime> 
+to all columns with the type DATE.
+
 =head1 METHODS
 
 None of these methods are intended for direct invocation by regular
@@ -1533,9 +1545,11 @@ sub _make_pod {
            $self->_pod( $class,
                         join "\n", map {
                             my $s = $attrs->{$_};
-                            $s = !defined $s      ? 'undef'          :
-                                 length($s) == 0  ? '(empty string)' :
-                                                     $s;
+                            $s = !defined $s         ? 'undef'          :
+                                  length($s) == 0     ? '(empty string)' :
+                                  ref($s) eq 'SCALAR' ? $$s              :
+                                                        $s
+                                  ;
 
                             "  $_: $s"
                         } sort keys %$attrs,
@@ -1599,14 +1613,31 @@ sub _quote_table_name {
 sub _is_case_sensitive { 0 }
 
 sub _custom_column_info {
-    my ( $self, $info ) = @_;
+    my ( $self, $table_name, $column_name, $column_info ) = @_;
 
     if( ref $self->custom_column_info eq 'CODE' ) {
-        return $self->custom_column_info->($info);
+        return $self->custom_column_info->( $table_name, $column_name, $column_info );
     }
     return {};
 }
 
+sub _datetime_column_info {
+    my ( $self, $table_name, $column_name, $column_info ) = @_;
+    my $return = {};
+    my $type = lc ( $column_info->{data_type} );
+    if (
+        ( defined $column_info->{inflate_datetime} and $column_info->{inflate_datetime} )
+        or ( defined $column_info->{inflate_date} and $column_info->{inflate_date} )
+        or ( $type eq 'date')
+        or ( $type eq 'datetime')
+        or ( $type eq 'timestamp')
+    ){
+        $return->{timezone} = $self->datetime_timezone if $self->datetime_timezone;
+        $return->{locale}   = $self->datetime_locale if $self->datetime_locale;
+    }
+    return $return;
+}
+
 # remove the dump dir from @INC on destruction
 sub DESTROY {
     my $self = shift;