Merged in changes to StartupCheck, documentation and tests for Red Hat perl performance issues
Revision history for DBIx::Class
- - delete throws exception if passed arguments to prevent drunken mishaps. (purge)
+ - InflateColumn::DateTime: add warning about floating timezone
+ - InflateColumn::DateTime: possible to enforce/skip inflation
+ - delete throws exception if passed arguments to prevent drunken mishaps. (purge)
- Fix storage to copy scalar conds before regexping to avoid
trying to modify a constant in odd edge cases
- Related resultsets on uninserted objects are now empty
if ($type eq 'datetime' || $type eq 'date') {
my ($parse, $format) = ("parse_${type}", "format_${type}");
+
+ # This assignment must happen here, otherwise Devel::Cycle treats
+ # the resulting deflator as a circular reference (go figure):
+ #
+ # Cycle #1
+ # DBICTest::Schema A->{source_registrations} => %B
+ # %B->{Event} => DBIx::Class::ResultSource::Table C
+ # DBIx::Class::ResultSource::Table C->{_columns} => %D
+ # %D->{created_on} => %E
+ # %E->{_inflate_info} => %F
+ # %F->{deflate} => &G
+ # closure &G, $info => $H
+ # $H => %E
+ #
+ my $floating_tz_ok = $info->{extra}{floating_tz_ok};
+
$self->inflate_column(
$column =>
{
},
deflate => sub {
my ($value, $obj) = @_;
- $value->set_time_zone($timezone) if $timezone;
+ if ($timezone) {
+ warn "You're using a floating timezone, please see the documentation of"
+ . " DBIx::Class::InflateColumn::DateTime for an explanation"
+ if ref( $value->time_zone ) eq 'DateTime::TimeZone::Floating'
+ and not $floating_tz_ok
+ and not $ENV{DBIC_FLOATING_TZ_OK};
+ $value->set_time_zone($timezone);
+ }
$obj->_datetime_parser->$format($value);
},
}
1;
__END__
+=head1 USAGE NOTES
+
+If you have a datetime column with the C<timezone> extra setting, and subsenquently
+create/update this column with a DateTime object in the L<DateTime::TimeZone::Floating>
+timezone, you will get a warning (as there is a very good chance this will not have the
+result you expect). For example:
+
+ __PACKAGE__->add_columns(
+ starts_when => { data_type => 'datetime', extra => { timezone => "America/Chicago" } }
+ );
+
+ my $event = $schema->resultset('EventTZ')->create({
+ starts_at => DateTime->new(year=>2007, month=>12, day=>31, ),
+ });
+
+The warning can be avoided in several ways:
+
+=over
+
+=item Fix your broken code
+
+When calling C<set_time_zone> on a Floating DateTime object, the timezone is simply
+set to the requested value, and B<no time conversion takes place>. It is always a good idea
+to be supply explicit times to the database:
+
+ my $event = $schema->resultset('EventTZ')->create({
+ starts_at => DateTime->new(year=>2007, month=>12, day=>31, time_zone => "America/Chicago" ),
+ });
+
+=item Suppress the check on per-column basis
+
+ __PACKAGE__->add_columns(
+ starts_when => { data_type => 'datetime', extra => { timezone => "America/Chicago", floating_tz_ok => 1 } }
+ );
+
+=item Suppress the check globally
+
+Set the environment variable DBIC_FLOATING_TZ_OK to some true value.
+
+=back
+
+
+
=head1 SEE ALSO
=over 4
=item More information about the add_columns method, and column metadata,
can be found in the documentation for L<DBIx::Class::ResultSource>.
+=item Further discussion of problems inherent to the Floating timezone:
+ L<Floating DateTimes|DateTime/Floating_DateTimes>
+ and L<< $dt->set_time_zone|DateTime/"Set" Methods >>
+
=back
=head1 AUTHOR
=cut
sub set_column {
- my $self = shift;
- my ($column) = @_;
+ my ($self, $column, $new_value) = @_;
+
$self->{_orig_ident} ||= $self->ident_condition;
- my $old = $self->get_column($column);
- my $ret = $self->store_column(@_);
+ my $old_value = $self->get_column($column);
+
+ $self->store_column($column, $new_value);
$self->{_dirty_columns}{$column} = 1
- if (defined $old xor defined $ret) || (defined $old && $old ne $ret);
+ if (defined $old_value xor defined $new_value) || (defined $old_value && $old_value ne $new_value);
# XXX clear out the relation cache for this column
delete $self->{related_resultsets}{$column};
- return $ret;
+ return $new_value;
}
=head2 set_columns
eval 'use utf8; 1' or plan skip_all => 'Need utf8 run this test';
}
-plan tests => 3;
+plan tests => 5;
DBICTest::Schema::CD->load_components('UTF8Columns');
DBICTest::Schema::CD->utf8_columns('title');
$cd->title($utf8_char);
ok( !utf8::is_utf8( $cd->{_column_data}{title} ), 'store utf8-less chars' );
}
+
+my $v_utf8 = "\x{219}";
+
+$cd->update ({ title => $v_utf8 });
+$cd->title($v_utf8);
+ok( !$cd->is_column_changed('title'), 'column is not dirty after setting the same unicode value' );
+
+$cd->update ({ title => $v_utf8 });
+$cd->title('something_else');
+ok( $cd->is_column_changed('title'), 'column is dirty after setting to something completely different');
eval { require DateTime::Format::MySQL };
plan skip_all => "Need DateTime::Format::MySQL for inflation tests" if $@;
-plan tests => 27;
+plan tests => 28;
# inflation test
my $event = $schema->resultset("Event")->find(1);
is("$created_on", '2006-01-31T12:34:56', 'Loaded correct timestamp using timezone');
is($created_on->time_zone->name, 'America/Chicago', 'Correct timezone');
+# Test floating timezone warning
+# We expect one warning
+SKIP: {
+ skip "ENV{DBIC_FLOATING_TZ_OK} was set, skipping", 1 if $ENV{DBIC_FLOATING_TZ_OK};
+ local $SIG{__WARN__} = sub {
+ like(
+ shift,
+ qr/You're using a floating timezone, please see the documentation of DBIx::Class::InflateColumn::DateTime for an explanation/,
+ 'Floating timezone warning'
+ );
+ };
+ my $event_tz_floating = $schema->resultset('EventTZ')->create({
+ starts_at => DateTime->new(year=>2007, month=>12, day=>31, ),
+ created_on => DateTime->new(year=>2006, month=>1, day=>31,
+ hour => 13, minute => 34, second => 56, ),
+ });
+ delete $SIG{__WARN__};
+};
+
# This should fail to set
my $prev_str = "$created_on";
$loaded_event->update({ created_on => '0000-00-00' });
__PACKAGE__->add_columns(
id => { data_type => 'integer', is_auto_increment => 1 },
starts_at => { data_type => 'datetime', extra => { timezone => "America/Chicago" } },
- created_on => { data_type => 'timestamp', extra => { timezone => "America/Chicago" } },
+ created_on => { data_type => 'timestamp', extra => { timezone => "America/Chicago", floating_tz_ok => 1 } },
);
__PACKAGE__->set_primary_key('id');