From: Peter Rabbitson Date: Tue, 1 Mar 2011 08:14:55 +0000 (+0100) Subject: Switch sql_maker_class and datetime_parser_type to component_class accessors X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6f7a118e7728040e015699975dafde1a1fb81538;p=dbsrgits%2FDBIx-Class-Historic.git Switch sql_maker_class and datetime_parser_type to component_class accessors --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 153b287..2dc005c 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -22,12 +22,15 @@ use namespace::clean; __PACKAGE__->cursor_class('DBIx::Class::Storage::DBI::Cursor'); __PACKAGE__->mk_group_accessors('inherited' => qw/ - sql_maker_class sql_limit_dialect sql_quote_char sql_name_sep + sql_limit_dialect sql_quote_char sql_name_sep /); -__PACKAGE__->sql_name_sep('.'); +__PACKAGE__->mk_group_accessors('component_class' => qw/sql_maker_class datetime_parser_type/); __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker'); +__PACKAGE__->datetime_parser_type('DateTime::Format::MySQL'); # historic default + +__PACKAGE__->sql_name_sep('.'); __PACKAGE__->mk_group_accessors('simple' => qw/ _connect_info _dbi_connect_info _dbic_connect_attributes _driver_determined @@ -107,7 +110,15 @@ for my $meth (@rdbms_specific_methods) { no strict qw/refs/; no warnings qw/redefine/; *{__PACKAGE__ ."::$meth"} = subname $meth => sub { - if (not $_[0]->_driver_determined and not $_[0]->{_in_determine_driver}) { + if ( + # only fire when invoked on an instance, a valid class-based invocation + # would e.g. be setting a default for an inherited accessor + ref $_[0] + and + ! $_[0]->_driver_determined + and + ! $_[0]->{_in_determine_driver} + ) { $_[0]->_determine_driver; # This for some reason crashes and burns on perl 5.8.1 @@ -117,6 +128,7 @@ for my $meth (@rdbms_specific_methods) { my $cref = $_[0]->can ($meth); goto $cref; } + goto $orig; }; } @@ -993,7 +1005,6 @@ sub sql_maker { my ($self) = @_; unless ($self->_sql_maker) { my $sql_maker_class = $self->sql_maker_class; - $self->ensure_class_loaded ($sql_maker_class); my %opts = %{$self->_sql_maker_opts||{}}; my $dialect = @@ -2822,12 +2833,7 @@ sub datetime_parser { =head2 datetime_parser_type -Defines (returns) the datetime parser class - currently hardwired to -L - -=cut - -sub datetime_parser_type { "DateTime::Format::MySQL"; } +Defines the datetime parser class - currently defaults to L =head2 build_datetime_parser @@ -2838,7 +2844,6 @@ See L sub build_datetime_parser { my $self = shift; my $type = $self->datetime_parser_type(@_); - $self->ensure_class_loaded ($type); return $type; } diff --git a/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm index 7c053af..efe32b6 100644 --- a/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Storage/DBI/ADO/Microsoft_SQL_Server.pm @@ -57,6 +57,10 @@ currently supported, datetimes are truncated at the second. =cut +__PACKAGE__->datetime_parser_type ( + 'DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::DateTime::Format' +); + sub _rebless { my $self = shift; $self->_identity_method('@@identity'); @@ -142,10 +146,6 @@ sub _mssql_max_data_type_representation_size_in_bytes { } } -sub datetime_parser_type { - 'DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::DateTime::Format' -} - package # hide from PAUSE DBIx::Class::Storage::DBI::ADO::Microsoft_SQL_Server::DateTime::Format; diff --git a/lib/DBIx/Class/Storage/DBI/DB2.pm b/lib/DBIx/Class/Storage/DBI/DB2.pm index 66851d8..31b9230 100644 --- a/lib/DBIx/Class/Storage/DBI/DB2.pm +++ b/lib/DBIx/Class/Storage/DBI/DB2.pm @@ -8,6 +8,7 @@ use mro 'c3'; __PACKAGE__->sql_limit_dialect ('RowNumberOver'); __PACKAGE__->sql_quote_char ('"'); +__PACKAGE__->datetime_parser_type('DateTime::Format::DB2'); sub _dbh_last_insert_id { my ($self, $dbh, $source, $col) = @_; @@ -20,7 +21,6 @@ sub _dbh_last_insert_id { return @res ? $res[0] : undef; } -sub datetime_parser_type { "DateTime::Format::DB2"; } 1; diff --git a/lib/DBIx/Class/Storage/DBI/Informix.pm b/lib/DBIx/Class/Storage/DBI/Informix.pm index 90587d0..21401f4 100644 --- a/lib/DBIx/Class/Storage/DBI/Informix.pm +++ b/lib/DBIx/Class/Storage/DBI/Informix.pm @@ -11,6 +11,10 @@ use namespace::clean; __PACKAGE__->sql_limit_dialect ('SkipFirst'); __PACKAGE__->sql_quote_char ('"'); +__PACKAGE__->datetime_parser_type ( + 'DBIx::Class::Storage::DBI::Informix::DateTime::Format' +); + __PACKAGE__->mk_group_accessors('simple' => '__last_insert_id'); @@ -117,10 +121,6 @@ sub connect_call_datetime_setup { $ENV{GL_DATETIME} = "%Y-%m-%d %H:%M:%S%F5"; } -sub datetime_parser_type { - 'DBIx::Class::Storage::DBI::Informix::DateTime::Format' -} - package # hide from PAUSE DBIx::Class::Storage::DBI::Informix::DateTime::Format; diff --git a/lib/DBIx/Class/Storage/DBI/InterBase.pm b/lib/DBIx/Class/Storage/DBI/InterBase.pm index ab8bc70..9651277 100644 --- a/lib/DBIx/Class/Storage/DBI/InterBase.pm +++ b/lib/DBIx/Class/Storage/DBI/InterBase.pm @@ -35,6 +35,9 @@ L. __PACKAGE__->_use_insert_returning (1); __PACKAGE__->sql_limit_dialect ('FirstSkip'); __PACKAGE__->sql_quote_char ('"'); +__PACKAGE__->datetime_parser_type( + 'DBIx::Class::Storage::DBI::InterBase::DateTime::Format' +); sub _sequence_fetch { my ($self, $nextval, $sequence) = @_; @@ -222,9 +225,6 @@ sub connect_call_datetime_setup { $self->_get_dbh->{ib_time_all} = 'ISO'; } -sub datetime_parser_type { - 'DBIx::Class::Storage::DBI::InterBase::DateTime::Format' -} package # hide from PAUSE DBIx::Class::Storage::DBI::InterBase::DateTime::Format; diff --git a/lib/DBIx/Class/Storage/DBI/MSSQL.pm b/lib/DBIx/Class/Storage/DBI/MSSQL.pm index d4f87cc..07d3a4f 100644 --- a/lib/DBIx/Class/Storage/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Storage/DBI/MSSQL.pm @@ -17,6 +17,11 @@ __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::MSSQL'); __PACKAGE__->sql_quote_char([qw/[ ]/]); +__PACKAGE__->datetime_parser_type ( + 'DBIx::Class::Storage::DBI::MSSQL::DateTime::Format' +); + + __PACKAGE__->new_guid('NEWID()'); sub _set_identity_insert { @@ -180,10 +185,6 @@ sub _svp_rollback { $self->_get_dbh->do("ROLLBACK TRANSACTION $name"); } -sub datetime_parser_type { - 'DBIx::Class::Storage::DBI::MSSQL::DateTime::Format' -} - sub sqlt_type { 'SQLServer' } sub sql_limit_dialect { diff --git a/lib/DBIx/Class/Storage/DBI/ODBC/Firebird.pm b/lib/DBIx/Class/Storage/DBI/ODBC/Firebird.pm index 6f6acdf..0784e24 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC/Firebird.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC/Firebird.pm @@ -26,6 +26,8 @@ under L. =cut +__PACKAGE__->datetime_parser_type ('DBIx::Class::Storage::DBI::ODBC::Firebird::DateTime::Format'); + # XXX seemingly no equivalent to ib_time_all from DBD::InterBase via ODBC sub connect_call_datetime_setup { 1 } @@ -38,10 +40,6 @@ sub _set_sql_dialect { 1 } # releasing savepoints doesn't work, but that shouldn't matter sub _svp_release { 1 } -sub datetime_parser_type { - 'DBIx::Class::Storage::DBI::ODBC::Firebird::DateTime::Format' -} - package # hide from PAUSE DBIx::Class::Storage::DBI::ODBC::Firebird::DateTime::Format; diff --git a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm index 79896d8..d049d6c 100644 --- a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm +++ b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm @@ -80,6 +80,7 @@ use base qw/DBIx::Class::Storage::DBI/; use mro 'c3'; __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::Oracle'); +__PACKAGE__->datetime_parser_type('DateTime::Format::Oracle'); sub _determine_supports_insert_returning { my $self = shift; @@ -335,10 +336,6 @@ sub get_autoinc_seq { This sets the proper DateTime::Format module for use with L. -=cut - -sub datetime_parser_type { return "DateTime::Format::Oracle"; } - =head2 connect_call_datetime_setup Used as: diff --git a/lib/DBIx/Class/Storage/DBI/Pg.pm b/lib/DBIx/Class/Storage/DBI/Pg.pm index 0673fe8..785a67b 100644 --- a/lib/DBIx/Class/Storage/DBI/Pg.pm +++ b/lib/DBIx/Class/Storage/DBI/Pg.pm @@ -15,6 +15,7 @@ use namespace::clean; __PACKAGE__->sql_limit_dialect ('LimitOffset'); __PACKAGE__->sql_quote_char ('"'); +__PACKAGE__->datetime_parser_type ('DateTime::Format::Pg'); # Ask for a DBD::Pg with array support warn __PACKAGE__.": DBD::Pg 2.9.2 or greater is strongly recommended\n" @@ -166,8 +167,6 @@ sub sqlt_type { return 'PostgreSQL'; } -sub datetime_parser_type { return "DateTime::Format::Pg"; } - sub bind_attribute_by_data_type { my ($self,$data_type) = @_; diff --git a/lib/DBIx/Class/Storage/DBI/SQLite.pm b/lib/DBIx/Class/Storage/DBI/SQLite.pm index b87c63a..0fa8e75 100644 --- a/lib/DBIx/Class/Storage/DBI/SQLite.pm +++ b/lib/DBIx/Class/Storage/DBI/SQLite.pm @@ -9,6 +9,7 @@ use mro 'c3'; __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::SQLite'); __PACKAGE__->sql_limit_dialect ('LimitOffset'); __PACKAGE__->sql_quote_char ('"'); +__PACKAGE__->datetime_parser_type ('DateTime::Format::SQLite'); sub backup { @@ -63,8 +64,6 @@ sub deployment_statements { $self->next::method($schema, $type, $version, $dir, $sqltargs, @rest); } -sub datetime_parser_type { return "DateTime::Format::SQLite"; } - =head2 connect_call_use_foreign_keys Used as: diff --git a/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm b/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm index 52e90bf..906d3ae 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase/ASE.pm @@ -18,6 +18,7 @@ use namespace::clean; __PACKAGE__->sql_limit_dialect ('RowCountOrGenericSubQ'); __PACKAGE__->sql_quote_char ([qw/[ ]/]); +__PACKAGE__->datetime_parser_type('DateTime::Format::Sybase'); __PACKAGE__->mk_group_accessors('simple' => qw/_identity _blob_log_on_update _writer_storage _is_extra_storage @@ -888,7 +889,6 @@ C columns only have minute precision. } } -sub datetime_parser_type { "DateTime::Format::Sybase" } # ->begin_work and such have no effect with FreeTDS but we run them anyway to # let the DBD keep any state it needs to. diff --git a/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm index 4b55929..71d6e34 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm @@ -10,6 +10,10 @@ use base qw/ use mro 'c3'; use Carp::Clan qw/^DBIx::Class/; +__PACKAGE__->datetime_parser_type( + 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format' +); + sub _rebless { my $self = shift; my $dbh = $self->_get_dbh; @@ -105,9 +109,6 @@ C columns only have minute precision. } } -sub datetime_parser_type { - 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format' -} package # hide from PAUSE DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format;