]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
[Bug 1592129] Make Bugzilla::DB::Schema and subclasses Moo-based classes.
authorDylan William Hardison <dylan@hardison.net>
Sat, 1 Feb 2020 15:36:42 +0000 (16:36 +0100)
committerGitHub <noreply@github.com>
Sat, 1 Feb 2020 15:36:42 +0000 (16:36 +0100)
This changes the Schema classes enough so they use Moo, which will allow adding a weak reference to the database connection

Bugzilla/DB/Schema.pm
Bugzilla/DB/Schema/Mysql.pm
Bugzilla/DB/Schema/Oracle.pm
Bugzilla/DB/Schema/Pg.pm
Bugzilla/DB/Schema/Sqlite.pm

index 6e15ef1db77f55e5d4f0e78f77224430e0f87890..053ec389af505d98a8441c21fbec54699c78a6d4 100644 (file)
@@ -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);
 }
 
 #####################################################################
index 3ca54549d3d3d29df8ea8f3fbf0a4d31ac390eff..2ab649596f1b2663527504d69cb776e95fb8e8ab 100644 (file)
@@ -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} = {
 
index 3f589b337851782ecbc23461c22f9bd0c1442bdf..891896efc3e384ad2a15dae56429d6f9a0395190 100644 (file)
@@ -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} = {
 
index 908ad86924736382427efd406ff7c97bed0d353c..6249bb639846ee0b4d09744e86b4abc9d409d11f 100644 (file)
@@ -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}}) {
index 5173ae3bd8a761abf1670b35439d75aa8e77f85b..06488818b16646152eef930726096dc9fea6e581 100644 (file)
@@ -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',