DBIx::Class::InflateColumn::TimeMoment - Auto-create TimeMoment objects from date and datetime columns.
version 0.050
Load this component and then declare one or more columns to be of the datetime, timestamp or date datatype.
package Event; use base 'DBIx::Class::Core'; __PACKAGE__->load_components(qw/InflateColumn::TimeMoment/); __PACKAGE__->add_columns( starts_when => { data_type => 'datetime' } create_date => { data_type => 'date' } );
Then you can treat the specified column as a TimeMoment object.
If you want to inflate no matter what data_type your column is, use inflate_datetime or inflate_date:
__PACKAGE__->add_columns( starts_when => { data_type => 'varchar', inflate_datetime => 1 } ); __PACKAGE__->add_columns( starts_when => { data_type => 'varchar', inflate_date => 1 } );
It's also possible to explicitly skip inflation:
__PACKAGE__->add_columns( starts_when => { data_type => 'datetime', inflate_datetime => 0 } );
This module works with Time::Moment IS8601 date formats to inflate/deflate. A later version may handle databases in a more forgiving way, but really why not make them do something sensible.
For more help with using components, see "USING" in DBIx::Class::Manual::Component.
Chains with the "register_column" in DBIx::Class::Row method, and sets up datetime columns appropriately. This would not normally be directly called by end users.
In the case of an invalid date, Time::Moment will throw an exception. To bypass these exceptions and just have the inflation return undef, use the datetime_undef_if_invalid option in the column info:
datetime_undef_if_invalid
"broken_date", { data_type => "datetime", default_value => '0000-00-00', is_nullable => 1, datetime_undef_if_invalid => 1 }
NOTE: Don't rely on InflateColumn::TimeMoment to parse date strings for you. The column is set directly for any non-references and InflateColumn::TimeMoment is completely bypassed. Instead, use an input parser to create a TimeMoment object.
InflateColumn::TimeMoment
As is obvious from a quick inspection of the code, this module is very heavily based on and draws code from DBIx::Class::InflateColumn::DateTime, however it is significantly simplified due to the less well developed timezone handling and formatter ecosystem.
Check the list of additional DBIC resources.
Nigel Metheringham <nigelm@cpan.org>
This software is copyright (c) 2015-2017 by Nigel Metheringham.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install DBIx::Class::InflateColumn::TimeMoment, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::InflateColumn::TimeMoment
CPAN shell
perl -MCPAN -e shell install DBIx::Class::InflateColumn::TimeMoment
For more information on module installation, please visit the detailed CPAN module installation guide.