Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.