Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: MVC Catalyst Architecture - City, State Zip locator

by Your Mother (Archbishop)
on Jul 18, 2008 at 23:52 UTC ( [id://698759] : note . print w/replies, xml ) Need Help??

in reply to MVC Catalyst Architecture - City, State Zip locator

When something goes from working to not working and you think you didn't change anything significant, you usually just made one dumb little mistake. If you want debugging to be easy, put lots of feedback in your code to report when it's used incorrectly (and write tests for it). Try this for starters-

use Carp; sub get_zip { my $self = shift; my $city = uc(+shift) || croak "No city given"; my $state = uc(+shift) || croak "No state given"; my $zip = $self->single({ city_name => $city, state_abbr => $state }, { columns => [qw/zip_code/] } ); if ( $zip ) { return $zip->zip_code; } else { carp "No ZIP found for city_name:$city and state_abbr:$state"; } return undef; }

I'm a fan of the die early, die often edict (hence the croaks) but you can tone it down or adapt. The main idea is just to never assume that your code will be called as designed and account for that. See also Params::Validate.

Replies are listed 'Best First'.
Re^2: MVC Catalyst Architecture - City, State Zip locator
by Anonymous Monk on Jul 21, 2008 at 19:02 UTC
    I'm a regular commenter when using PHP and if I knew Perl at all I would comment it out as well. Thats one thing that has been so difficult with this script and the models with it. Thanks for your help!

      I'd say, general rule, avoid comments in Perl in favor of Pod. Comments have their place (and opinions differ widely) but I personally only like to see them when they illuminate some data or business logic oddity and as you'll read here, they can lie or be out of sync just as often as they help. Well chosen variable and sub names are better than comments most of the time.

      Here are examples of both. See perlpod for more.

      # Perl only has one real comment style, this is it. # Leading pound/number sign. =head2 get_zip L</get_zip> takes blah, blah, and returns blah, blah, blah. Pod has more syntax and is readily convertible to a number of formats +from RTF to WikiText and HTML and plenty in between. =cut sub get_zip { my $self = shift; # ...

        I've never heard of Perlpod before - actually, alot of this is new to me. I can understand bad commenting - just never thought anyone would do something like. Rather tactless. I will look into perlpod now that I'm starting to learn Perl.