X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FVersioned.pm;h=d59961fec14f07e1102239bbb49a9996e224d067;hb=08a8d8f1b8a69ea29bcceb9f399214943a34905c;hp=95adc66b0daf2138187c2dabd1c80a457e8b67ed;hpb=77c3a5dca478801246ff728f80a0c5013e57f4a2;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Schema/Versioned.pm b/lib/DBIx/Class/Schema/Versioned.pm index 95adc66..d59961f 100644 --- a/lib/DBIx/Class/Schema/Versioned.pm +++ b/lib/DBIx/Class/Schema/Versioned.pm @@ -202,8 +202,9 @@ use warnings; use base 'DBIx::Class::Schema'; use DBIx::Class::Carp; +use DBIx::Class::_Util 'dbic_internal_try'; use Time::HiRes qw/gettimeofday/; -use Try::Tiny; +use Scalar::Util 'weaken'; use namespace::clean; __PACKAGE__->mk_classdata('_filedata'); @@ -238,7 +239,7 @@ Call this to initialise a previously unversioned database. The table 'dbix_class Takes one argument which should be the version that the database is currently at. Defaults to the return value of L. -See L for more details. +See L for more details. =cut @@ -526,7 +527,7 @@ sub get_db_version my ($self, $rs) = @_; my $vtable = $self->{vschema}->resultset('Table'); - my $version = try { + my $version = dbic_internal_try { $vtable->search({}, { order_by => { -desc => 'installed' }, rows => 1 } ) ->get_column ('version') ->next; @@ -589,9 +590,10 @@ sub _on_connect { my ($self) = @_; - my $conn_info = $self->storage->connect_info; - $self->{vschema} = DBIx::Class::Version->connect(@$conn_info); - my $conn_attrs = $self->{vschema}->storage->_dbic_connect_attributes || {}; + weaken (my $w_self = $self ); + + $self->{vschema} = DBIx::Class::Version->connect(sub { $w_self->storage->dbh }); + my $conn_attrs = $self->storage->_dbic_connect_attributes || {}; my $vtable = $self->{vschema}->resultset('Table'); @@ -600,7 +602,7 @@ sub _on_connect # check for legacy versions table and move to new if exists unless ($self->_source_exists($vtable)) { - my $vtable_compat = DBIx::Class::VersionCompat->connect(@$conn_info)->resultset('TableCompat'); + my $vtable_compat = DBIx::Class::VersionCompat->connect(sub { $w_self->storage->dbh })->resultset('TableCompat'); if ($self->_source_exists($vtable_compat)) { $self->{vschema}->deploy; map { $vtable->new_result({ installed => $_->Installed, version => $_->Version })->insert } $vtable_compat->all; @@ -640,8 +642,8 @@ sub _create_db_to_schema_diff { return; } - unless (DBIx::Class::Optional::Dependencies->req_ok_for ('deploy')) { - $self->throw_exception("Unable to proceed without " . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') ); + if ( my $missing = DBIx::Class::Optional::Dependencies->req_missing_for('deploy') ) { + $self->throw_exception("Unable to proceed without $missing"); } my $db_tr = SQL::Translator->new({ @@ -744,23 +746,28 @@ sub _read_sql_file { sub _source_exists { - my ($self, $rs) = @_; - - return try { - $rs->search(\'1=0')->cursor->next; - 1; - } catch { - 0; - }; + my ($self, $rs) = @_; + + ( dbic_internal_try { + $rs->search(\'1=0')->cursor->next; + 1; + } ) + ? 1 + : 0 + ; } -1; +=head1 FURTHER QUESTIONS? +Check the list of L. -=head1 AUTHOR AND CONTRIBUTORS +=head1 COPYRIGHT AND LICENSE -See L and L in DBIx::Class +This module is free software L +by the L. You can +redistribute it and/or modify it under the same terms as the +L. -=head1 LICENSE +=cut -You may distribute this code under the same terms as Perl itself. +1;