I'm fairly new Perl so any help on working this out is awesome.

The application I'm working on is based on catalyst MVC architecture. My Postgresql table looks like this:
CREATE TABLE zips ( zip_code CHAR(5) NOT NULL, zip_type CHAR(1), city_name VARCHAR(64), city_type CHAR(1), state_name VARCHAR(64), state_abbr CHAR(2) NOT NULL, area_code CHAR(3), latitude NUMERIC(9,6) NOT NULL, longitude NUMERIC(9,6) NOT NULL ); CREATE INDEX zip_codes ON zips (zip_code); CREATE INDEX state_abbrs ON zips (state_abbr); CREATE INDEX city_names ON zips USING btree (city_name); CREATE TABLE distance_cache ( orig_zip CHAR(5) NOT NULL, dest_zip CHAR(5) NOT NULL, miles SMALLINT );


My search by zipcode is working great and turning out the results I need. Searching by city and state however, is not working. This started not working when I had to create a backup of zips called zips_backup because I corrupted the zips table. I changed a perl module to pull from zips_backup . As far as I can tell, this one module is the only thing that was changed but some insight would be great.

I can supply any files that one would need. Thank you in advance - I look forward to learning whats going on with this.
Here is the module I'm referring to:
package WeilMclainDB::Zips; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto Core/); __PACKAGE__->table('zips'); __PACKAGE__->add_columns(qw/zip_code zip_type city_name city_type stat +e_name state_abbr area_code latitude longitude/); __PACKAGE__->resultset_class('WeilMclainDB::ZipsResultSet'); 1; package WeilMclainDB::ZipsResultSet; use base 'DBIx::Class::ResultSet'; use Geo::Distance; sub get_zip { my ($self, $city, $state) = @_; #return undef unless ($city && $state =~ /^(\d*)$/); if (my $zip = $self->single({city_name => uc($city),state_abbr=>uc +($state)},{columns => [qw/zip_code/]})) { return $zip->get_column('zip_code'); } return undef; return $self->single({city_name=>uc($city),state_abbr=>uc($state)} +,{columns=>[qw/zip_code/]})->get_column('zip_code'); } sub get_closest { my ($self, $zip_code, $miles) = @_; # First get the latitude and longititude for the given zip code if (my $zip = $self->single({zip_code => $zip_code})) { my $geo = Geo::Distance->new; my $locations = $geo->closest( dbh => $self->result_source->storage->dbh, table => 'zips', lon => $zip->longitude, lat => $zip->latitude, unit => 'mile', distance => $miles, lon_field => 'longitude', lat_field => 'latitude', 'sort' => 1, fields => [qw/zip_code/], ); my @zips; foreach my $result (@{$locations}) { push (@zips, $result->{zip_code}); } return \@zips; } else { return undef; } } 1;

In reply to MVC Catalyst Architecture - City, State Zip locator by ChristinaH

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.