diff --git a/lib/NGCP/Panel/Utils/RedisLocationResultSet.pm b/lib/NGCP/Panel/Utils/RedisLocationResultSet.pm index a867f69465..9ff1c2593c 100644 --- a/lib/NGCP/Panel/Utils/RedisLocationResultSet.pm +++ b/lib/NGCP/Panel/Utils/RedisLocationResultSet.pm @@ -1,37 +1,54 @@ package NGCP::Panel::Utils::RedisLocationResultSet; -use Moose; +use Moo; use TryCatch; +use NGCP::Panel::Utils::Generic qw(:all); use NGCP::Panel::Utils::RedisLocationResultSource; use Data::Dumper; +use Time::HiRes qw(time); has _c => ( is => 'ro', - isa => 'NGCP::Panel', + isa => sub { die "$_[0] must be NGCP::Panel" unless $_[0] && ref $_[0] eq 'NGCP::Panel' }, ); has _redis => ( is => 'ro', - isa => 'Redis', + isa => sub { die "$_[0] must be Redis" unless $_[0] && ref $_[0] eq 'Redis' }, ); has _rows => ( is => 'rw', - isa => 'ArrayRef', + isa => sub { die "$_[0] must be ARRAY" unless $_[0] && ref $_[0] eq 'ARRAY' }, default => sub {[]} ); has _query_done => ( is => 'rw', - isa => 'Int', + isa => sub { die "$_[0] must be int" unless defined $_[0] && is_int($_[0]) }, default => 0, ); +has result_source => ( + is => 'ro', + default => sub { NGCP::Panel::Utils::RedisLocationResultSource->new }, +); + +has result_class => ( + is => 'ro', + default => 'dummy', +); + +has current_source_alias => ( + is => 'ro', + default => 'me', +); + has _domain_resellers => ( is => 'rw', - isa => 'HashRef', + isa => sub { die "$_[0] must be HASHREF" unless $_[0] && ref $_[0] eq 'HASH' }, lazy => 1, default => sub { my $self = shift; @@ -164,7 +181,6 @@ sub _filter { foreach my $row (@{ $self->_rows }) { my $match = 0; my $filter_applied = 0; - my %attr = map { $_->name => 1 } $row->meta->get_all_attributes; foreach my $colname (keys %{ $filter }) { my $condition = $filter->{$colname}; my $searchname = $colname; @@ -173,7 +189,7 @@ sub _filter { next if ($colname =~ /\./); # we don't support joined table columns $filter_applied = 1; if (ref $condition eq "") { - if (!exists $attr{$colname} || lc($row->$colname) ne lc($condition)) { + if (lc($row->$colname) ne lc($condition)) { $match = 0; last; } else { @@ -183,7 +199,7 @@ sub _filter { my $fil = $condition->{like}; $fil =~ s/^\%//; $fil =~ s/\%$//; - if (!exists $attr{$colname} || $row->$colname !~ /$fil/i) { + if ($row->$colname !~ /$fil/i) { $match = 0; last; } else { @@ -221,17 +237,4 @@ sub _scan { return 1; } -sub result_class { - "dummy"; -} - -sub result_source { - NGCP::Panel::Utils::RedisLocationResultSource->new; -} - -sub current_source_alias { - my ($self) = @_; - return 'me'; -} - 1; diff --git a/lib/NGCP/Panel/Utils/RedisLocationResultSource.pm b/lib/NGCP/Panel/Utils/RedisLocationResultSource.pm index d9f6af4587..0713637401 100644 --- a/lib/NGCP/Panel/Utils/RedisLocationResultSource.pm +++ b/lib/NGCP/Panel/Utils/RedisLocationResultSource.pm @@ -1,21 +1,20 @@ package NGCP::Panel::Utils::RedisLocationResultSource; -use Moose; +use Moo; + +our $AUTOLOAD; has _data => ( is => 'ro', - isa => 'HashRef', + isa => sub { die "$_[0] must be HASHREF" unless $_[0] && ref $_[0] eq 'HASH' }, default => sub {{}}, ); -sub BUILD { - my ($self) = @_; - foreach my $k (keys %{ $self->_data }) { - $self->meta->add_attribute( - $k => (accessor => $k) - ); - $self->$k($self->_data->{$k}); - } +sub AUTOLOAD { + my $self = shift; + my $col = $AUTOLOAD; + $col = (split /::/, $col)[-1]; + return $self->_data->{$col}; } sub get_inflated_columns { @@ -23,9 +22,6 @@ sub get_inflated_columns { return %{ $self->_data }; } -sub columns { - -} - +sub columns { } 1;