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; ...@@ -16,8 +16,7 @@ package Bugzilla::DB::Schema;
########################################################################### ###########################################################################
use 5.10.1; use 5.10.1;
use strict; use Moo;
use warnings;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Hook; use Bugzilla::Hook;
...@@ -1751,33 +1750,29 @@ other modules should not invoke these methods directly. ...@@ -1751,33 +1750,29 @@ other modules should not invoke these methods directly.
=cut =cut
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
sub new { sub BUILD {
my $self = shift;
my $class = ref($self) || $self;
=over die "$class is an abstract base class. Instantiate a subclass instead."
if ($class eq __PACKAGE__);
=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
=cut $self->_initialize();
} #eosub--BUILD
my $this = shift; # we declare attributes below, even though we access their slots directly.
my $class = ref($this) || $this; # 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." # the init_arg begins with an underscore as this should only be passed in internally.
if ($class eq __PACKAGE__); # 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 = {}; # this could also be lazy, but it is also set in _initialize()
bless $self, $class; has 'schema' => (init_arg =>undef, is => 'rw');
$self = $self->_initialize(@_);
return ($self); has 'db_specific' => (init_arg => undef, is => 'rw');
} #eosub--new
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
sub _initialize { sub _initialize {
...@@ -1792,17 +1787,12 @@ sub _initialize { ...@@ -1792,17 +1787,12 @@ sub _initialize {
define the database-specific implementation of the all define the database-specific implementation of the all
abstract data types), and then call the C<_adjust_schema> abstract data types), and then call the C<_adjust_schema>
method. 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 Returns: the instance of the Schema class
=cut =cut
my $self = shift; my $self = shift;
my $abstract_schema = shift; my $abstract_schema = $self->abstract_schema;
if (!$abstract_schema) { if (!$abstract_schema) {
...@@ -2970,7 +2960,7 @@ sub deserialize_abstract { ...@@ -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; ...@@ -14,12 +14,11 @@ package Bugzilla::DB::Schema::Mysql;
############################################################################### ###############################################################################
use 5.10.1; use 5.10.1;
use strict; use Moo;
use warnings;
use Bugzilla::Error; 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 # 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 # boolean and when it's really a tinyint. This only has to be accurate
...@@ -90,7 +89,7 @@ sub _initialize { ...@@ -90,7 +89,7 @@ sub _initialize {
my $self = shift; my $self = shift;
$self = $self->SUPER::_initialize(@_); $self = $self->SUPER::_initialize();
$self->{db_specific} = { $self->{db_specific} = {
......
...@@ -14,10 +14,9 @@ package Bugzilla::DB::Schema::Oracle; ...@@ -14,10 +14,9 @@ package Bugzilla::DB::Schema::Oracle;
############################################################################### ###############################################################################
use 5.10.1; use 5.10.1;
use strict; use Moo;
use warnings;
use base qw(Bugzilla::DB::Schema); extends qw(Bugzilla::DB::Schema);
use Carp qw(confess); use Carp qw(confess);
use Bugzilla::Util; use Bugzilla::Util;
...@@ -34,7 +33,7 @@ sub _initialize { ...@@ -34,7 +33,7 @@ sub _initialize {
my $self = shift; my $self = shift;
$self = $self->SUPER::_initialize(@_); $self = $self->SUPER::_initialize();
$self->{db_specific} = { $self->{db_specific} = {
......
...@@ -14,10 +14,9 @@ package Bugzilla::DB::Schema::Pg; ...@@ -14,10 +14,9 @@ package Bugzilla::DB::Schema::Pg;
############################################################################### ###############################################################################
use 5.10.1; use 5.10.1;
use strict; use Moo;
use warnings;
use base qw(Bugzilla::DB::Schema); extends qw(Bugzilla::DB::Schema);
use Storable qw(dclone); use Storable qw(dclone);
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
...@@ -25,7 +24,7 @@ sub _initialize { ...@@ -25,7 +24,7 @@ sub _initialize {
my $self = shift; my $self = shift;
$self = $self->SUPER::_initialize(@_); $self = $self->SUPER::_initialize();
# Remove FULLTEXT index types from the schemas. # Remove FULLTEXT index types from the schemas.
foreach my $table (keys %{$self->{schema}}) { foreach my $table (keys %{$self->{schema}}) {
......
...@@ -8,8 +8,7 @@ ...@@ -8,8 +8,7 @@
package Bugzilla::DB::Schema::Sqlite; package Bugzilla::DB::Schema::Sqlite;
use 5.10.1; use 5.10.1;
use strict; use Moo;
use warnings;
use base qw(Bugzilla::DB::Schema); use base qw(Bugzilla::DB::Schema);
...@@ -24,7 +23,7 @@ sub _initialize { ...@@ -24,7 +23,7 @@ sub _initialize {
my $self = shift; my $self = shift;
$self = $self->SUPER::_initialize(@_); $self = $self->SUPER::_initialize();
$self->{db_specific} = { $self->{db_specific} = {
BOOLEAN => 'integer', 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