From 3bf1bc54822c12fc2a1d4388a193ebccea2b552e Mon Sep 17 00:00:00 2001 From: Matthew Musgrove Date: Sat, 30 Apr 2011 20:41:26 -0500 Subject: [PATCH] Correcting search --- .../DB/Result/Map/Body/Planet/Station.pm | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm index 9561f62f..93cd5292 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm @@ -101,23 +101,22 @@ sub add_waste { sub in_jurisdiction { my ($self, $target) = @_; - my $type = ''; - $type = 'star' if (ref $target eq 'Lacuna::DB::Result::Map::Star'); - $type = 'body' if (ref $target =~ /Lacuna::DB::Result::Map::Body/); - unless ($type) { - confess [1009, 'Invalid target '.ref $target. ' '.$target->id]; - } - my $class = ( $type eq 'star' ) ? 'Lacuna::DB::Result::Map::Star' : 'Lacuna::DB::Result::Map::Body'; - my $search = Lacuna->db->resultset($class); - my $find = $search->find($target->id); - unless (defined $find) { - confess [1009, 'Invalid target '.ref $target. ' '.$target->id]; - } - if ($type eq 'star' && $find->station_id != $self->id) { - confess [1009, 'Target is not in the station\'s jurisdiction.']; - } - elsif ($find->star->station_id != $self->id) { - confess [1009, 'Target is not in the station\'s jurisdiction.']; + if (ref $target eq 'Lacuna::DB::Result::Map::Star') { + my $star = Lacuna->db->resultset('Lacuna::DB::Result::Map::Star')->find($target->id); + unless (defined $star) { + confess [1009, 'Invalid star']; + } + unless ($star->station_id == $self->id) { + confess [1009, 'Target star is not in the station\'s jurisdiction.']; + } + } else { + my $body = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($target->id); + unless (defined $body) { + confess [1009, 'Invalid body']; + } + unless ($body->star->station_id == $self->id) { + confess [1009, 'Target body is not in the station\'s jurisdiction.']; + } } } -- 2.51.2