Commit 67ac35cf authored by Dylan William Hardison's avatar Dylan William Hardison Committed by Давид Добряков

[Bug 1592129] Make Bugzilla::DB::Schema and subclasses Moo-based classes.

This changes the Schema classes enough so they use Moo, which will allow adding a weak reference to the database connection
parent 0310c0cb
......@@ -16,8 +16,7 @@ package Bugzilla::DB::Schema;
###########################################################################
use 5.10.1;
use strict;
use warnings;
use Moo;
use Bugzilla::Error;
use Bugzilla::Hook;
......@@ -1751,33 +1750,29 @@ other modules should not invoke these methods directly.
=cut
#--------------------------------------------------------------------------
sub new {
sub BUILD {
my $self = shift;
my $class = ref($self) || $self;
=over
=item C<new>
Description: Public constructor method used to instantiate objects of this
class.
Parameters: $schema (optional) - A reference to a hash. Callers external
to this package should never use this parameter.
Returns: new instance of the Schema class or a database-specific subclass
die "$class is an abstract base class. Instantiate a subclass instead."
if ($class eq __PACKAGE__);
=cut
$self->_initialize();
} #eosub--BUILD
my $this = shift;
my $class = ref($this) || $this;
# we declare attributes below, even though we access their slots directly.
# This is because this code is evolving from the pre-Moo days of perl OO.
die "$class is an abstract base class. Instantiate a subclass instead."
if ($class eq __PACKAGE__);
# the init_arg begins with an underscore as this should only be passed in internally.
# This should be a 'lazy' attribute, but to maintain the smallest diff we're
# instead setting it in _initialize() if it isn't already passed in.
has 'abstract_schema' => ( init_arg => '_abstract_schema', is => 'rw' );
my $self = {};
bless $self, $class;
$self = $self->_initialize(@_);
# this could also be lazy, but it is also set in _initialize()
has 'schema' => (init_arg =>undef, is => 'rw');
return ($self);
has 'db_specific' => (init_arg => undef, is => 'rw');
} #eosub--new
#--------------------------------------------------------------------------
sub _initialize {
......@@ -1792,17 +1787,12 @@ sub _initialize {
define the database-specific implementation of the all
abstract data types), and then call the C<_adjust_schema>
method.
Parameters: $abstract_schema (optional) - A reference to a hash. If
provided, this hash will be used as the internal
representation of the abstract schema instead of our
default abstract schema. This is intended for internal
use only by deserialize_abstract.
Returns: the instance of the Schema class
=cut
my $self = shift;
my $abstract_schema = shift;
my $abstract_schema = $self->abstract_schema;
if (!$abstract_schema) {
......@@ -2970,7 +2960,7 @@ sub deserialize_abstract {
}
}
return $class->new($thawed_hash);
return $class->new(_abstract_schema => $thawed_hash);
}
#####################################################################
......
......@@ -14,12 +14,11 @@ package Bugzilla::DB::Schema::Mysql;
###############################################################################
use 5.10.1;
use strict;
use warnings;
use Moo;
use Bugzilla::Error;
use base qw(Bugzilla::DB::Schema);
extends qw(Bugzilla::DB::Schema);
# This is for column_info_to_column, to know when a tinyint is a
# boolean and when it's really a tinyint. This only has to be accurate
......@@ -90,7 +89,7 @@ sub _initialize {
my $self = shift;
$self = $self->SUPER::_initialize(@_);
$self = $self->SUPER::_initialize();
$self->{db_specific} = {
......
......@@ -14,10 +14,9 @@ package Bugzilla::DB::Schema::Oracle;
###############################################################################
use 5.10.1;
use strict;
use warnings;
use Moo;
use base qw(Bugzilla::DB::Schema);
extends qw(Bugzilla::DB::Schema);
use Carp qw(confess);
use Bugzilla::Util;
......@@ -34,7 +33,7 @@ sub _initialize {
my $self = shift;
$self = $self->SUPER::_initialize(@_);
$self = $self->SUPER::_initialize();
$self->{db_specific} = {
......
......@@ -14,10 +14,9 @@ package Bugzilla::DB::Schema::Pg;
###############################################################################
use 5.10.1;
use strict;
use warnings;
use Moo;
use base qw(Bugzilla::DB::Schema);
extends qw(Bugzilla::DB::Schema);
use Storable qw(dclone);
#------------------------------------------------------------------------------
......@@ -25,7 +24,7 @@ sub _initialize {
my $self = shift;
$self = $self->SUPER::_initialize(@_);
$self = $self->SUPER::_initialize();
# Remove FULLTEXT index types from the schemas.
foreach my $table (keys %{$self->{schema}}) {
......
......@@ -8,8 +8,7 @@
package Bugzilla::DB::Schema::Sqlite;
use 5.10.1;
use strict;
use warnings;
use Moo;
use base qw(Bugzilla::DB::Schema);
......@@ -24,7 +23,7 @@ sub _initialize {
my $self = shift;
$self = $self->SUPER::_initialize(@_);
$self = $self->SUPER::_initialize();
$self->{db_specific} = {
BOOLEAN => 'integer',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment