Changeset 2033
- Timestamp:
- 05/23/08 12:26:58
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/fastladder-crawler/plagger/lib/Plagger/Plugin/Store/Fastladder.pm
r2022 r2033 15 15 16 16 $self->{schema} = Plagger::Plugin::Store::Fastladder::Schema::Loader->new( 17 @{ $self->conf->{connect_info} }, 17 $self->conf->{connect_info}, 18 { time_zone => $self->conf->{timezone} || $c->conf->{timezone} || 'local' }, 18 19 ); 19 20 branches/fastladder-crawler/plagger/lib/Plagger/Plugin/Store/Fastladder/Schema/Loader.pm
r2011 r2033 11 11 12 12 __PACKAGE__->loader_options( 13 components => [qw/InflateColumn::DateTime/], 14 exclude => qr/^schema_info$/, 13 exclude => qr/^schema_info$/, 15 14 ); 16 15 } 17 16 18 17 sub new { 19 my ($class, @connect_info) = @_;18 my ($class, $connect_info, $options) = @_; 20 19 21 my $schema = Plagger::Plugin::Store::Fastladder::Schema->connect(@ connect_info);20 my $schema = Plagger::Plugin::Store::Fastladder::Schema->connect(@$connect_info); 22 21 croak "cannot load schema info" unless $schema->sources; 23 22 … … 56 55 $favicons->belongs_to( feed => $feeds, 'feed_id' ); 57 56 57 # XXX: setup datetime inflate manually 58 # InflateColumn::DateTime doesn't treat time_zone when it used with Schema::Loader? 59 my $time_zone = $options->{time_zone}; 60 my $parser_class = $schema->storage->datetime_parser; 61 62 for my $source ($schema->sources) { 63 my $rs = $schema->resultset($source); 64 65 for my $column ($source->columns) { 66 my $info = $source->column_info($column); 67 next unless defined $info->{data_type}; 68 69 my $type = lc $info->{data_type}; 70 $type = 'datetime' if $type =~ /^timestamp/; 71 next unless $type eq 'datetime' || $type eq 'date'; 72 73 my ($parse, $format) = ("parse_$type", "format_$type"); 74 $rs->inflate_column( 75 $column => { 76 inflate => sub { 77 my $dt = $parser_class->$parse(shift); 78 $dt->set_time_zone($time_zone) if $time_zone; 79 $dt; 80 }, 81 deflate => sub { 82 my $dt = shift; 83 $dt->set_time_zone($time_zone) if $time_zone; 84 $parser_class->$format($dt); 85 }, 86 }, 87 ); 88 } 89 } 58 90 59 91 $schema;
