From 824bb3102b852179efb655f754ff679c0f36b0b5 Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Thu, 19 Oct 2017 15:19:52 +0200 Subject: [PATCH] TT#23774 remove Moose completely and clean up the dependencies by throwing out libraries we don't use Change-Id: Ia88a9d9f9d6744178ee382fb4a2311c1608cef32 --- Build.PL | 5 - debian/control | 18 --- lib/NGCP/InterceptSchema.pm | 11 +- lib/NGCP/Schema.pm | 57 +++------ lib/NGCP/Schema/Config.pm | 107 ++++------------ lib/NGCP/Schema/Exception.pm | 118 ------------------ .../Schema/Storage/DateTime/Format/MySQL.pm | 1 + 7 files changed, 48 insertions(+), 269 deletions(-) delete mode 100644 lib/NGCP/Schema/Exception.pm diff --git a/Build.PL b/Build.PL index 4ec9743d..6e5028f6 100644 --- a/Build.PL +++ b/Build.PL @@ -16,11 +16,6 @@ my $builder = Module::Build->new( 'DBIx::Class::Schema::Loader' => 0, 'File::Path' => 0, 'Getopt::Long' => 0, - 'MooseX::ClassAttribute' => 0, - 'MooseX::NonMoose' => 0, - 'MooseX::Singleton' => 0, - 'MooseX::Types::Path::Class' => 0, - 'namespace::sweep' => 0, 'Quantum::Superpositions' => 0, 'Pod::Usage' => 0, 'Regexp::Common' => 0, diff --git a/debian/control b/debian/control index 68e63550..446888a8 100644 --- a/debian/control +++ b/debian/control @@ -18,13 +18,7 @@ Build-Depends: libgetopt-long-descriptive-perl, libgtk2-gladexml-simple-perl, libhash-storediterator-perl, - liblog-log4perl-perl, libmodule-build-perl, - libmoosex-classattribute-perl, - libmoosex-nonmoose-perl, - libmoosex-singleton-perl, - libmoosex-types-path-class-perl, - libnamespace-sweep-perl, libquantum-superpositions-perl, libregexp-common-email-address-perl, libregexp-common-net-cidr-perl, @@ -35,11 +29,8 @@ Build-Depends: libtemplate-plugin-xml-perl, libtest-fatal-perl, libtest-xml-simple-perl, - libthrowable-perl, libxml-libxml-simple-perl, libxml-simple-perl, - libxml-simpleobject-libxml-perl, - libxml-simpleobject-perl, perl-doc, Standards-Version: 3.9.8 Homepage: https://www.sipwise.com/ @@ -61,12 +52,6 @@ Depends: libgetopt-long-descriptive-perl, libgtk2-gladexml-simple-perl, libhash-storediterator-perl, - liblog-log4perl-perl, - libmoosex-classattribute-perl, - libmoosex-nonmoose-perl, - libmoosex-singleton-perl, - libmoosex-types-path-class-perl, - libnamespace-sweep-perl, libparse-debianchangelog-perl, libquantum-superpositions-perl, libregexp-common-email-address-perl, @@ -78,11 +63,8 @@ Depends: libtemplate-plugin-xml-perl, libtest-fatal-perl, libtest-xml-simple-perl, - libthrowable-perl, libxml-libxml-simple-perl, libxml-simple-perl, - libxml-simpleobject-libxml-perl, - libxml-simpleobject-perl, perl-doc, ${misc:Depends}, ${perl:Depends}, diff --git a/lib/NGCP/InterceptSchema.pm b/lib/NGCP/InterceptSchema.pm index 5a41e6b5..e11a2a7a 100644 --- a/lib/NGCP/InterceptSchema.pm +++ b/lib/NGCP/InterceptSchema.pm @@ -1,13 +1,16 @@ package NGCP::InterceptSchema; -use Moose; -extends 'NGCP::Schema'; + +use warnings; +use strict; + +use base 'NGCP::Schema'; our $VERSION = '2.007'; sub connection { my ($self) = @_; - $self->SUPER::connection($self->config->as_hash->{ngcp_intercept_connect_info}); + my $full_config = NGCP::Schema::Config::get_config_hash(); + $self->SUPER::connection($full_config->{ngcp_intercept_connect_info}); } -no Moose; 1; diff --git a/lib/NGCP/Schema.pm b/lib/NGCP/Schema.pm index 939e2646..77e63c93 100644 --- a/lib/NGCP/Schema.pm +++ b/lib/NGCP/Schema.pm @@ -1,12 +1,10 @@ package NGCP::Schema; + use Sipwise::Base; -use aliased 'NGCP::Schema::Exception'; use NGCP::Schema::Config qw(); use Regexp::Common qw(net); use Regexp::IPv6 qw($IPv6_re); -use Moose; -use MooseX::ClassAttribute qw(class_has); -extends 'DBIx::Class::Schema'; +use base 'DBIx::Class::Schema'; our $VERSION = '2.007'; @@ -17,45 +15,36 @@ __PACKAGE__->load_namespaces( use DBIx::Class::Storage::DBI; DBIx::Class::Storage::DBI->datetime_parser_type('NGCP::Schema::Storage::DateTime::Format::MySQL'); -class_has('config', is => 'rw', isa => 'NGCP::Schema::Config', lazy => 1, default => sub { - return NGCP::Schema::Config->instance; -}); - sub connection { my ($self, $cfg) = @_; + my $config_file_name; if ($cfg->{config_file}) { - $self->config->config_file($cfg->{config_file}); + $config_file_name = $cfg->{config_file}; + } else { + $config_file_name = NGCP::Schema::Config::get_config_filename(); } unless(defined $cfg->{dsn}) { - $cfg = $self->config->as_hash->{ngcp_connect_info}; + my $full_config = NGCP::Schema::Config::get_config_hash($config_file_name); + $cfg = $full_config->{ngcp_connect_info}; } $self->SUPER::connection($cfg); } sub validate { my ($self, $data, $mandatory_params, $optional_params) = @_; - Exception->throw({ - description => 'Client.Syntax.MissingParam', - message => q(missing parameter 'data'), - }) unless defined $data; - Exception->throw({ - description => 'Client.Syntax.MalformedParam', - message => q(parameter 'data' should be an object/hash, but is '%s')->sprintf(ref $data) - }) unless defined eval { %$data }; + die q(missing parameter 'data') + unless defined $data; + die q(parameter 'data' should be an object/hash, but is '%s')->sprintf(ref $data) + unless defined eval { %$data }; my %check_data = %$data; for my $param (@$mandatory_params) { - Exception->throw({ - description => 'Client.Syntax.MissingParam', - message => "missing parameter '$param' in request" - }) unless exists $check_data{$param}; + die "missing parameter '$param' in request" + unless exists $check_data{$param}; delete $check_data{$param}; } foreach my $key (keys %check_data) { next if grep { $key eq $_ } @$optional_params; - Exception->throw({ - description => 'Client.Syntax.UnknownParam', - message => "unknown parameter '$key'", - }); + die "unknown parameter '$key'"; } return; } @@ -65,7 +54,7 @@ sub check_domain { $self->validate($data, ['domain']); my $domain = $data->{domain}; return 1 if $domain =~ /^(?:[a-z0-9]+(?:-[a-z0-9]+)*\.)+[a-z]+$/i; - return 1 if $self->config->as_hash->{allow_ip_as_domain} + return 1 if NGCP::Schema::Config::get_config_hash->{allow_ip_as_domain} and ($self->check_ip4({ip4 => $domain}) || $self->check_ip6_brackets({ip6brackets => $domain})); return; } @@ -99,8 +88,6 @@ sub _check_ip_generic { return; } -__PACKAGE__->meta->make_immutable; -no Moose; 1; __END__ @@ -111,10 +98,6 @@ __END__ NGCP::Schema - DBIC-derived ORM schema classes -=head1 VERSION - -This document describes NGCP::Schema version 2.007 - =head1 SYNOPSIS use NGCP::Schema::accounting; @@ -153,15 +136,11 @@ Version 2 moves the result classes of all tables into one namespace. This means This is solved by prefixing the result class name I with the database name and an underscore, e.g. table C becomes the result class . -=head1 BUGS AND LIMITATIONS - -L - =head1 AUTHOR -Lars Dieckow C<< >> +Sipwise Development Team C<< >> -=head1 LICENCE +=head1 LICENSE This software is Copyright © 2013 by Sipwise GmbH, Austria. diff --git a/lib/NGCP/Schema/Config.pm b/lib/NGCP/Schema/Config.pm index d618e005..00b2032e 100644 --- a/lib/NGCP/Schema/Config.pm +++ b/lib/NGCP/Schema/Config.pm @@ -1,35 +1,26 @@ package NGCP::Schema::Config; + use Sipwise::Base; -use Log::Log4perl qw(); -use MooseX::Types::Path::Class qw(File); -use MooseX::Singleton qw(has); use XML::Simple qw(); -our $VERSION = '2.007'; - -has 'config_file' => ( - is => 'rw', - isa => File, - required => 1, - coerce => 1, - default => '/etc/ngcp-panel/provisioning.conf' -); - -has('as_hash', isa => 'HashRef', is => 'rw', lazy => 1, default => sub { - my ($self) = @_; - return $self->check_config(XML::Simple->new->XMLin($self->config_file->stringify, ForceArray => 0)); -}); - -sub BUILD { - my ($self) = @_; - die q(can't find config file %s)->sprintf($self->config_file) - unless -e $self->config_file; - Log::Log4perl->init_once($self->config->{logconf}); - Log::Log4perl->get_logger($self)->info('using config file "%s"'->sprintf($self->config_file)); +my $_config; + +sub get_config_filename { + return '/etc/ngcp-panel/provisioning.conf'; +} + +sub get_config_hash { + my ($config_file) = @_; + $config_file //= get_config_filename; + unless ($_config) { + my $tmp_config = XML::Simple->new->XMLin($config_file, ForceArray => 0); + $_config = check_config($tmp_config); + } + return $_config; } sub check_config { - my ($self, $config) = @_; + my ($config) = @_; $config->{vsc}{actions} = [$config->{vsc}{actions}] if defined $config->{vsc} and defined $config->{vsc}{actions} @@ -51,7 +42,7 @@ sub check_config { return $config; } -__PACKAGE__->meta->make_immutable; +1; __END__ @@ -61,76 +52,22 @@ __END__ NGCP::Schema::Config - configuration class -=head1 VERSION - -This document describes NGCP::Schema::Config version 2.007 - =head1 SYNOPSIS use NGCP::Schema::Config qw(); - my $c_hashref = NGCP::Schema::Config->new; + my $c_hashref = NGCP::Schema::Config::get_config_hash(); =head1 DESCRIPTION -Reads a configuration file, initialises the logger, provides configuration as structured data. - -=head1 INTERFACE - -=head2 Attributes - -=head3 C - -Type C, B attribute, location of the configuration file. Default is -C. - -=head3 C - -Type C, supplies configuration from the L. - -=head2 Methods - -=head3 C - -Takes hashref as just parsed by the configuration file reader and makes sure it is formatted correctly. At the moment, -it only ensures that arrays are arrays even if there is only one member. - -=head1 DIAGNOSTICS - -=over - -=item C - -The configuration file does not exist. - -=back - -=head1 CONFIGURATION AND ENVIRONMENT - -See L. - -The meaning of the configuration items are detailed in the manual. - -=head1 DEPENDENCIES - -See meta file in the source distribution. - -=head1 INCOMPATIBILITIES - -None reported. - -=head1 BUGS AND LIMITATIONS - -L - -No known limitations. +Reads a configuration file, provides configuration as structured data. =head1 AUTHOR -Lars Dieckow C<< >> +Sipwise Development Team C<< >> -=head1 LICENCE +=head1 LICENSE -This software is Copyright © 2013 by Sipwise GmbH, Austria. +This software is Copyright © 2017 by Sipwise GmbH, Austria. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public diff --git a/lib/NGCP/Schema/Exception.pm b/lib/NGCP/Schema/Exception.pm deleted file mode 100644 index 18059559..00000000 --- a/lib/NGCP/Schema/Exception.pm +++ /dev/null @@ -1,118 +0,0 @@ -package NGCP::Schema::Exception; -use Sipwise::Base; -use Moose; -our $VERSION = '2.007'; - -extends 'Throwable::Error'; -has('description', is => 'ro', isa => 'Str', required => 1); -has('context', is => 'ro', isa => 'HashRef', documentation => 'extra data to pass along'); - -no Moose; - -__PACKAGE__->meta->make_immutable(inline_constructor => 0); - -__END__ - -=encoding UTF-8 - -=head1 NAME - -NGCP::Schema::Exception - exceptions that work like ossbss mydie - -=head1 VERSION - -This document describes NGCP::Schema::Exception version 2.007 - -=head1 SYNOPSIS - - use aliased 'NGCP::Schema::Exception'; - Exception->throw({ - description => 'Client.Auth.Failed', - message => 'authentication failed', - }); - -=head1 DESCRIPTION - -This is a stop-gap measure to port ossbss code. - -=head1 INTERFACE - -=head2 Composition - - NGCP::Schema::Exception - ISA Throwable::Error - -All methods and attributes not mentioned here are inherited from L. - -=head2 Attributes - -=head3 C - -Type C, B attribute, designates the ossbss error type. - -=head3 C - -Type C, extra data to pass along to the error handler. - -=head2 Exports - -None. - -=head1 DIAGNOSTICS - -None. - -=head1 CONFIGURATION AND ENVIRONMENT - -NGCP::Schema::Exception requires no configuration files or environment variables. - -=head1 DEPENDENCIES - -See meta file in the source distribution. - -=head1 INCOMPATIBILITIES - -None reported. - -=head1 BUGS AND LIMITATIONS - -L - -No known limitations. - -=head1 TO DO - -This becomes obsolete with a hierarchy of exception classes. - -=head1 SEE ALSO - -L - -=head1 AUTHOR - -Lars Dieckow C<< >> - -=head1 LICENCE - -This software is Copyright © 2013 by Sipwise GmbH, Austria. - -This program is free software; you can redistribute it -and/or modify it under the terms of the GNU General Public -License as published by the Free Software Foundation; either -version 3 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be -useful, but WITHOUT ANY WARRANTY; without even the implied -warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more -details. - -You should have received a copy of the GNU General Public -License along with this package; if not, write to the Free -Software Foundation, Inc., 51 Franklin St, Fifth Floor, -Boston, MA 02110-1301 USA - -On Debian systems, the full text of the GNU General Public -License version 3 can be found in the file -F. diff --git a/lib/NGCP/Schema/Storage/DateTime/Format/MySQL.pm b/lib/NGCP/Schema/Storage/DateTime/Format/MySQL.pm index af0e0ac2..54b1efbc 100644 --- a/lib/NGCP/Schema/Storage/DateTime/Format/MySQL.pm +++ b/lib/NGCP/Schema/Storage/DateTime/Format/MySQL.pm @@ -1,6 +1,7 @@ package NGCP::Schema::Storage::DateTime::Format::MySQL; use strict; +use warnings; use vars qw ($VERSION);