From: Dylan William Hardison Date: Sun, 15 Dec 2019 18:56:37 +0000 (-0500) Subject: Make Bugzilla::DB::Schema and subclasses Moo-based classes. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2be2071fa3b0d74f94d2b7b0692d5f2fcaede51b;p=thirdparty%2Fbugzilla.git Make Bugzilla::DB::Schema and subclasses Moo-based classes. --- diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index 6e15ef1db7..053ec389af 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -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 - - 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); } ##################################################################### diff --git a/Bugzilla/DB/Schema/Mysql.pm b/Bugzilla/DB/Schema/Mysql.pm index 3ca54549d3..2ab649596f 100644 --- a/Bugzilla/DB/Schema/Mysql.pm +++ b/Bugzilla/DB/Schema/Mysql.pm @@ -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} = { diff --git a/Bugzilla/DB/Schema/Oracle.pm b/Bugzilla/DB/Schema/Oracle.pm index 3f589b3378..891896efc3 100644 --- a/Bugzilla/DB/Schema/Oracle.pm +++ b/Bugzilla/DB/Schema/Oracle.pm @@ -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} = { diff --git a/Bugzilla/DB/Schema/Pg.pm b/Bugzilla/DB/Schema/Pg.pm index 908ad86924..6249bb6398 100644 --- a/Bugzilla/DB/Schema/Pg.pm +++ b/Bugzilla/DB/Schema/Pg.pm @@ -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}}) { diff --git a/Bugzilla/DB/Schema/Sqlite.pm b/Bugzilla/DB/Schema/Sqlite.pm index 5173ae3bd8..06488818b1 100644 --- a/Bugzilla/DB/Schema/Sqlite.pm +++ b/Bugzilla/DB/Schema/Sqlite.pm @@ -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',